Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

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

With a little ambition you might have taken my example and run with it, adapting it to your needs. But here's the updated version that more closely accomplishes what you're asking, now that the details are known. Honestly, the only significant change was to how I formatted the output of the sample script. The script was already capable of handling data formatted in just about any way, so long as the formatting is accomplished with what Perl thinks of as space (\n\t\r and ' ')

use strict; use warnings; my $input = <<HERE; log1 123 log1 233 log1 223 log2 465 log2 231 log2 456 HERE my %groups; { my @items = split /\s+/, $input; while ( @items ) { push @{$groups{ +shift( @items ) }}, shift( @items ); } } { local $" = "\t"; print "$_\n@{$groups{$_}}\n\n" foreach sort keys %groups; } __OUTPUT__ log1 123 233 223 log2 465 231 456

My second example uses a HERE doc to illustrate input in the form of a tabular list. Also, I played around with scoping a bit to keep variables confined to narrower scopes... not really necessary, but you've got to let me have a little fun with it too. ;)

If this is your first post to the Monastery, let me point out that when you post nodes, your input needs HTML-like markup, or else it will lose all formatting. Prior to your initial post being edited by a janitor (me), it was impossible to tell that your input data was in a tabular format. After adding simple code tags, it became apparent that you were presenting tabular format data. Please do read the PerlMonks FAQ for details on formatting your posts with PerlMonks HTML tags.


Dave


In reply to Re^3: key and values help by davido
in thread key and values help by Anonymous Monk

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 exploiting the Monastery: (5)
As of 2024-04-18 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found