Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Re: (jeffa) Re: Closures as Itterators

by blakem (Monsignor)
on Jul 02, 2001 at 22:48 UTC ( [id://93276]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: (jeffa) Re: Closures as Itterators
in thread Closures as Itterators

I know what while(chomp($row = <$fh>)) is doing. In this case, though, I'm reading from a very specific data file (which does end with a newline) and the very nature of the routine prevents it from using the last line of the data file 99.9% of the time anyway. (is is primarily used to grab a few lines from the middle of the file)
Thanks for the $_ tip, though, I like it.

-Blake

Replies are listed 'Best First'.
Re: Re: Re: Re: (jeffa) Re: Closures as Itterators
by dragonchild (Archbishop) on Jul 02, 2001 at 23:30 UTC
    I know what while(chomp($row = <$fh>)) is doing. In this case, though, I'm reading from a very specific data file ...

    If I had a nickel for every time I heard someone say something like that, PM would never have to beg for money. The issue isn't whether or not your specific data file at this specific instance will or will not break your syntax. The issue is whether or not that syntax is the better way to write it. Why introduce a potential bug into your code?

    Now, your reply is that you know where the issue is and you won't make that mistake when it matters.

    My reply to that is simple - why get into a bad habit? Always code with good habits. My swim coach in 3rd grade was never happy with "Practice makes perfect" ... he believe in "Perfect practice makes perfect". I hated him at the time, but I thank him now.

      You are right about good habits of course. The previous rev of this code snippet looked like:
      while(defined($row = <$fh>)) { chomp($row);
      I thought it was silly to use defined when the return value from chomp suits my purposes in this particular instance.

      -Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found