Stories
Slash Boxes
Comments
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.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • This isn’t better, but in the spirit of TMTOWTDI and of the select idiom from perldoc -q unbuffer

    sub get_log { @{ ( [@log], @log=() )[0] } }

    Or to do away with the array-copy, assuming you have set up with “my $log = []” instead:

    sub get_log { @{ ( \@$log, $log=[] )[0] } }

    The \@$ construction is there to force Perl to make a new copy of the array reference in $log. That way the first list element is a copy of $log instead of an alias, and therefore unaffected by the overwriting of $log in the next expression.

    But the splice solution is lightyears ahead.