Assign Named $foo and $bar - Fortune

Assign Named $foo and $bar

LeoNerd I feel there must be a way to do this... given func( foo => 1, bar => 2 ); how to write my ( $foo, $bar ) = .... inside the function?
LeoNerd My current attempt is my ( $foo, $bar ) = @{{@_}}{qw( foo bar )}; which is messy as sin
icke LeoNerd: what's the problem? readability?
LeoNerd Yah
dazjorz LeoNerd: I'd change specs to be func({ foo => 1, bar => 2})
dazjorz then my ($foo, $bar) = ($_[0]{foo}, $_[0]{bar});
ton Leonerd: If you insist on doing it on one line, that's about as good as it gets. But why not use a temporary hash ? Should be just as fast and as readable
LeoNerd Hrm.. :/ Then it's only marginally nicer as my ( $foo, $bar ) = @{$_[0]}{qw( foo bar )};
LeoNerd my %args = @_; my ( $foo, $bar ) = @args{qw( foo bar )}; ya... that works
mst LeoNerd: my ($foo, $bar) = do { my %a = @_; @a{qw(foo bar)} };
ton if you combine it with a delete you can then check if %args is empty and catch typos or unexpected arguments....
LeoNerd Oooh.. a do block
vincent or use padwalker
LeoNerd Oh, args won't be empty... this is a wrapper function that pulls a few named args off and sends the rest to a nested inner function
LeoNerd Now.. I want to call a function "foreach" but that breaks things... suggestions?
icke a method could be named 'foreach'
LeoNerd Ya.. but this is a plain function
icke tough
LeoNerd I suppose "iterate" is about as best as I'll get
icke for_each
ton LeoNerd: forall ?
LeoNerd I'll think on it overnight maybe.. I guess it's home time now
icke foreachandeverysingleone
ton forever, forfun, forlorn...
vincent FOREACH
icke boo
LeoNerd one_for $all and $all for @one;
rindolf forevery?
rindolf <LeoNerd> one_for $all and $all for @one; - heh
rindolf $one for @all and @all for @one
rindolf $one for @all and @all for @$one
rindolf $one for @all and @all for $one
rindolf Works too.
LeoNerd Hrm.. it does?
LeoNerd deparse: $one for @all and @all for $one
buubot LeoNerd: Error: syntax error at (eval 107195) line 1, near "@all for "
LeoNerd You can't use two postmod fors in a single statement
Channel #perl
Network Freenode
Tagline Syntax Fun