Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: split question

by John M. Dlugosz (Monsignor)
on Sep 09, 2001 at 23:43 UTC ( [id://111317]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://111317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2024-04-18 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found