[pm-h] Perl Code
Michael R. Davis
mrdvt92 at yahoo.com
Fri Jun 19 15:34:43 PDT 2020
PM,>And Uri has a very good point about needing to include some way to verify that the regex actually matched and returned values.
I always - put the regexp in a condition - use the optional "m" - use m{} if the regexp has a "/" in it. - use \A for ^ - use \Z for $ - use (?:) when group not needed in $N
- and assign $N to well named scoped variables before anything else.
if ($string =~ m/\A(.)(?:.)(.)\Z/) { my $char1 = $1; my $char3 = $2;
dosomething($char1, $char3);} else {
die("handle string not what expected");}
Michael R. Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/houston/attachments/20200619/12254471/attachment.html>
More information about the Houston
mailing list