Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: print out the values from a hash

by Kenosis (Priest)
on Jan 11, 2013 at 18:11 UTC ( #1012943=note: print w/ replies, xml ) Need Help??


in reply to print out the values from a hash

choroba has provided excellent suggestions. Here an option that uses a hash of arrays (HoA), where the key is the file name and its associated value is a reference to a list of frequencies:

use strict; use warnings; my %files; for my $file (<*.abc>) { open my $fh, '<', $file or die $!; while (<$fh>) { push @{ $files{$file} }, $1 if /FREQ\s+([\d.]+)/; } close $fh; } print "$_ FREQ @{ $files{$_} }\n" for keys %files;

Output on files containing FREQ <val> info:

file3.abc FREQ 27.047 400 file1.abc FREQ 33.3 2.22 file2.abc FREQ 12345.67

Hope this helps!


Comment on Re: print out the values from a hash
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2015-07-29 02:08 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 (260 votes), past polls