navalned has asked for the wisdom of the Perl Monks concerning the following question:
I have the following code that seems to work thus far. However, it just feels like there is a better way to do it. If so I'd love to see it.
use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 0; my $file = "test"; my @data; { local $/ = undef; open FILE, "$file" or die $!; while (my $line = <FILE>) { push @data, split /XXX/, $line; # I thought it should be /^XXX$/, but that didn't work } } @data = grep /\S/, @data; # I don't understand why I had to do this print Dumper \@data;
This gives the following correct output:
$VAR1 = ['This is a test.','This is a multiline test.']
The file looks like so:
This is a test. XXX This is a multiline test. XXX
2018-10-07 Athanasius put code tags around script output and file contents
|
|---|