in reply to Re: split question
in thread split question

So just what is the meaning of what he wrote, putting split, rather than m, s, tr, or y, after the =~ ?

Replies are listed 'Best First'.
Re: Re: Re: split question (Calling functions with =~)
by charnos (Friar) on Sep 10, 2001 at 01:40 UTC
    This is just a "for the record" post, as the answer has obviously already been given, but what the heck. I did a little experimenting (because I didn't know this before hand) with wantarray() in subs, and assuming that builtin functions work the same way, what actually happens goes something like this. Whenever a line of code like:
    @list =~ sub_or_function(); # or $scalar =~ sub_or_function();
    appears, the sub is called in scalar context (at least it did in the simple sub i wrote, which just printed out the context based on the value of wantarray()). So for split(), the return value would be 2, since the scalar version of split returns the number of fields the string was split into. So essentially, the line comes down to this:
    ($remainder, $working) =~ 2;
    which won't effect either variable, since =~ is only a binding operator, and does not assign value. Which is why your code left the values intact after attempting to change them. Also, that line of code will not work with warnings on, as I get "Use of implicit split to @_ at line.." when I ran the code with warnings on. Of course, this is only my interpretation of the results that I recieved, and could very well be wrong. ;)