Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by Chmrr (Vicar)
on Dec 15, 2002 at 08:37 UTC ( [id://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'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found