PS: The above will not work unless you remove the '@' and '$' from the print statements. For some reason this is not a problem for the % symbol which, I find inconsistent. Surely the same attempt at variable expansion would apply to all the primitives.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 in +terface. # 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 th +e buffer # $linesSTDOUT. Is there some kind of syntax I can use here that d +isables # 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"; }
In reply to How do I disable variable expansion of strings? by seank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |