in reply to What is the logical error here (Fixed, but I want to understand)

If you look at the documentation of split from 5.10.1: "In scalar and void context it splits into the @_ array." Then, from here: "split() no longer modifies @_ when called in scalar or void context. In void context it now produces a "Useless use of split" warning. This was also a perl 5.12.0 change".

Replies are listed 'Best First'.
Re^2: What is the logical error here (Fixed, but I want to understand)
by hghosh (Acolyte) on Jun 07, 2019 at 14:48 UTC
    Does "split() no longer modifies @_" mean that it will not return the output of its call to the variable @_? As in,  split(\/t\, $line) will not work, but  my @array = split(\/t\, $line) will work?
      Does "split() no longer modifies @_" mean that it will not return the output of its call to the variable @_? As in, split(\/t\, $line) will not work, but my @array = split(\/t\, $line) will work?

      Yes, that's it. In your first piece of code, you were using split in "void context" because you weren't doing anything with the return value, in which case Perl before v5.12 used to store split's return value in the @_ variable, which is why you could access it via $_[0] etc. That is no longer the case, and you need to use split's return value explicitly, such as by storing it in an array, like you did in your second piece of code.