in reply to What happens with empty $1 in regular expressions? (was: Regular Expression Question)
So there is a method now doing the checking and returning the value of $1. What is creating the 'undef' value though, is the use of 'strict'. From what I understand, using strict causes variables to be isolated to the block of code they are declared in, and when that block is finished the variable is destroyed. So $1 would be destroyed at the end of the routine after the value is returned. It works though, this way you definitely have an 'undef' value to play with if that is what you are after.use strict; my $i = "mmmm9"; my $a = match_rtn( $i ); print $a, "\n"; $i = "mmm"; $a = match_rtn( $i ); print $a, "\n"; sub match_rtn { my $str = shift; $str =~ m/(\d+)/; return $1; }
I looked up exactly what 'strict' is supposed to do, and the Camel book says its supposed to disallow "unsafe" code. My question to anyone else is what is considered "unsafe"?
Amel - f.k.a. - kel
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regular Expression Question
by danger (Priest) on Feb 28, 2001 at 22:25 UTC | |
by merlyn (Sage) on Feb 28, 2001 at 22:30 UTC | |
by danger (Priest) on Feb 28, 2001 at 23:29 UTC | |
|
Re: Re: Regular Expression Question
by chipmunk (Parson) on Mar 01, 2001 at 00:40 UTC | |
by dsb (Chaplain) on Mar 01, 2001 at 00:47 UTC | |
by chipmunk (Parson) on Mar 01, 2001 at 01:05 UTC | |
by tye (Sage) on Mar 01, 2001 at 00:57 UTC |