Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Swapping names of list while keeping the contents as it is.

by philiprbrenan (Monk)
on Aug 30, 2012 at 18:32 UTC ( #990818=note: print w/replies, xml ) Need Help??


in reply to Swapping names of list while keeping the contents as it is.

Try:

use feature ":5.14"; use warnings FATAL => qw(all); use strict; for(split /\n/, << 'END') jay 21 34 56 bob 12 39 jay 11 10 bob 14 jay 190 bob 13 END {s/jay/bob/ or s/bob/jay/; say }

Produces

bob 21 34 56
jay 12 39
bob 11 10
jay 14
bob 190
jay 13

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990818]
help
Chatterbox?
[shmem]: yes, at least for the result in @foo
[shmem]: but the results of both operations are different.
[shmem]: result := the discarded result (what's leftmost of the statement)
[shmem]: push returns the number of elements in @foo, the assignment returns all the elements in the (renewed) @foo
[Lady_Aleena]: Sanity check please? push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addiction; # so I don't have the change existing uses of the sub.
[shmem]: $list_addiction should be $list_addition

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-04-27 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (503 votes). Check out past polls.