in reply to Partial string match -- with a twist.

What you want to match is: /(node[0-9]*)/

If you match on .* that means "everything else" and that's exactly what you got.
  • Comment on Re: Partial string match -- with a twist.

Replies are listed 'Best First'.
Re^2: Partial string match -- with a twist.
by smw6181 (Initiate) on Jul 20, 2012 at 13:55 UTC
    Revised code:

    if ($key =~ m/(node[0-9]*)/) { if ($key = $1) { print "You entered " .$key. ":" . $ref->{$key}. "\n"; } }
    That did the trick. Amazing how something so simple can be so easily missed. Thank you both very much.

      This form of matching is more common:
      if ($key =~ m/(node[0-9]*)/) { print "You entered " .$1. ":" . $ref->{$1}. "\n"; }
      Sorry if my advice was wrong.

        That works as well and is cleaner looking. Thanks to you as well. :)

        That works as well and is cleaner looking. Thanks!