Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: split question

by blakem (Monsignor)
on Sep 08, 2001 at 03:01 UTC ( #111068=note: print w/replies, xml ) Need Help??

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.


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. ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://111068]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2017-05-28 02:27 GMT
Find Nodes?
    Voting Booth?