Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm a baby monk only... ;)

Have to admit I have never seen @_ used for anything else than for function arguments, and I don't exactly understand push @data, [@_]; Using @_ seems nice and intuitive, applying it to my example gives me:

use strict; my $output = <<EOD; 4865FA9B 0702 P H rmt0 TAPE OPERATION ERROR DE9A52D1 0704 I S rmt0 DEVICE DUMP RETRIEVED 4865FA9B 0701 P H rmt2 TAPE OPERATION ERROR F3E9B3E2 0620 I O SYSJ2 UNABLE TO ALLOCATE SPACE IN FILE SY +STEM DCB47997 0511 T H hdisk4 DISK OPERATION ERROR EOD my (@data, %identifier); for my $line (split /\n/,$output) { @_ = split /\s+/, $line, 6; push @data, [@_]; $identifier{$_[0]} = $data[-1]; # Index for first field } # Sort on multiple fields, in this case 4th (class) and 2nd (time)... print "\@data:\n"; for my $rec (reverse sort {$a->[3] cmp $b->[3] || $a->[1] <=> $b->[1]} + @data) { print "Error ID: $rec->[0] Time: $rec->[1]\n"; }

Also, if i understand you right, %identifier contains a hash of array references which I can use to access @data elements e.g.

print "key $_ value: $identifier{$_}->[0]\n" for (keys %identifier);

Thanks for the help!

Niel


In reply to Re^2: Hash keys affect sorting by 0xbeef
in thread Hash keys affect sorting by 0xbeef

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 rifling through the Monastery: (3)
As of 2024-03-29 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found