in reply to How is this printing?

When you use a regular expression to match something (i.e.) $html =~m/<A HREF=\"(.*?)\"/g) the parenthesis around ->.*?<- capture the result of the match, and stores it in a special variable ->$n where n is a number indicating the parenthesis group.

Ok - let me try an example, it may be clearer

$a="123abc345" $a=~/123(.*?)345/; # $1 is now equal to "abc" $a=~/(123).*?(345)/; # $1 is now "123" and $2 is "345" $a=~/(xyz).*/; # $1 is still "123" because there was # no match

Replies are listed 'Best First'.
Re^2: How is this printing?
by muba (Priest) on Oct 16, 2004 at 14:47 UTC
      Nope, I'm not exactly sure if I understand what you are asking, but here's my best guess...

      Consider the following code and result

      foreach ("abc123", "xyz123","def12","ghi123") { /(.*)123/; print "scanning $_: found $1\n"; } __DATA__ scanning abc123: found abc scanning xyz123: found xyz scanning def12: found xyz scanning ghi123: found ghi <code> Notice that while scanning "<code>def12
      " the "$1" variable was not reset to undef but remains in its previously defined state.

      Was this what you were asking?