Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: printing hash values, (don't need the keys)

by GrandFather (Sage)
on Jul 06, 2006 at 22:32 UTC ( #559685=note: print w/ replies, xml ) Need Help??


in reply to Re: printing hash values, (don't need the keys)
in thread printing hash values, (don't need the keys)

If you omit the chomp then you can:

my $data_file = "ActiveItems2.txt"; open(DAT, $data_file) || die("Could not open file: $!"); my %seen; $seen{$_}++ while <DAT>; print for sort keys %seen; close(DAT);

Another interesting variant (although it may suffer the slurp problem) is to use a hash slice:

@seen{<DAT>} = (); # Hash slice assignement print for sort keys %seen;

It's worth seeing the hash slice a few times to remember that it is there and what the syntax is. Like many things in Perl, occasionally it is exactly what you need to achieve a clean solution to a problem. Perhaps not in this case though. :)


DWIM is Perl's answer to Gödel


Comment on Re^2: printing hash values, (don't need the keys)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2015-07-06 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (71 votes), past polls