in reply to Re^2: Benchmark diamond operator
in thread Benchmark diamond operator

You need to understand what the diamond operator does:

That's pretty much it. I might be forgetting some subtleties.

The key bit, I've highlighted for you in bold. It uses @ARGV to figure out what file to read, and it alters that array!

So the first time you read a file using the diamond operator, you read it fine. The second time you try to read the file, the filename is no longer on @ARGV, so the diamond operator reads from STDIN instead.

Replies are listed 'Best First'.
Re^4: Benchmark diamond operator
by thanos1983 (Parson) on May 10, 2017 at 08:50 UTC

    Hello again tobyink,

    Thanks for the analytical explanation. I knew that the error was coming because it was reading the STDIN and it was expecting to be fed but I did not know how to overcome this problem.

    Very nice trick to store the @ARGV temporarily on an array and then call it infinite times since it is not altered every time the loop runs. So simple and very clever at the same time.

    Thank you for your time and effort.

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