> -----Original Message-----
> From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 17, 2001 8:58 AM
> To: Beginners (E-mail)
> Subject: help with SWITCH
> 
> 
> Folks,
> 
> I have this little bit of code that was recommended by Peter 
> Scott (not the
> actual code, but he recommended using a SWITCH)
> 
>        if ($test = /($regex)/o) {
>            SWITCH: for ($test){ # I think this is the problem 
> right here,
> not sure though

The assignment:

   $test = /($regex)/o

Evaluates the right-hand side in scalar context, since $test is a scalar.

>From perldoc perlop:

      m/PATTERN/cgimosx
      /PATTERN/cgimosx
              Searches a string for a pattern match, and in scalar context
              returns true if it succeeds, false if it fails.
              ...
              If the "/g" option is not used, "m//" in list context returns
              a list consisting of the subexpressions matched by the
              parentheses in the pattern, i.e., ("$1", "$2", "$3"...).

and from perldoc perldata:

      Assignment is a little bit special in that it uses its left argument
      to determine the context for the right argument.  Assignment to a
      scalar evaluates the right-hand side in scalar context, while
      assignment to an array or hash evaluates the righthand side in list
      context.  Assignment to a list (or slice, which is just a list anyway)
      also evaluates the righthand side in list context.

So you need to force list context, which you do by placing the left-hand
side in parens:

   ($test) = /($regex)/o

This evaluates the m// in list context, since ($test) is a list. See
perldoc perldata "List value constructors"

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to