Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: regexp word break help

by George_Sherston (Vicar)
on May 01, 2002 at 11:42 UTC ( [id://163238]=note: print w/replies, xml ) Need Help??


in reply to Re: regexp word break help
in thread regexp word break help

I really like that, partly because I don't understand quite why it works. Without the brackets $str would be set to "1", which I take to be the return value of the successful pattern matching.

But why do the brackets stop this happening? I should have thought that $str and ($str) wd behave the same way.

And then why do they not perform this function in ($str) = $str =~ s/(.{1,45})\b/foo/s;, in which $str gets set to "1"?

/me backs respectfully away from the shrine...

§ George Sherston

Replies are listed 'Best First'.
Re: Re: Re: regexp word break help
by buckaduck (Chaplain) on May 01, 2002 at 12:39 UTC
    I should have thought that $str and ($str) wd behave the same way.

    This node explains the difference between list context and scalar context very well. Many of the replies have great links to some interesting articles on the subject.

    And then why do they not perform this function in ($str) = $str =~ s/(.{1,45})\b/foo/s;, in which $str gets set to "1"?

    The perlop manpage explains the return values of the m/// and s/// operators in list and scalar context. The s/// operator returns the number of substitutions in either context.

    buckaduck

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found