You, unfortunately did not post the relevant code where you performed the regex match.

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_

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.