in reply to Qwestion about Automatic Match Variables
Using warnings or launching perl with the -w switch would have told you that there is a problem:
> perl -w tmp.pl Possible unintended interpolation of @gmail in string at tmp.pl line 5 +. Name "main::gmail" used only once: possible typo at tmp.pl line 5. Terminating on signal SIGINT(2)
... and using strict would have prevented that error completely as it forces you to predeclare variables:
> type tmp.pl #!/usr/bin/perl use strict; while (<>) { # take one input line at a time chomp; if (/(dmathis@gmail.\w+)/) { print "Matched: |$`<$&>$'|\n"; # the special match vars } else { print "No match: |$_|\n"; } } > perl -w tmp.pl Possible unintended interpolation of @gmail in string at tmp.pl line 6 +. Global symbol "@gmail" requires explicit package name at tmp.pl line 6 +. Execution of tmp.pl aborted due to compilation errors.
You need to escape the @ because Perl interprets this as the start of the name of an array:
... if (/(dmathis\@gmail.\w+)/) { ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Qwestion about Automatic Match Variables
by dbmathis (Scribe) on Sep 22, 2008 at 13:39 UTC | |
by wol (Hermit) on Sep 22, 2008 at 14:27 UTC |