> Bryan R Harris wrote:
>> 
>>>> returns "true" or "false" (1 or '') and in list context it returns the
>>>> contents of any capturing parentheses in the pattern.
>>>> 
>>>> The expression:
>>>> 
>>>> ( $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i
>>>> )[ 0 ]
>>>> 
>>>> is a list slice so the regular expression is in list context but the slice
>>>> is
>>>> a single value so the expression is a scalar.
>>>> 
>>>> The || operator will only work with scalar values, not with lists, so this
>>>> works because the list has been converted to a scalar with the list slice.
>>>> 
>>>> John
>>> ********************************************
>>> the list context represents everything between the / /
>>> and the slice context represents [ 0 ] which is
>>> assigned as a scalar to $ptypeline.
>>> 
>>> Correct?
>> 
>> 
>> Any time you surround something with parenthesis () it is considered "list
>> context", i.e.
>> 
>> Scalar context:   $a = $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i;
>> 
>> In scalar context, perl is trying to assign a scalar to $a.  In scalar
>> context that expression returns a 1 or 0 depending on whether it was able to
>> find that regular expression inside of $ptypeline.  (Or if I had a /gi at
>> the end it would return the number of matches it found).
>> 
>> List context:  @a = ($ptypeline =~ /movable.+(sine|geo|radial|ortho)/i);
>> 
>> This is list context, meaning that perl is trying to get a list out of that
>> expression.  In list context, that expression returns whatever items it
>> found in sets of parenthesis -- in this case, if ptypeline had "ortho", @a
>> would be ("ortho").
> 
> No.  It is list context because "@a =" forces list context.  In other words:
> 
> @a = ( $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i );
> 
> and:
> 
> @a = $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i;
> 
> are both in list context, the parentheses are superfluous.  However in:
> 
> $a = $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i;
> 
> the expression is in scalar context because "$a =" forces scalar context.
> Even if you add parentheses:
> 
> $a = ( $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i );
> 
> it is still in scalar context, while:
> 
> ( $a ) = $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i;
> 
> is in list context because $a is now part of a list.


Umm...  So would this do what I want also?

($ptype)=($projection =~ /movable.+(sine|geo|radial|ortho)/i)
              or $ptype="(missing)";

It seems to...

- B




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to