in reply to Problems removing leading whitespace

print Dumper($result); $VAR1 = [ " echo ", " ----------", ...

$result is a reference to an array of strings. You can access the actual array via @$result (perlreftut, perlref). You can simply use this to remove the leading whitespace from all the elements of $result: s/^\s+// for @$result;

Update: Also, your sub remove_leadspace is designed to return a modified list of strings, but you're not doing anything with its return value. You could do: @$result = remove_leadspace(@$result); or my @trimmed = remove_leadspace(@$result);

Replies are listed 'Best First'.
Re^2: Problems removing leading whitespace
by Anonymous Monk on Jan 30, 2020 at 16:22 UTC

    Expanding on this:

    In the original implementation, you call remove_leadspace() without assigning its result to anything. This means that wantarray is undef, so the original implementation of remove_leadspace() returns without doing anything.

    Because in Perl there is More Than One Way To Do It, another implementation would be something like:

    sub remove_leadspace( s/^\s+// for @{ $_[0] }; return; }

    This is called by remove_leadspace( $result ). That is, it expects a single argument which is an array reference, modifies the elements of the array (note that the /r qualifier qas removed from the s///), and returns nothing.

Re^2: Problems removing leading whitespace
by Anonymous Monk on Jan 30, 2020 at 12:13 UTC

    Fantastic, many thanks for the prompt reply