Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by izut (Chaplain)
on Feb 15, 2007 at 11:17 UTC ( #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
Node Status?
node history
Node Type: note [id://600182]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2021-03-02 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (63 votes). Check out past polls.

    Notices?