Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Grepping arrays, any better way to do this?

by izut (Chaplain)
on Feb 15, 2007 at 11:17 UTC ( [id://600182]=note: print w/replies, xml ) Need Help??


in reply to Grepping arrays, any better way to do this?

Assuming that the first part of each @fileslist element will have that scheme:

use strict; use warnings; use Smart::Comments; my @datelist = ( "20030901", "20061017", "20050406", "20070101", "2008 +0202" ); my @fileslist = ( "DIR22.20060816", "DIR22.20050919", "DIR22.20061017", "DIR22.20060 +516", "DIR22.20050406" ); # creates a hash with all dates seen on @fileslist my %seen_dates; @seen_dates{ map { ( unpack( "x6A*", $_ ) )[0] } @fileslist } = (); # increases the value of each seen @datelist element on %seen_dates. foreach (@datelist) { if ( exists $seen_dates{$_} ) { $seen_dates{$_}++; } } # search for defined values for each %seen_dates key. my @seen_dates = grep { defined $seen_dates{$_} } keys %seen_dates; ### @seen_dates

Igor 'izut' Sutton
your code, your rules.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-25 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found