I'm trying to create an array-of-arrays with some data in a for loop. The regex command in the code below helps me to gather the scalars that I will place in it. As far as I know, that is correct, but when I try to output the @output array to a CSV file I receive a "Can't use string () as an ARRAY ref while "strict refs" in use." error. Is this because of the way I am creating the array or the way I'm trying to write it into a file?
foreach my $row(@input){
my @cmd = qx("command");
foreach my $line(@cmd){
if($line =~ /regex/){
push(@output, ($sp_name, $sp_port, $sp_type, $sp_uid));
}
}
}
The code below is what I am using to create my output file::
my $csv = Text::CSV->new()
or die "Cannot use Text::CSV ($!)";
my $file = "output.csv";
open my $fh, '>', $file
or die "Cannot open $file ($!)";
$csv->eol("\n");
foreach my $row (@output)
{
$csv->print($fh, \@{$row})
or die "Failed to write $file ($!)";
}
close $fh
or die "Failed to close $file ($!)";
\@{$row}back to the simpler$row.