Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Openning a File

Reply
Thread Tools

Openning a File

 
 
MattM
Guest
Posts: n/a
 
      02-21-2008
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...
 
Reply With Quote
 
 
 
 
david
Guest
Posts: n/a
 
      02-21-2008
On Feb 21, 4:46 pm, MattM <matthew.men...@navy.mil> wrote:
> 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
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      02-21-2008
MattM wrote:
> 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
 
Reply With Quote
 
MattM
Guest
Posts: n/a
 
      02-21-2008
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:
> MattM wrote:
> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
log4j - openning a new file ER Java 2 08-12-2007 02:23 AM
find if any application is openning the file ravichoudhari@gmail.com C++ 2 04-17-2006 09:32 AM
find if any application is openning the file ravichoudhari@gmail.com C++ 1 04-17-2006 06:19 AM
Openning a file while in an object DJ C++ 6 10-27-2004 07:18 AM
Save as to appear instead of openning file in the browser.... Mel HTML 5 07-18-2004 08:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57