in reply to Benchmark diamond operator

Hi, if I understand you correctly, the issue is that the diamond operator uses shift to iterate through @ARGV, so the second sub will find it empty.

$ perl -Mstrict -Mwarnings -E 'say "starting: " . scalar @ARGV; while( +<>){chomp; say "$_\nremaining: " . scalar @ARGV}' foo bar baz
starting: 3 foo remaining: 2 bar remaining: 1 baz remaining: 0

Hope this helps!

Update: added demo


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Benchmark diamond operator
by thanos1983 (Parson) on May 09, 2017 at 14:47 UTC

    Hello 1nickt ,

    I assume the same, but how can I make my script to stop after parsing the first input? I want to avoid using @ARGV but this would be my last option.

    Any ideas? Thanks for your time and effort.

    Seeking for Perl wisdom...on the process of learning...not there...yet!