Re: in the elemetns of programming perl , I need help with 2 lines that I don't understand

[email protected] (Richard Lee)
Newsgroups perl.beginners
Message-ID <[email protected]>
Rob Dixon wrote:
> It's always confusing when a program written in one language (here, Perl)
> creates a program in another (this script is building regular expressions).
>
> Look at the strings those lines are generating.
>
> use strict;
> use warnings;
>
> local @ARGV = qw/A B C/;
>
> my $or_pattern = '.*(?:' . join('|', @ARGV) . ')';
> my $and_pattern = join('', map{"(?=.*$_)"} @ARGV);
>
> print "Or pattern:  $or_pattern\n";
> print "And pattern: $and_pattern\n";
>
> **OUTPUT**
>
> Or pattern:  .*(?:A|B|C)
> And pattern: (?=.*A)(?=.*B)(?=.*C)
>
> Now can you understand those as regular expressions? The former uses
> non-capturing parentheses (?: ... ) to find any one of the values anywhere in
> the string, while the latter uses a lookahead (?= ... ) to find a point in the
> string after which all three of the values appear anywhere.
>
> HTH,
>
> Rob
>   
This is VERY clear. thank you understand it now!!!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.