Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Applying a regular expression to a string

by ysth (Canon)
on Apr 04, 2005 at 11:54 UTC ( [id://444634]=note: print w/replies, xml ) Need Help??


in reply to Applying a regular expression to a string

=~ is not related to the ~ operator; the assignment variant of ~ would be ~=, except that ~ is a unary operator and so has no assignment variant.

What you want is to select everything before the first \s, and assign that to $message_id; use a match, not a substitution, to do that:

($message_id) = $message =~ /^(\S*)/;
(Note the parentheses around $message_id that make it a list assignment; you need to do the assignmentmatch in list context to have it return anything besides success/failure.)

Replies are listed 'Best First'.
Re^2: Applying a regular expression to a string
by mw (Sexton) on Apr 07, 2005 at 07:50 UTC
    Simple and elegant. I will start using this construct as soon as I next come across this type of problem. Thank you all.

Log In?
Username:
Password:

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

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

    No recent polls found