On Wednesday, August 13, 2003 10:45, [EMAIL PROTECTED] wrote:

>I've been reading the previous post and was wondering about what qr does in

>this code.
>
>use strict;
>  use warnings;
>
>  my @array = (
>    qr'^to: myprog'mi,
>    qr'^from: [EMAIL PROTECTED]'mi
>  );
>
>  my $str = 'To: myprog with trailing text';
>
>  foreach (@array) {
>    print "found\n" if $str =~ $_
>  }

>From "perldoc -q perlop"

qr/STRING/imosx

This operator quotes (and possibly compiles) its STRING as a regular
expression. STRING is interpolated the same way as PATTERN in m/PATTERN/. If
``''' is used as the delimiter, no interpolation is done. Returns a Perl
value which may be used instead of the corresponding /STRING/imosx
expression. 

    For example,

    $rex = qr/my.STRING/is;
    s/$rex/foo/;

    is equivalent to

    s/my.STRING/foo/is;

In your case, that means for the first array item, the line translates to:
  print "found\n" if $str =~ '^to: myprog'mi
Which could also be written as
  print "found\n" if $str =~ /^to: myprog/mi

It prints "found=n" if $str starts with "to: myprog".  The 'm' modifier says
to treat the string as multiple lines, and the 'i' modifier says to ignore
case.

For the second array item, the line translates to:
  print "found\n" if $str =~ '^from: [EMAIL PROTECTED]'mi
Which could also be written as
  print "found\n" if $str =~ /^from: [EMAIL PROTECTED]/mi

It prints "found=n" if $str starts with "from: [EMAIL PROTECTED]".  Same notes
on the modifiers.

HTH,

Alan

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

Reply via email to