Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: What the [sub]in 'L value do they have?

by Chmrr (Vicar)
on Dec 15, 2002 at 08:37 UTC ( #219978=note: print w/ replies, xml ) Need Help??


in reply to What the [sub]in 'L value do they have?

The only time I used : lvalue was in writing the following subroutine:

sub set : lvalue { @_ == 1 ? $_[0] : set($_[0]{$_[1]},@_[2..$#_]); }

..which is used to set values at any depth in a recursive hash structure, like so:

use Data::Dumper; sub set : lvalue { @_ == 1 ? $_[0] : set($_[0]{$_[1]},@_[2..$#_]); } my $h = {foo => 1, bar => 2, baz => { troz => 3, zort => 4, poit => { qux => 5, quux => 6, }, }, }; print Dumper($h); set($h, qw/baz troz/) = 42; set($h, qw/baz poit qux/) = 17; print Dumper($h);

In this particular case, doing data verification wasn't overly useful, but I can definately see when it might be. While I'm not convinced that using $_ "won't break any existing code," it seems to be the most perlish choice to use.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


Comment on Re: What the [sub]in 'L value do they have?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2015-07-01 20:32 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 (19 votes), past polls