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+)/) { ...
In reply to Re: Qwestion about Automatic Match Variables
by Corion
in thread Qwestion about Automatic Match Variables
by dbmathis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |