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

Re: [FWP] Add to elements of a list



At 11:17 AM 4/8/00 -0700, tallwine@carol.ixlabs.com wrote:
>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 }
>
>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];
>}

I see I shouldn't have said "increment", as it was 
misleading.  s/increment/add/, and see a sample use of my code:

my ($x, $y, $z) = (3, 5, 7);
for (foo()) { eval "$1 += $_" if '$x $y $z' =~ m/(\S+)/g }
print "$x $y $z\n";
sub foo { (5, 8, 13) }
__END__
8 13 20




--
Peter Scott
Pacific Systems Design Technologies


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