Openning a File

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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>) {


   print STDOUT $_ . "\n";

   $lineIn = $_;

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

   $triggers .= $trigger;


close MYFILE;

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

Re: Openning a File

Quoted text here. Click to load it

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

Re: Openning a File

MattM wrote:
Quoted text here. Click to load it

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

Quoted text here. Click to load it

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.


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

parm=ZZZ223 trigger=FP2115

Re: Openning a File

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 wrote:
Quoted text here. Click to load it

Re: Openning a File

MattM wrote:
Quoted text here. Click to load it

Then welcome to the wonderful word of unicode and the
evil difference between characters and bytes :)

Have a look at "perldoc -f open" and the docs mentioned
there, "perldoc PerlIO" and "perldoc perluniintro".
There's a lot of information and examples on the topic
of using single- and multibyte encodings in Perl.


[And please, try not to top-post. Putting the answer below
the cited text makes it really easier to follow a conversation.]

Site Timeline