in reply to Localized Backreferences, If Statements & Blocks
Apparently, stuff inside of the braces on an if statement is not localized. Therefore, the behaviour of $1 does not fit any of the conditions you specified from the Camel. I learn something new about Perl every day :)#!/usr/bin/perl -w use strict; $|++; my $valid ='realgoodname'; my $invalid ='bad name'; my ($test1,$test2); { if ($valid =~ /^([a-z]+)$/i){ $test1=$1; } } { $invalid =~ /^([a-z]+)$/i; $test2=$1; die "Invalid test2" unless $test2; } print "Valid word\t= $valid\nInvalid word\t= $invalid\n\n"; print "Valid test\t= $test1\nInvalid test\t= $test2\n"; exit();
Cheers,
Ovid
Update: Duh! The regex wasn't in the block. It's amazing how simple these things often turn out to be. Thanks, chromatic.
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: (Ovid) Re: Localized Backreferences
by chromatic (Archbishop) on Sep 15, 2000 at 06:18 UTC | |
by doran (Deacon) on Sep 15, 2000 at 07:38 UTC | |
|
RE (tilly) 2: Localized Backreferences
by tilly (Archbishop) on Sep 15, 2000 at 12:58 UTC |