http://www.perlmonks.org?node_id=1050635


in reply to File Manipulation

I would use a simple array of arrays where the first element of each sub-array is the server, like this:

use strict; use warnings; my @logs; while(<DATA>){ push @logs, [ $1 ] if /\[(.*)\]/; push @{$logs[-1]}, $1 if /^(\/.*)/; } print shift @$_, ":", join( ",", @$_ ), "\n" for @logs; __DATA__ [server1] /tmp/location1/file.log /tmp/location2/file.log [server2] /usr/loc1/file.log /usr/loc2/file.log [server3] /citrix/dir3/file.log