Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A problem with file handle CHUNK 1

Status
Not open for further replies.

lcs01

Programmer
Joined
Aug 2, 2006
Messages
182
Location
US
I am having trouble in dealing with file handle Chunk issue.

Here is what I did:

Linux/Apache/perl 5.6/Mod_perl.

When you click a link, a perl code is invoked which parses a list of files in a loop.

A piece of code list below (very simple):

Code:
foreach my $fn (@fileList) {
  parseFile($fn);
}

sub parseFile {
  my $file = $_[0];
  open(FH, "$file") || die;
  my $i = 0;
  while(FH) {
    my $len = length($_);
    warn "\$i = $i, \$len = #$len#";
    $i++;
  }
  close(FH);
}

What I expect is something like this:

Code:
[Fri Dec  8 11:12:27 2006] null: $i = 0, $len = #20# at {$somepath}/myperl.pm line 3862.
[Fri Dec  8 11:12:27 2006] null: $i = 1, $len = #42# at {$somepath}/myperl.pm line 3862.
......
......

However, the actual log is like this:

Code:
[Fri Dec  8 11:12:36 2006] null: $i = 0, $len = #258476# at {$somepath}/myperl.pm line 3862, [b]<INFILE> chunk 1[/b].

That means the whole file was treated as one line -- all line feeds are ignored!

Certainly, the actual code was quite complicated and the piece shown above is very much simplified. I tried to run the simplified piece from cmdline and it works just fine.
Could someone here tell me
1) how to deal with the file handle CHUNK problem?
2) under what circumtances, could this problem happen?

Many thanks!!!
 
Code:
  while([COLOR=blue]<FH>[/color]) {

-------------
Kirsle.net | Kirsle's Programs and Projects
 
I figured out why. Somewhere in the codes, there is a line that set the system variable $/. Once I reset it, everything is back to what expected.
 
Good eye Kirsle. That would be it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top