Openning a File

M

MattM

This should be fairly straightforward, but I'm having trouble openning
a file. I'm modifying a current perl script that seemed to run fine.
I open a file for input, parse it, make some changes to it, create
another file, and write the changes to the new file. I wanted to open
up another file for input, but when I do, it seems to be adding spaces
between each character in the line as its read in. On of the lines of
the file looks something like:

ZZZ223 FP2115

the columns are seperated by a tab. What I get when I run the simple
file openning code is:

Z Z Z 2 2 3 F P 2 1 1 5

I'm trying to put these into a hash table for quick access later in
the program. The code I'm using is pretty simple. It looks like:

open MYFILE,"myfile.txt" or die "Can't open trigger file: $!\n";

while (<MYFILE>) {

chomp;

print STDOUT $_ . "\n";

$lineIn = $_;

($parm,$trigger) = split /\s+/, $lineIn;


$triggers{$parm} .= $trigger;

}

close MYFILE;


But when I run this I get the strange spacing problem. Any Ideas?
Thanks...
 
D

david

This should be fairly straightforward, but I'm having trouble openning
a file. I'm modifying a current perl script that seemed to run fine.
I open a file for input, parse it, make some changes to it, create
another file, and write the changes to the new file. I wanted to open
up another file for input, but when I do, it seems to be adding spaces
between each character in the line as its read in. On of the lines of
the file looks something like:

ZZZ223 FP2115

the columns are seperated by a tab. What I get when I run the simple
file openning code is:

Z Z Z 2 2 3 F P 2 1 1 5

I'm trying to put these into a hash table for quick access later in
the program. The code I'm using is pretty simple. It looks like:

open MYFILE,"myfile.txt" or die "Can't open trigger file: $!\n";

while (<MYFILE>) {

chomp;

print STDOUT $_ . "\n";

$lineIn = $_;

($parm,$trigger) = split /\s+/, $lineIn;

$triggers{$parm} .= $trigger;

}

close MYFILE;

But when I run this I get the strange spacing problem. Any Ideas?
Thanks...

Hi,
I ran your program on the sample line but did not observe the problem.
Best regards,
Michael
 
J

J. Gleixner

MattM said:
This should be fairly straightforward, but I'm having trouble openning
a file. I'm modifying a current perl script that seemed to run fine.
I open a file for input, parse it, make some changes to it, create
another file, and write the changes to the new file. I wanted to open
up another file for input, but when I do, it seems to be adding spaces
between each character in the line as its read in. On of the lines of
the file looks something like:

Instead of 'something like', provide the actual lines.
ZZZ223 FP2115

the columns are seperated by a tab. What I get when I run the simple
file openning code is:

Z Z Z 2 2 3 F P 2 1 1 5
[...]

Post an actual example that displays the issue. Since we don't have
access to your 'myfile.txt' and you didn't show the code that's
doing something with your hash, there's no way anyone can reproduce
your issue.

e.g.

my $lineIn = 'ZZZ223 FP2115';
my ($parm,$trigger) = split /\s+/, $lineIn;
print "parm=$parm trigger=$trigger\n";

parm=ZZZ223 trigger=FP2115
 
M

MattM

When I tried to create a smaller subset of "myfile.txt" that I copied
from the larger file, the code worked ok. Just for the heck of it, I
opened up the larger file in Hex. My text editor indicated that there
were null characters in between the valid alphanumeric values. When
the editor is allowed to display that larger file, it must
automatically remove the nulls, because it appeared as subsequent
valid alphanumeric values. When I copied some of the values to the
smaller file, it seems to have removed the nulls as well. When I
brought up the smaller file in Hex, it didn't have the nulls between
the alphanumeric values. The process of copying the file removed the
nulls. Not sure why. But anyway, thanks for the input. It made me
dig a little deeper....

J. Gleixner said:
MattM said:
This should be fairly straightforward, but I'm having trouble openning
a file. I'm modifying a current perl script that seemed to run fine.
I open a file for input, parse it, make some changes to it, create
another file, and write the changes to the new file. I wanted to open
up another file for input, but when I do, it seems to be adding spaces
between each character in the line as its read in. On of the lines of
the file looks something like:

Instead of 'something like', provide the actual lines.
ZZZ223 FP2115

the columns are seperated by a tab. What I get when I run the simple
file openning code is:

Z Z Z 2 2 3 F P 2 1 1 5
[...]

Post an actual example that displays the issue. Since we don't have
access to your 'myfile.txt' and you didn't show the code that's
doing something with your hash, there's no way anyone can reproduce
your issue.

e.g.

my $lineIn = 'ZZZ223 FP2115';
my ($parm,$trigger) = split /\s+/, $lineIn;
print "parm=$parm trigger=$trigger\n";

parm=ZZZ223 trigger=FP2115
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top