[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Add to elements of a list



Peter Scott said...
>
>After much head-scratching, I came up with this monstrosity fitting the 
>criteria: mustn't call foo() more than once; mustn't create any temporary 
>variables (well, not by name, anyway; I don't count localized $_ and $1):
>
>	for (foo()) { eval "$1 += $_" if '$x $y $z' =~ m/(\S+)/g }
>
>Gross, huh?  No, I'm not planning on using it in my code.
>

Here is one way:
($x,$y,$z) = map{$_+= 1} @{foo()}
print join(' ',$x,$y,$z),"\n";

sub foo {
    my $v1 = 1;
    my $v2 = 2;
    my $v3 = 3;
    return [$v1,$v2,$v3];
}

-- 
Tim Allwine
IX Development Laboratories
(707)-543-8030 Ext.15

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe