Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • You can also:

    push @array, @{ $x || [] };

    It is not pretty, but anyway :-)

    Igor Sutton
    • If $x is not a long and complex expression, then readability would command to use push @array, @$x if $x;.

      Note that the really equivalent code would be this:

      $x = [] if not defined $x;
      push @array, @$x;

      Or in 5.10 parlance:

      push @array, @{ $x //= [] };

      Because the reason that the for loop doesn’t throw an error is that it because it aliases $_ to each element, rather than copying, it has to provide lvalue context on each iteration, which means it must also provide lvalue context to the containe