in reply to Re: Resistor network simplifier
in thread Resistor network simplifier
$$_ = node() for \my ($in_neg, $in_pos, $out_neg, $out_pos);
Or more simply, since $_ is already aliased to each item of the list:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use 5.010; ;; sub node { state $x = 42; return ++$x; } ;; $_ = node() for my ($in_neg, $in_pos, $out_neg, $out_pos); dd $in_neg, $in_pos, $out_neg, $out_pos; " (43 .. 46)
Update 1: BTW: Both approaches work under Perl version 5.8.9 (without the use of state of course!).
Update 2: Although I have to say that the first | quoted form could be very useful when iterating over a list of references to arbitrary my variables (actually, I think this would work with any kind of variable, but I haven't tested this):
c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; print 'perl version: ', $]; ;; init($_) for \my ($scalar, @ra, %ha); dd $scalar, \@ra, \%ha; ;; sub init { my ($r) = @_; ;; return 'ARRAY' eq ref $r ? @$r = (9, 8, 7) : 'HASH' eq ref $r ? %$r = qw(one 1 two 2 three 3) : 'SCALAR' eq ref $r ? $$r = 42 : die qq{unknown ref type: '$r'} ; } " perl version: 5.008009 (42, [9, 8, 7], { one => 1, three => 3, two => 2 })
Give a man a fish: <%-{-{-{-<
|
|---|