On Jul 13, Tom Dubs said:

>while (<TEMP>) {
>
>        $strip = /\w+/;
>        print "$strip \n";
>}

A regular expression in scalar context returns true or false.  If you want
to get at a specific part of the match, you need to:

  1. use capturing parentheses, and
  2a. use list context, OR
  2b. use the $DIGIT variables

Here are two examples:

  $_ = "Jeff is brother #734";

  my ($num) = /(\d+)/;
  /(\w+)/;

  print "$num, $1\n";  # 734, Jeff

The list context is made by the (...) on the LEFT-HAND side of the equals
sign.

      $num  = ...;    # scalar
     ($num) = ...;    # list
  my  $num  = ...;    # scalar
  my ($num) = ...;    # list

The $1 variable corresponds to the FIRST capturing parentheses of the most
recent successful regex.

For more information, read:

  perldoc perlretut
  perldoc perlre

  "Regular Expressions in Perl"
     http://www.pobox.com/~japhy/docs/book.html

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to