Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^2: Anonymous Arrays or Anonymous Array References

by ikegami (Pope)
on Mar 03, 2011 at 19:07 UTC ( #891287=note: print w/replies, xml ) Need Help??

in reply to Re: Anonymous Arrays or Anonymous Array References
in thread Anonymous Arrays or Anonymous Array References

@U = keys ('A'=>1,'B'=>2,'Z'=>26);

That's the same as getting every second item (starting with the first) and removing duplicates. There's no good shorthand for that, even if you omit the requirement to remove duplicates.

@U = keys %{{ map { $_=>1} @NU }};

If the contents of @NU has no duplicates, then that's the same as

my @U = @NU;

If your question is how to remove duplicates, then there's an answer in perlfaq4. Some solutions

my @U = uniq @NU; # From List::Util

I use the idiomatic

my %seen; my @U = grep !$seen{$_}++, @NU;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://891287]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-07-20 05:33 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (424 votes). Check out past polls.