Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by Marshall (Canon)
on Mar 02, 2021 at 22:14 UTC ( #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? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2022-11-27 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?