Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'd say you're on the right track. As long as you apply the regex to tear the 'MONKEY' part out of column 3 before you check to see if you've seen it before, you should do just fine.

I would make one pass through each line to build a hash with the value from column 3 as the key pointing to a hashref with num_false (a count) and col1_vals (an arrayref). Then I would go through each key of that hash and run the calculations you want to run. I'm thinking something like this (assuming your lines are in @lines):

my %seen = (); foreach my $line (@lines) { my @values = split ',', $line; my $col1_val = $values[0]; my $key = $values[2]; my $true_or_false = $values[7]; $key =~ /^LOGGED IN (\w+) GET/; $key = $1; $seen{$key}->{num_false}++ if $true_or_false eq 'false'; push @{$seen{$key}->{col1_vals}}, $col1_val; } foreach my $key (keys %seen) { my $calcd = calculate_stuff($seen{$key}->{col1_vals}); my $num_false = $seen{$key}->{num_false}; print <<HERE; Key: $key Calc'd values: $calcd Num false: $num_false HERE }

I just took a stab at guessing the proper regex (for example: are spaces allowed?) because I don't know what all your input looks like, but the basic idea holds.


In reply to Re: Hashes, Arrays, and Confusion -- In a bit over my head! by Riales
in thread Hashes, Arrays, and Confusion -- In a bit over my head! by bpthatsme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found