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

Re: How to reset a variable for each file inside a while( <> ) loop?

by starX (Chaplain)
on Jun 13, 2008 at 14:43 UTC ( [id://691911]=note: print w/replies, xml ) Need Help??


in reply to How to reset a variable for each file inside a while( <> ) loop?

Aesthetic reasons not withstanding, I'm not sure how you plan on resetting your counter without keeping track of which file you're working with in some way. There are some other things you might try, but from where I sit, you're going to wind up writing something resembling the code that you're trying to avoid.

I think there's something in PBP to the effect of "don't be elegant" anyway. The aesthetics you're working with today may not be the aesthetics you're working with a few months from now, or that the next guy uses. The code that you already know how to write and are trying to avoid, on the other hand, is pretty straight forward in what it does. That may be more meaningful for you in the future than whether or not it's pretty.

  • Comment on Re: How to reset a variable for each file inside a while( <> ) loop?

Replies are listed 'Best First'.
Re^2: How to reset a variable for each file inside a while( <> ) loop?
by pat_mc (Pilgrim) on Jun 13, 2008 at 15:33 UTC
    Thanks, starXX for your comments and for taking the time to post your reply!

    While I see your point regarding the transient nature of aesthetic standards I am reluctant to agree and gladly retreat to the position that everybody feel free to make their code as (transiently) aesthetic as they please.

    More to the point of my original question, I would be very much interested in the "some other things you might try" that you mentioned. Can you provide details here?

    As you point out correctly, it seems one explicitly would need to keep track of which file Perl is currently working on. I was hoping there is a way around that because implictly the <> operator seems to be knowing which file it is currently processing.
    I am therefore still wondering if Perl provides an access to this 'behind the scene' information at the time of iterating through those input files.

    Thanks again!

    Cheers - Pat
      ...still wondering if Perl provides an access to this 'behind the scene' information

      (from perlvar)

      $ARGV contains the name of the current file when reading from <> +.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found