in reply to push with interpolated variable

push (@array, $value);
is the same as
push @array, "$value";
But when you say
push @array, "$value ";
you add a space at the end of $value.

holli, regexed monk

Replies are listed 'Best First'.
Re^2: push with interpolated variable
by mpeters (Chaplain) on Jan 19, 2005 at 19:26 UTC
    Also, by saying "$value" you are making perl treat $value in string context when it might not be at string but a number, or a boolean, or a reference, or an object, etc.
Re^2: push with interpolated variable
by Anonymous Monk on Jan 20, 2005 at 10:20 UTC
    push (@array, $value);
    is the same as
    push @array, "$value";
    It's not.
    #!/usr/bin/perl use strict; use warnings; my (@array, $value); @array = ("foo"); $value = []; push(@array, $value); $array[-1][0] = "bar"; print $array[-1][0], "\n"; @array = ("foo"); $value = []; push @array, "$value"; $array[-1][0] = "bar"; print $array[-1][0], "\n"; __END__ bar Can't use string ("ARRAY(0x818427c)") as an ARRAY ref while "strict re +fs" in use
      Indeed. I assumed $value contains a simple scalar (a string or a number). If $value contains a reference then "$value" is stringified.

      Thanks for the clarification, i never thought about that.

      holli, regexed monk