No, regex is not a requirement. I was originally trying to test on a
difficult example something I read in Programming Perl--Chap 5.7.2
Clustering, p 185:

-------------------------
In the remainder of the chapter, we'll see many more regex extensions, all
of which cluster without capturing, as well as doing something else. The
(?:PATTERN) extension is just special in that it does nothing else. So if
you say:

@fields = split(/\b(?:a|b|c)\b/)
it's like:
@fields = split(/\b(a|b|c)\b/)
but doesn't spit out extra fields. (The split operator is a bit like m//g in
that it will emit extra fields for all the captured substrings within the
pattern. Ordinarily, split only returns what it didn't match. For more on
split see Chapter 29, "Functions".)
-------------------------

It seems to me that 'split /a/' and 'split /(?:a)/' both split on and do not
emit 'a'; whereas, 'a' should be part of the split result in the latter
case.

Thanks again.

-----Original Message-----
From: Robert Citek [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 29, 2003 11:21 PM
To: Zeus Odin
Cc: [EMAIL PROTECTED]
Subject: Re: A very annoying regex question.



Hello Zeus,

At 11:55 AM 1/29/2003 -0500, Zeus Odin wrote:
>An even shorter version of yours is:
>-------------------------
>my @a;
>while(<DATA>){
>   next unless /=/ && chomp;
>   push @a, split /=/, $_, 2;
>}
>print "$_\n" for @a;
>-------------------------

This is even shorter, eliminates all uses of variables, and slurps in the
data all at once:

#!/usr/bin/perl -w0
print join("\n", map({split(/=/,$_,2)} grep(/=/, split(/\n/, <DATA>))));

The only thing it does not do is use the regex.  Is the regex a requirement?

Regards,
- Robert




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

Reply via email to