in reply to breaking up a file by delimiter
I would write it something like this:
use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 0; my $file = "test"; # Use lexical file handles and 3-argument form of open # See http://modernperlbooks.com/mt/2010/04/three-arg-open-migrating-t +o-modern-perl.html open my $fh, '<', $file or die "error opening '$file': $!"; # Slurp file contents into string $contents # See http://modernperlbooks.com/mt/2009/08/a-one-line-slurp-in-perl-5 +.html my $contents = do { local $/; <$fh> }; close $fh; # Split contents into fields by XXX on a line by itself (note the /m m +odifier) my @fields = split /^XXX$/m, $contents; # Tidy up newlines/spaces in multiline fields for (@fields) { tr/\n/ /s; s/^ +//; s/ +$//; } print Dumper \@fields;
Update: See Also
|
|---|