Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: File Manipulation

by 2teez (Priest)
on Aug 23, 2013 at 12:46 UTC ( #1050667=note: print w/ replies, xml ) Need Help??


in reply to File Manipulation

Hi,
You have been given great solutions, but in the spirit of "tim today", you could also check this (a somewhat modifications to the solutions already given):

use strict; use warnings; my %logger; my $key; while(<DATA>){ s/\s+$//; if(/\[(.*)\]/){ $key = $1; }else{push @{$logger{$key}}, $_;} } print $_,":", join ("," => @{$logger{$_}}),$/ for sort {$a cmp $b} keys %logger; __DATA__ [server1] /tmp/location1/file.log /tmp/location2/file.log [server2] /usr/loc1/file.log /usr/loc2/file.log [server3] /citrix/dir3/file.log
NOTE:
Since, the key only changes, when the name of server is seen, and that until the next one. It works perfectly well.
You could also see perldsc

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: File Manipulation
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-07-14 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (258 votes), past polls