[32311] in Perl-Users-Digest
Perl-Users Digest, Issue: 3578 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 29 18:09:30 2011
Date: Thu, 29 Dec 2011 15:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 29 Dec 2011 Volume: 11 Number: 3578
Today's topics:
An observation about open($fh, '-|') <rweikusat@mssgmbh.com>
Re: Opening Unicode files? <ben@morrow.me.uk>
Re: Opening Unicode files? <nospam-abuse@ilyaz.org>
Re: Opening Unicode files? <nospam-abuse@ilyaz.org>
Re: Opening Unicode files? <ben@morrow.me.uk>
Re: Opening Unicode files? r.mariotti@fdcx.net
pod2ipf version? (Seymour J.)
Re: regexp for matching a string with mandatory undersc <ben@morrow.me.uk>
Re: regexp for matching a string with mandatory undersc <tadmc@seesig.invalid>
Re: regexp for matching a string with mandatory undersc <nospam-abuse@ilyaz.org>
Re: regexp for matching a string with mandatory undersc (Tim McDaniel)
Re: regexp for matching a string with mandatory undersc <tadmc@seesig.invalid>
Re: regexp for matching a string with mandatory undersc <davidfilmer@gmail.com>
Re: regexp for matching a string with mandatory undersc <willem@toad.stack.nl>
Re: regexp for matching a string with mandatory undersc (Tim McDaniel)
Re: regexp for matching a string with mandatory undersc (Tim McDaniel)
Re: regexp for matching a string with mandatory undersc <rweikusat@mssgmbh.com>
Re: regexp for matching a string with mandatory undersc (Tim McDaniel)
Re: regexp for matching a string with mandatory undersc <jwkrahn@example.com>
Re: regexp for matching a string with mandatory undersc <derykus@gmail.com>
Re: regexp for matching a string with mandatory undersc (Tim McDaniel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Dec 2011 19:32:56 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: An observation about open($fh, '-|')
Message-Id: <8762h1kdxz.fsf@sapphire.mobileactivedefense.com>
According to the documentation of the open function the return value
should be
the pid of the child within the parent process, and 0 within the
child process. (Use "defined($pid)" to determine whether the
open was successful.)
As opposed to this, at least for perl 5.10.1, the open call will die
('croak', actually) with a message "Can't fork" when the fork failed
because of any error except EAGAIN.
------------------------------
Date: Tue, 27 Dec 2011 12:32:43 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Opening Unicode files?
Message-Id: <bgqos8-bm2.ln1@anubis.morrow.me.uk>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> Does Perl ship with a simple method of opening Unicode files? E.g., I
> would like to have something like
>
> open my $fh, '< :BOM0or(utf8)', $filename
>
> where BOM0or does what Perl itself does for Perl files: it looks for the
> first 4 bytes; given that a Perl file starts in ASCII, one can detect
> BOMs, can detect UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, or see that it
> is none of the above (then the arument in parens explains what to do;
> e.g., Perl itself does BOM0or(latin1)).
>
> Likewise, if one does not know that the file starts in ASCII, one can
> still detect BOM (which does not appear often in the encodings I know)
> so one could do :BOMor(utf8). Do not recollect seeing such support
> for files open()ed by Perl programs; is there?
Encode::Guess, which can be invoked as
open my $fh, '< :encoding(Guess)', $filename
Somewhat annoyingly, you have to explicitly use Encode::Guess or it
won't recognise the encoding name, and you have to use
Encode::Guess->set_suspects to set the list of encodings to try.
Ben
------------------------------
Date: Tue, 27 Dec 2011 21:17:31 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Opening Unicode files?
Message-Id: <slrnjfkdfb.8sb.nospam-abuse@panda.math.berkeley.edu>
On 2011-12-26, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
>>Does Perl ship with a simple method of opening Unicode files? E.g., I
>>would like to have something like
>>
>> open my $fh, '< :BOM0or(utf8)', $filename
>>
>>where BOM0or does what Perl itself does for Perl files: it looks for the
>>first 4 bytes; given that a Perl file starts in ASCII, one can detect
>>BOMs, can detect UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, or see that it
>>is none of the above (then the arument in parens explains what to do;
>>e.g., Perl itself does BOM0or(latin1)).
Thinking about it more, there are 3 situations:
a) we know that the first 2 characters in the file are 7-bit, and
are not 0. Then read the first 2 bytes; if both 0, it is 32BE
(possibly with [hardly legal] BOM); if BOM-BE, it is 16BE+BOM; if
high bits are set, it is UTF-8+BOM; if the first byte is 0, it is
16BE.
One needs to read the other 2 bytes only if 32BE is detected (and
only if one wants to guard against BOM) and if the second byte is
0 - then it may be 16LE or 32LE.
The only possible confusion is whether the file is actually in
Unicode encoding, or in an 8-bit encoding (or between UTF-7 and
UTF-8-no-BOMs).
b) The only thing known is that the first 2 chars are not 0. Again,
one reads 2 bytes - but now there is no way to detect UTF-8-BOM.
c) The only thing known is that the fist 2 chars are 7-bit. Then
there is no way to detect BOMless UTF-16.
d) General case: 8-bit chars may be present.
It looks like the decision algorithms are DIFFERENT in these 4 cases;
hence one needs 4 different "filters": One can call them BOM07, BOM08,
BOM7, and BOM8.
> Here's what I use and it seems to do what's needed:
>
> use File::BOM qw( :all );
And do you know from which version it is shipped with Perl?
> # Open specified input file
> open(IFH, '<:via(File::BOM)', $IF) or die "Could NOT open specified
> file ($IF)!\n";
Do not see how this may be related: I see no way to inform the filter
about what is known in advance...
Thanks,
Ilya
------------------------------
Date: Tue, 27 Dec 2011 21:19:00 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Opening Unicode files?
Message-Id: <slrnjfkdi4.8sb.nospam-abuse@panda.math.berkeley.edu>
On 2011-12-27, Ben Morrow <ben@morrow.me.uk> wrote:
> Encode::Guess, which can be invoked as
>
> open my $fh, '< :encoding(Guess)', $filename
>
> Somewhat annoyingly, you have to explicitly use Encode::Guess or it
> won't recognise the encoding name, and you have to use
> Encode::Guess->set_suspects to set the list of encodings to try.
Same question as to the other answer: does it ship with Perl? And I
do not want any guessing; I want a very deterministic procedure...
Thanks,
Ilya
------------------------------
Date: Tue, 27 Dec 2011 22:54:06 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Opening Unicode files?
Message-Id: <etups8-f0n.ln1@anubis.morrow.me.uk>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2011-12-27, Ben Morrow <ben@morrow.me.uk> wrote:
> > Encode::Guess, which can be invoked as
> >
> > open my $fh, '< :encoding(Guess)', $filename
> >
> > Somewhat annoyingly, you have to explicitly use Encode::Guess or it
> > won't recognise the encoding name, and you have to use
> > Encode::Guess->set_suspects to set the list of encodings to try.
>
> Same question as to the other answer: does it ship with Perl?
~% corelist Encode::Guess
Encode::Guess was first released with perl v5.8.0
> And I do not want any guessing; I want a very deterministic
> procedure...
Well, given that all UTF-8 files are technically valid ISO8859-* files
as well some form of heuristic is necessary to distinguish them. E::G
uses a sensible series of tests: first it looks for the various Unicode
BOMs; then it checks for nul bytes and assumes one of the wide Unicode
encodings; then it tries decoding with the list of fallback encodings
you supply and uses the first one that succeeds. (Obviously something
like ISO8859-1 will always succeed, so it would need to be listed on its
own.)
Ben
------------------------------
Date: Tue, 27 Dec 2011 22:59:59 -0500
From: r.mariotti@fdcx.net
Subject: Re: Opening Unicode files?
Message-Id: <7v4lf7lr7g2ro357f5q6prbesdlo29u34f@4ax.com>
On Tue, 27 Dec 2011 21:19:00 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:
>On 2011-12-27, Ben Morrow <ben@morrow.me.uk> wrote:
>> Encode::Guess, which can be invoked as
>>
>> open my $fh, '< :encoding(Guess)', $filename
>>
>> Somewhat annoyingly, you have to explicitly use Encode::Guess or it
>> won't recognise the encoding name, and you have to use
>> Encode::Guess->set_suspects to set the list of encodings to try.
>
>Same question as to the other answer: does it ship with Perl? And I
>do not want any guessing; I want a very deterministic procedure...
>
>Thanks,
>Ilya
Do as all perl mongers do - use CPAN to locate, download and install
the needed function.
$>perl -MCPAN -e shell
Similar source available with activesatate for windows
------------------------------
Date: Thu, 29 Dec 2011 11:40:52 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: pod2ipf version?
Message-Id: <4efc9814$2$fuzhry+tra$mr2ice@news.patriot.net>
This is a MIME encapsulated message.
--===_4EFA027B_==
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
The most recent pod2ipf that I found at CPAN was
5-19-09 8:12 72,922 342 pod2ipf-1.27.cmd
containing the version information
# $rcs = ' $Id: pod2ipf.cmd,v 1.27 2001/05/16 10:04:04 vera Exp vera
$ ' ;
($VERSION) = (' $revision: 1.24 $ ' =~ /(\d+(\.\d+)*)/);
However, an older OS/2 build of Perl had
12-16-03 22:32 77,861 0 pod2ipf.cmd
containing the version information
# $rcs = ' $Id: pod2ipf.cmd,v 1.34 2003/12/17 06:31:14 vera Exp vera
$ ' ;
($VERSION) = (' $Revision: 1.34 $ ' =~ /(\d+(\.\d+)*)/);
Which, if either, is the correct version to run in Perl 5.10.0 and is
there a more recent version?
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
--===_4EFA027B_==--
------------------------------
Date: Tue, 27 Dec 2011 12:40:04 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <4uqos8-bm2.ln1@anubis.morrow.me.uk>
Quoth David Filmer <davidfilmer@davidfilmer.com>:
> I want to be able to match the string foo1_bar2_baz3 as having
> multiple underscore characters (with no intervening whitespace), but
> not match foo1_bar2 which has only one underscore. I want to ignore
> one match, but not two or more.
>
> This would be easy if \w did not ALSO match underscores. But it
> does. There does not seem to be a character class for alphanumeric
> ONLY.
[A-Za-z0-9], which is almost certainly safer anyway unless you're using
5.14's new /a switch. \w matches a *lot* of Unicode characters you
probably didn't want to match.
You can also use the POSIXish [[:alnum:]], though this also matches
Unicode letters and numbers. (I think this may also have changed in
5.14, and the POSIX classes now only ever match ASCII, but I can't
remember.)
Ben
------------------------------
Date: Tue, 27 Dec 2011 09:21:30 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <slrnjfjotv.9f9.tadmc@tadbox.sbcglobal.net>
XeCycle <xecycle@gmail.com> wrote:
> David Filmer <davidfilmer@davidfilmer.com> writes:
>
> [...]
>
>> How can I match continuous alphanumeric strings which contain more
^^^^
>> than one underscore?
^^^^^^^^
>
> \w*_(_|\w)*
That will match when there is only one underscore.
(_|\w) matches EXACTLY the same things as \w does.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 27 Dec 2011 21:20:44 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <slrnjfkdlc.8sb.nospam-abuse@panda.math.berkeley.edu>
On 2011-12-27, David Filmer <davidfilmer@davidfilmer.com> wrote:
> This would be easy if \w did not ALSO match underscores. But it
> does. There does not seem to be a character class for alphanumeric
> ONLY.
??? [^\W_]
Ilya
------------------------------
Date: Tue, 27 Dec 2011 21:57:46 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <jddf0q$jhn$1@reader1.panix.com>
In article
<2151840d-7a2b-42c4-8c9d-5f03adf30948@s10g2000prs.googlegroups.com>,
David Filmer <davidfilmer@davidfilmer.com> wrote:
>How can I match continuous alphanumeric strings which contain more
>than one underscore?
Is it OK to use more than one regexp? If so, I might try
/^\w+$/ && /_.*_/
It's a bit brute-force, but it's also very clear. The second could be
optimized to /_[^_]*_/, but unless you're evaluating it lots of times,
"micro-optimizations leads to micro-results".
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Tue, 27 Dec 2011 17:04:13 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <slrnjfkk1j.ag3.tadmc@tadbox.sbcglobal.net>
Tim McDaniel <tmcd@panix.com> wrote:
> In article
><2151840d-7a2b-42c4-8c9d-5f03adf30948@s10g2000prs.googlegroups.com>,
> David Filmer <davidfilmer@davidfilmer.com> wrote:
>>How can I match continuous alphanumeric strings which contain more
>>than one underscore?
>
> Is it OK to use more than one regexp? If so, I might try
> /^\w+$/ && /_.*_/
> It's a bit brute-force, but it's also very clear.
/_.*_/ is a _clear_ way to say "more than one underscore" ?
> The second could be
> optimized to /_[^_]*_/, but unless you're evaluating it lots of times,
> "micro-optimizations leads to micro-results".
The way to count characters is with tr///, not regexes:
/^\w+$/ && tr/_// > 1
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 27 Dec 2011 19:09:23 -0800 (PST)
From: David Filmer <davidfilmer@gmail.com>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <2717bee7-43c0-4554-87a5-96ff429eeddb@b20g2000pro.googlegroups.com>
On Dec 27, 3:04=A0pm, Tad McClellan <ta...@seesig.invalid> wrote:
> /_.*_/ is a _clear_ way to say "more than one underscore" ?
Yes, but it also would match "foo_bar baz_quux" which contains an
intervening whitespace. This would not satisfy the original
requirements, which stipulate finding multiple underscores within
continuous alphanumeric characters with no intervening whitespace.
------------------------------
Date: Wed, 28 Dec 2011 16:31:32 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <slrnjfmh34.28l3.willem@toad.stack.nl>
David Filmer wrote:
) I want to be able to match the string foo1_bar2_baz3 as having
) multiple underscore characters (with no intervening whitespace), but
) not match foo1_bar2 which has only one underscore. I want to ignore
) one match, but not two or more.
)
) This would be easy if \w did not ALSO match underscores. But it
) does. There does not seem to be a character class for alphanumeric
) ONLY.
How would that make it easy?
Doesn't the following work? : m/\w*_\w*_\w*/
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Wed, 28 Dec 2011 17:53:28 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <jdfl2o$717$1@reader1.panix.com>
In article <2717bee7-43c0-4554-87a5-96ff429eeddb@b20g2000pro.googlegroups.com>,
David Filmer <davidfilmer@gmail.com> wrote:
>On Dec 27, 3:04 pm, Tad McClellan <ta...@seesig.invalid> wrote:
>
>> /_.*_/ is a _clear_ way to say "more than one underscore" ?
Very clear to me, at least.
>Yes, but it also would match "foo_bar baz_quux" which contains an
>intervening whitespace. This would not satisfy the original
>requirements, which stipulate finding multiple underscores within
>continuous alphanumeric characters with no intervening whitespace.
Which is why I wrote
>>> /^\w+$/ && /_.*_/
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Wed, 28 Dec 2011 18:03:48 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <jdflm3$jud$1@reader1.panix.com>
In article <slrnjfkk1j.ag3.tadmc@tadbox.sbcglobal.net>,
Tad McClellan <tadmc@seesig.invalid> wrote:
>The way
There are times to apply the phrase "The way" to Perl, but I don't
know yet that this is one of them.
>to count characters is with tr///, not regexes:
>
> /^\w+$/ && tr/_// > 1
What are your reasons to think one better than the other?
Unless the expression is being evaluated many times, efficiency isn't
so important.
How many people are familiar with tr/// versus plain m//? I rarely
use tr///. I don't remember ever using the return value of tr///.
I've never used the empty RHS feature except with /d (indeed, I had to
check the man page to see that you hadn't trashed $_).
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Wed, 28 Dec 2011 18:33:09 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <87zkecpmvu.fsf@sapphire.mobileactivedefense.com>
tmcd@panix.com (Tim McDaniel) writes:
> In article <slrnjfkk1j.ag3.tadmc@tadbox.sbcglobal.net>,
> Tad McClellan <tadmc@seesig.invalid> wrote:
>>The way
[...]
>>to count characters is with tr///, not regexes:
>>
>> /^\w+$/ && tr/_// > 1
>
> What are your reasons to think one better than the other?
>
> Unless the expression is being evaluated many times, efficiency isn't
> so important.
A subroutine I encountered in the past in some script written by
someone else was
sub mod($$) { return $_[0] - $_[1] * int($_[0] / $_[1]); }
Actually, it wasn't a subroutine but an inline calculation. Provided
the language provides a more direct way to achieve the same result
(the % operator), the question is not 'why should the built-in way be
preferred' but 'why should something other than the built-in way be
used' and ...
> How many people are familiar with tr/// versus plain m//?
... "But I didn't know about it!" is only a suitable justifcation
until this problem has been remedied.
------------------------------
Date: Thu, 29 Dec 2011 04:26:29 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <jdgq5l$sss$1@reader1.panix.com>
In article <87zkecpmvu.fsf@sapphire.mobileactivedefense.com>,
Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>Provided the language provides a more direct way to achieve the same
>result ..., the question is not 'why should the built-in way be
>preferred' but 'why should something other than the built-in way be
>used'
In the current case, it's
/_.*_/
versus
tr/_// > 1
They both use builtins pretty directly and they are both short.
Personally, I find the former to be clearer than the latter, which
uses an operator that usually causes side effects but doesn't in this
case, and I'm still don't know how many know its details.
>> How many people are familiar with tr/// versus plain m//?
>
>... "But I didn't know about it!" is only a suitable justifcation
>until this problem has been remedied.
To some extent I agree, but if someone is coding for other people, one
of the factors that the coder should consider is what is
comprehensible at a glance, in addition to other factors like brevity,
efficiency where needed, robustness, and such. For example, for my
own programs I have no problems with
my %key_lookup;
@key_lookup{@keys} = (1) x @keys;
But since I don't know how many people know that idiom, I might
hesitate to use it when coding for others, and if I did I would likely
comment it clearly.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Wed, 28 Dec 2011 22:20:14 -0800
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <zETKq.42791$cG.4522@newsfe14.iad>
Tim McDaniel wrote:
> In article<87zkecpmvu.fsf@sapphire.mobileactivedefense.com>,
> Rainer Weikusat<rweikusat@mssgmbh.com> wrote:
>> Provided the language provides a more direct way to achieve the same
>> result ..., the question is not 'why should the built-in way be
>> preferred' but 'why should something other than the built-in way be
>> used'
>
> In the current case, it's
> /_.*_/
> versus
> tr/_//> 1
> They both use builtins pretty directly and they are both short.
> Personally, I find the former to be clearer than the latter, which
> uses an operator that usually causes side effects but doesn't in this
> case, and I'm still don't know how many know its details.
tr/_// is pretty simple. It is actually short for tr/_/_/ which
replaces every '_' character with a '_' character and returns the number
of replacements made. It has the advantages that it doesn't interpolate
and it only does one thing, and does it well.
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
------------------------------
Date: Thu, 29 Dec 2011 12:28:43 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <9f2a27ae-87e8-4dfb-a29e-19ce1837fb48@t16g2000vba.googlegroups.com>
On Dec 27, 2:04=A0am, David Filmer <davidfil...@davidfilmer.com> wrote:
> I want to be able to match the string foo1_bar2_baz3 as having
> multiple underscore characters (with no intervening whitespace), but
> not match foo1_bar2 which has only one underscore. =A0I want to ignore
> one match, but not two or more.
>
> This would be easy if \w did not ALSO match underscores. =A0But it
> does. =A0There does not seem to be a character class for alphanumeric
> ONLY.
>
> How can I match continuous alphanumeric strings which contain more
> than one underscore?
>
Maybe,
print '>1' if (()=3D /\G [[:alnum:]]+ _/gx) > 1;
--
Charles DeRykus
------------------------------
Date: Thu, 29 Dec 2011 22:04:53 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: regexp for matching a string with mandatory underscores
Message-Id: <jdio65$60b$1@reader1.panix.com>
In article <9f2a27ae-87e8-4dfb-a29e-19ce1837fb48@t16g2000vba.googlegroups.com>,
C.DeRykus <derykus@gmail.com> wrote:
>On Dec 27, 2:04 am, David Filmer <davidfil...@davidfilmer.com> wrote:
>> How can I match continuous alphanumeric strings which contain more
>> than one underscore?
>
>Maybe,
>
>print '>1' if (()= /\G [[:alnum:]]+ _/gx) > 1;
For anyone else who is wondering about the use of ()=, please see "man
perldata".
List assignment in scalar context returns the number of elements
pro- duced by the expression on the right side of the assignment:
$x = (($foo,$bar) = (3,2,1)); # set $x to 3, not 2
$x = (($foo,$bar) = f()); # set $x to f()'s return count
This is handy when you want to do a list assignment in a Boolean
context, because most list functions return a null list when
finished, which when assigned produces a 0, which is interpreted
as FALSE.
It's also the source of a useful idiom for executing a function or
performing an operation in list context and then counting the
number of return values, by assigning to an empty list and then
using that assignment in scalar context. For example, this code:
$count = () = $string =~ /\d+/g;
will place into $count the number of digit groups found in
$string. This happens because the pattern match is in list
context (since it is being assigned to the empty list), and will
therefore return a list of all matching parts of the string. The
list assignment in scalar context will translate that into the
number of elements (here, the number of times the pattern matched)
and assign that to $count. Note that simply using
$count = $string =~ /\d+/g;
would not have worked, since a pattern match in scalar context
will only return true or false, rather than a count of matches.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3578
***************************************