I am trying to use Perl to parse output from a (C-based) program. Every output line is a (1D) Perl array, which I sometimes want to store (based on certain conditions).
I now wish to (deep) copy an array when its first element has a certain keyword, and print that same copied array if another keyword matches in a later line-array.
So far, I have attempted the following:
#!/usr/bin/env perl
use strict; # recommended
use Storable qw(dclone);
...
while(1) # loop over the lines
{
# subsequent calls to tbse_line contain
# (references to) arrays of data
my $la = $population->tbse_line();
my @copy;
my $header = shift @$la;
# break out of the loop:
last if ($header eq 'fin');
if($header eq 'keyword')
{
@copy = @{ dclone \@$la };
}
if($header eq 'other_keyword')
{
print "second condition met, print first line:\n"
print "@copy\n";
}
}
However, this prints an empty line to the screen, instead of the contents of the copied array. I don't have a lot of Perl experience, and I can't figure out what I am doing wrong.
Any idea on how to go about this?