Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: sub that sets $_

by holli (Monsignor)
on Jun 28, 2005 at 12:29 UTC ( #470599=note: print w/replies, xml ) Need Help??

in reply to Re: sub that sets $_
in thread sub that sets $_

Thanks Damian for telling me about that possibility. I have taken your advice and updated Re: Handling A File In Human-Compatible Chunks with a new version of the module, that now supports $_.

Replies are listed 'Best First'.
Re^3: sub that sets $_
by Animator (Hermit) on Jun 28, 2005 at 12:54 UTC

    First of all congratulations with the excelent idea to use DESTROY to set $_.

    Second, it still has a little bug though... it will set the value of $_ when the object gets destroyed... which is why it works and why it is bugged. Example:

    $_ = "abc"; { my $line = $reader->chunk(); } print $_;
    $_ won't have the value "abc"...

    Update: since I'm not that familiar with overloading I re-looked at the overload pod... (to see if there is a function that is always called, so that the DESTROY could be made conditional/optional). In it I found an intresting overload option.

    You can overload <>. This would mean that you can overload it in your main module and use <$reader>. Which will set the appropriate variable. (Using < $reader->chunk > is not possible since it is a syntax error. You could ofcourse assign it to a temp var and use that but what would be wrong with using <$reader>?)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://470599]
[Discipulus]: shmem the first time I was in germany I was so smart to learn by heart the address of the hostel: Einbahnstraße..
[Discipulus]: james28909 you are welcome
james28909 doesnt drink much alcohol
james28909 does enjoy blazing up though
james28909 also walks around hunting for his cell phone while using its flashlight function

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-05-20 16:14 GMT
Find Nodes?
    Voting Booth?