Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Looking for alternative syntax for assigning variables based on regex matches

by Marshall (Canon)
on Mar 02, 2021 at 22:14 UTC ( [id://11129033]=note: print w/replies, xml ) Need Help??


in reply to Looking for alternative syntax for assigning variables based on regex matches

An idea for you:
use strict; use warnings; my $foo ="some hello message"; my ($hello) = $foo =~ /(hello)/; $hello //= ''; # null string if "hello" was not found __END__ $hello will be either "hello" or a null string. Better than an undef value. Amongst other things, this maintains a "printable value" for $hello. use $hello in a Boolean context. $foo is a string. Do not reuse that string variable name to mean something different. Create new Boolean variable.
  • Comment on Re: Looking for alternative syntax for assigning variables based on regex matches
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found