Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: eof not recognised when applying diamond operator to invocation arguments?

by Anonyrnous Monk (Hermit)
on Jan 12, 2011 at 17:58 UTC ( #881951=note: print w/replies, xml ) Need Help??


in reply to eof not recognised when applying diamond operator to invocation arguments?

Just in case you're curious...  If you wanted to stick with your original code as closely as possible, here's how you'd have to modify it to get it working as desired (I wouldn't recommend it though):

my @filesnames = @ARGV; for my $input_file ( @filesnames ) { eof(); while ( ! eof ) { print scalar <>; } print "=========SEPARATOR: Processing $input_file =========\n"; }
  • Comment on Re: eof not recognised when applying diamond operator to invocation arguments?
  • Download Code

Replies are listed 'Best First'.
Re^2: eof not recognised when applying diamond operator to invocation arguments?
by pat_mc (Pilgrim) on Jan 13, 2011 at 09:27 UTC
    Why wouldn't you recommend to use this code?

      Mainly because it's unnecessarily hard to understand:  eof(); WTF?  Why does it have to be before the loop? If you move it after the loop, it will work with Perl 5.12 just fine, too, but not with 5.10.  Also, someone (including yourself) looking at this later might figure the additional array @filenames is superfluous (and remove it), etc.

      Any compelling reason you can't use the more direct version you mentioned yourself elsewhere in the thread?

        Any compelling reason you can't use the more direct version you mentioned yourself elsewhere in the thread?
        Yes ... I need to use nested loops because I am reading the input file, parsing the input line and - if and when I find a certain pattern - read 100 lines further. If I use the direct version I will keep losing one line because the inside loop and the outside loop both read an line one after the other.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://881951]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-12-16 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (448 votes). Check out past polls.

    Notices?