Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Shorten the headers of a file and remove empty lines using perl

by Cristoforo (Deacon)
on Jun 13, 2013 at 23:27 UTC ( #1038861=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Shorten the headers of a file and remove empty lines using perl
in thread Shorten the headers of a file and remove empty lines using perl

foreach my $line ( <$input_fh> )

should be

while (my $line = <$input_fh> )

The first form is a glob, (but I don't know well enough to explain it to you).

The second line should work properly for reading your file.

Update: Yes Choroba is correct, it is not a glob - my mistake,


Comment on Re^3: Shorten the headers of a file and remove empty lines using perl
Select or Download Code
Re^4: Shorten the headers of a file and remove empty lines using perl
by choroba (Canon) on Jun 13, 2013 at 23:30 UTC
    It is not a glob. It is a readline in list context. If the file is large, it can eat lots of memory, and should therefor be avoided.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^4: Shorten the headers of a file and remove empty lines using perl
by Preceptor (Chaplain) on Jun 14, 2013 at 20:29 UTC

    Indeed - the bit I posted initially will work, but it'll trigger reading the whole file into memory. Probably not a good idea with a 500MB file.

    Perl contexts are incredibly clever, but do lead to some interesting gotchas - use of a filehandle in a scalar or array context is one of them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038861]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-07-02 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (34 votes), past polls