Re: What are the uses of the =~ operator?

2002-01-16 Thread Steven Brooks

On Wednesday 16 January 2002 03:56 pm, rabs wrote:
 I am new to regualr expressions and becoming  accqainted with the =~
 operator. It appears to me that the =~ allows me to match a pattern in a
 REGEX against a variable. As such it  replaces the $_ varible.

 $name =~ /[rabs]/;

 mtaches with a string containing   any of the following characters   r a b
 s

 is this correct? I am quite confused

The following text is from the perlop man-page (perldoc perlop)  -- Steven

Binary =~ binds a scalar expression to a pattern match.
   Certain operations search or modify the string $_ by
   default.  This operator makes that kind of operation work
   on some other string.  The right argument is a search pat­
   tern, substitution, or transliteration.  The left argument
   is what is supposed to be searched, substituted, or
   transliterated instead of the default $_.  When used in
   scalar context, the return value generally indicates the
   success of the operation.  Behavior in list context
   depends on the particular operator.  See the Regexp Quote-
   Like Operators entry elsewhere in this document for
   details.

   If the right argument is an expression rather than a
   search pattern, substitution, or transliteration, it is
   interpreted as a search pattern at run time.  This can be
   less efficient than an explicit search, because the pat­
   tern must be compiled every time the expression is evalu­
   ated.

   Binary !~ is just like =~ except the return value is
   negated in the logical sense.

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




Re: What are the uses of the =~ operator?

2002-01-16 Thread John W. Krahn

Rabs wrote:
 
 I am new to regualr expressions and becoming  accqainted with the =~
 operator. It appears to me that the =~ allows me to match a pattern in a
 REGEX against a variable.

Yes.

 As such it  replaces the $_ varible.

No, a regular expression will not replace anything and does not affect
the $_ variable.

 $name =~ /[rabs]/;

Anything between the [ and ] is a character class not a regular
expression.

 mtaches with a string containing   any of the following characters   r a b s
 
 is this correct? I am quite confused

Yes.



John
-- 
use Perl;
program
fulfillment

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