use strict; sub runCLIcommand { local *STDERR; my $lineSTDERR; my $returnValue = 0; open STDERR, '>', \$lineSTDERR; # This simulates what would in reality come from a command line interface. # In reality I would invoke: commands::display::ssh::run(); # which in turn would print to STDOUT. print "%dsadada ssadasd\n"; # Hash symbol does not cause a problem, which I think is inconsistent? print "@dsadada sdsadasd\n"; # Problem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! print "$dsadada sdsadasd\n"; # Problem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Looks for these declarations: my @dsadada; my $dsadada; # Check that there was nothing written to STDERR, which implies # everything went alright. if (length($lineSTDERR) > 0) { $returnValue = 1; } return $returnValue; } sub processCLIoutput { my $array_ref = $_[0]; my @array = @$array_ref; for (my $i = 0; $i < @array; $i++) { $array[$i] =~ s/^\s*//; $array[$i] =~ s/\s*$//; # Not a neat solution plus, doesn't work in the simulation, # since the print command itself gets there first. $array[$i] =~ s/\$/DOLLAR/g; $array[$i] =~ s/\@/ARRAY/g; $array[$i] =~ s/\%/HASH/g; } return \@array; } sub getSshDetails { local *STDOUT; my @sshDetails = (); my @capturedSTDOUT; my $lineSTDOUT; my $array_ref; open STDOUT, '>', \$lineSTDOUT || die "Could not open STDOUT. $!"; # Anything that is printed to STDOUT from now on is captured in the buffer # $linesSTDOUT. Is there some kind of syntax I can use here that disables # variable expansion of the captured output???????????????????????????????????????????? if (runCLIcommand() != 0) { die "CLI command did not run successfully. \n"; } @capturedSTDOUT = split(/\n/, ($lineSTDOUT)); $array_ref = processCLIoutput(\@capturedSTDOUT); @sshDetails = @$array_ref; return \@sshDetails; } ################################################################### # main: ################################################################### my $array_ref = getSshDetails(); my @array = @$array_ref; for (my $i = 0; $i < @array; $i++) { print "Array entry: ". $i. "\t". $array[$i]. "\n"; }