So I will assume you wanted the regex at ' if ($command eq "!1\n") ' and you are having the problem with the special regex vars because you are falling out of scope (because you are trying to access the regex vars after)
$command = $block; }
What you can do, is while the special regex vars are in scope and that scope is defined by a successful match you can assign $1 to a variable that is defined in the scope you would like to use it in.
eg. (untested code)
my $input = <STDIN>; chomp $input; my $script_name = ''; #This is in the main scope if ($input =~ /runme(.+)$/) { $script_name = $1; #$1 is in the scope of #the 'if' block } if ($script_name) { print "Running $script_name\n"; } else { print "Running $input\n"; }
Please check out Coping with Scoping if this is your problem.
Please, always post the relevant code, that has been run by you with strict and warnings on.
grep
| Mynd you, mønk bites Kan be pretti nasti... |
In reply to Re: Accessing /$\d/
by grep
in thread Accessing /$\d/
by Adam_
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |