http://qs321.pair.com?node_id=111068


in reply to split question

Change =~ to = and you'll get the results you expect, though a regex is probably a better approach for this one anyway.

-Blake

Replies are listed 'Best First'.
Re: Re: split question
by John M. Dlugosz (Monsignor) on Sep 09, 2001 at 23:43 UTC
    So just what is the meaning of what he wrote, putting split, rather than m, s, tr, or y, after the =~ ?
      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. ;)