Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: My 'perldar' tells me there is a 'better' solution for this list operation

by Sidhekin (Priest)
on Nov 03, 2006 at 22:35 UTC ( #582188=note: print w/replies, xml ) Need Help??


in reply to My 'perldar' tells me there is a 'better' solution for this list operation

If you judge whether a value is "present" by string equality (and it would seem you do), you could just use a hash:

my %map; @map{@l2} = (); my @list = map { exists $map{$_} ? $_ : 'null' } @l1;

( Also: "perldar"++ )

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://582188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-11-19 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (209 votes). Check out past polls.

    Notices?