Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Numeric summarisation from data in a hash?

by ahunter (Monk)
on Jul 07, 2000 at 17:58 UTC ( #21476=note: print w/ replies, xml ) Need Help??


in reply to Numeric summarisation from data in a hash?

Convert $vlength to seconds (easy), and use grep in its scalar context:

sub btween (\%$$) { my ($hash, $from, $until) = @_; return scalar(grep { $hash->{$_}->{VLENGTH} >= $from && $hash->{$_}->{VLENGTH} < $until } keys(%{$hash})); } print "There are ", btween(%hash, 0, 60), " clips between 0-1 minutes\ +n";
(And so on and so forth)

Update: Oops, forgot the titles. Grep again:

sub btween (\%$$) { my ($hash, $from, $until) = @_; my @found = grep { $hash->{$_}->{VLENGTH} >= $from && $hash->{$_}->{VLENGTH} < $until } keys(%{$hash})); my $titles = join(', ', map { $hash->{$_}->{TITLE} } @found); return ($#found, $titles); } my @result = btween(%hash, 0, 60); print "There are $result[0] clips between 0-1 minutes, and their names + are: $result[1]\n";
Update the second: Rewrote the update in the form of the original sub statement. This doesn't work for 'there are n clips >5 minutes long'-type things. Change the conditional in the grep statement to fix this.

Andrew.


Comment on Re: Numeric summarisation from data in 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://21476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-07-06 00:35 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 (68 votes), past polls