[23715] in Perl-Users-Digest
Perl-Users Digest, Issue: 5921 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 10 18:07:41 2003
Date: Wed, 10 Dec 2003 15:05:20 -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 Wed, 10 Dec 2003 Volume: 10 Number: 5921
Today's topics:
(module for) RTF parsing ? <myicq@gmx_fjernmig_.net>
Re: (module for) RTF parsing ? <jwillmore@remove.adelphia.net>
basic question on regexp (John)
basic question on regexp (Richard Snow)
Re: basic question on regexp <noreply@gunnar.cc>
Re: basic question on regexp <xx087@freenet.carleton.ca>
Re: basic question on regexp <noreply@gunnar.cc>
Re: Beginners Program (hymie!)
Re: Beginners Program <asu1@c-o-r-n-e-l-l.edu>
Re: Beginners Program (Sam Holden)
bug in lexically scoped array not reset in foreach loop <sherlock@genome.stanford.edu>
Re: bug in lexically scoped array not reset in foreach <uri@stemsystems.com>
CGI input variable - regular expression question (G Klinedinst)
Re: CGI input variable - regular expression question <noreply@gunnar.cc>
Re: CGI input variable - regular expression question <richard@zync.co.uk>
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: CGI input variable - regular expression question <noreply@gunnar.cc>
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: CGI input variable - regular expression question <flavell@ph.gla.ac.uk>
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: CGI input variable - regular expression question <emschwar@pobox.com>
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: CGI input variable - regular expression question <flavell@ph.gla.ac.uk>
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: Character class [\W_] clarification <xx087@freenet.carleton.ca>
Clearification--> HOWTO remove empty lines with Regex <torfinnk@hotmail.com>
Re: Clearification--> HOWTO remove empty lines with Re <noreply@gunnar.cc>
Re: connection fail with ppm <jwillmore@remove.adelphia.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Dec 2003 17:41:59 GMT
From: TDJ <myicq@gmx_fjernmig_.net>
Subject: (module for) RTF parsing ?
Message-Id: <Xns944DBE5DC63E0tdjtdjtdj@212.54.64.134>
I can find modules for making RTF files, but what if I want to go
the other way ?
I have a number of files (SMS messages) in a directory, which I
would like to convert to a database / table.
The message format per file is similar to:
(line feeds added for illustration.)
Anyone have hints at parsing that file ?
------------ start -------------------------------------
{
tf1\ansi\ansicpg1252\deff0\deflang1030
{\info
{\*\SemKeywords SEM
(SMS,NO_DM,NO_SMS_PIC,NO_SMS_SOUND,STATUS_REPORT,NO_REPLY_PATH,3-9-28-16-
28-33-8,+4599999999,VPREL:0-0-10-0,ST:1,PBLIST:+4588888888)
}
}
{\fonttbl
{\f0\fswiss\fprq2\fcharset0 Arial;}
}
\viewkind4\uc1\pard\f0\fs22
Message message bla bal abl ablba l balabablablasbdflkjsd flijg sidjfidifj
jijdifjdifj difj difj idjf idjf idjf idjf idj f
\par
}
----------- end --------------------------------------
------------------------------
Date: Wed, 10 Dec 2003 18:52:24 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: (module for) RTF parsing ?
Message-Id: <20031210135223.742499f7.jwillmore@remove.adelphia.net>
On Wed, 10 Dec 2003 17:41:59 GMT
TDJ <myicq@gmx_fjernmig_.net> wrote:
> I can find modules for making RTF files, but what if I want to go
> the other way ?
http://search.cpan.org/~sargie/RTF-Tokenizer-1.05/lib/RTF/Tokenizer.pm
This *should* read an RTF file and "translate" it for you.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
In a museum in Havana, there are two skulls of Christopher
Columbus, "one when he was a boy and one when he was a man."
<-- Mark Twain
------------------------------
Date: 10 Dec 2003 07:55:11 -0800
From: news2003@wanadoo.es (John)
Subject: basic question on regexp
Message-Id: <3bd6db81.0312100755.77fca1fa@posting.google.com>
Hi all,
I have to split a test but I don't know how to do it.
If I have:
#!/usr/local/bin/perl -w
use strict;
my $arr = "nothing to compa-re";
my $block = [split /\W+/, $arr];
foreach (@$block){
print "$_\n";
}
will produce:
nothing
to
compa
re
but I have to consider - as part of the word.
the result I would like to obtain is:
nothing
to
compa-re
any idea?
Thanks for your help.
J
------------------------------
Date: 10 Dec 2003 11:59:46 -0800
From: Richard@RichardSnow.org (Richard Snow)
Subject: basic question on regexp
Message-Id: <5b24ee87.0312101159.8751700@posting.google.com>
news2003@wanadoo.es (John) wrote in message news:<3bd6db81.0312100755.77fca1fa@posting.google.com>...
> Hi all,
>
>
> I have to split a test but I don't know how to do it.
>
>
> If I have:
>
> #!/usr/local/bin/perl -w
>
> use strict;
>
> my $arr = "nothing to compa-re";
>
> my $block = [split /\W+/, $arr];
>
> foreach (@$block){
> print "$_\n";
> }
>
>
> will produce:
>
> nothing
> to
> compa
> re
>
> but I have to consider - as part of the word.
>
> the result I would like to obtain is:
>
> nothing
> to
> compa-re
>
>
> any idea?
>
>
> Thanks for your help.
> J
Well, I'm sure someone will post something more elegant, but
my $block = [ split /[^a-z,A-Z,0-9,_,-]/,$arr ];
will do what you want I believe.
Richard Snow
Richard@RichardSnow.org
------------------------------
Date: Wed, 10 Dec 2003 17:10:28 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: basic question on regexp
Message-Id: <br7glp$7sc3$1@ID-184292.news.uni-berlin.de>
John wrote:
> If I have:
>
> #!/usr/local/bin/perl -w
> use strict;
> my $arr = "nothing to compa-re";
> my $block = [split /\W+/, $arr];
> foreach (@$block){
> print "$_\n";
> }
>
> will produce:
>
> nothing
> to
> compa
> re
>
> but I have to consider - as part of the word.
>
> the result I would like to obtain is:
>
> nothing
> to
> compa-re
>
> any idea?
If it's not sufficient to just split on white space:
split ' ', $arr
you can use a character class:
split /[^\w-]+/, $arr
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 10 Dec 2003 20:15:37 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: basic question on regexp
Message-Id: <slrnbtevos.ptg.xx087@smeagol.ncf.ca>
Richard Snow <Richard@RichardSnow.org> wrote:
> my $block = [ split /[^a-z,A-Z,0-9,_,-]/,$arr ];
Don't use commas inside your character class: it's not a list in there.
[^a-z,A-Z,0-9,_,-] is the same as [^,a-zA-Z0-9_-] is the same as [^,\w-]
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Wed, 10 Dec 2003 21:46:48 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: basic question on regexp
Message-Id: <br80tg$f74p$1@ID-184292.news.uni-berlin.de>
Richard Snow wrote:
> Well, I'm sure someone will post something more elegant, but
> my $block = [ split /[^a-z,A-Z,0-9,_,-]/,$arr ];
> will do what you want I believe.
Richard, please note that the ranges and characters in a character
class shall not be comma separated. This is probably what you mean:
my $block = [ split /[^a-zA-Z0-9_-]/, $arr ];
Also, in order to prevent the creation of empty array elements, you'd
better split on one or more characters in the class:
my $block = [ split /[^a-zA-Z0-9_-]+/, $arr ];
---------------------------------------^
Finally, since there already is a pre-defined character class \w which
is the same as [a-zA-Z0-9_], and provided that you want to avoid
unnecessary typing, you can do:
my $block = [ split /[^\w-]+/, $arr ];
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 10 Dec 2003 16:28:43 -0000
From: hymie@lactose.smart.net (hymie!)
Subject: Re: Beginners Program
Message-Id: <vteidrbpiurd65@corp.supernews.com>
In our last episode, the evil Dr. Lacto had captured our hero,
sholden@cs.usyd.edu.au, who said:
>On Wed, 10 Dec 2003 00:51:29 -0000,
> Lenny Challis <ned@challis2000.fsnet.co.uk> wrote:
>>
>> open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
>> open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
>
>I'd put single quotes aroung the < and >, since they don't need
>double quote features.
Just the opposite: I'd put > and $cfile into a single pair of double-quotes:
# opens for read-only by default
open INPUT,$ofile or die "Can't open $ofile: $!";
open OUTPUT,">$cfile" or die"Can't open $cfile: $!";
hymie! http://www.smart.net/~hymowitz hymie@lactose.smart.net
===============================================================================
------------------------------
Date: 10 Dec 2003 16:45:50 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Beginners Program
Message-Id: <Xns944D77AB2E633asu1cornelledu@132.236.56.8>
hymie@lactose.smart.net (hymie!) wrote in
news:vteidrbpiurd65@corp.supernews.com:
> In our last episode, the evil Dr. Lacto had captured our hero,
> sholden@cs.usyd.edu.au, who said:
>>On Wed, 10 Dec 2003 00:51:29 -0000,
>> Lenny Challis <ned@challis2000.fsnet.co.uk> wrote:
>>>
>>> open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
>>> open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n";
>>> #open
>>
>>I'd put single quotes aroung the < and >, since they don't need
>>double quote features.
>
> Just the opposite: I'd put > and $cfile into a single pair of
> double-quotes:
>
> # opens for read-only by default
> open INPUT,$ofile or die "Can't open $ofile: $!";
> open OUTPUT,">$cfile" or die"Can't open $cfile: $!";
From perldoc perlopentut:
In this case, the filename to open is the actual string in $datafile, so
you don't have to worry about $datafile containing characters that might
influence the open mode, or whitespace at the beginning of the filename
that would be absorbed in the 2-argument version. Also, any reduction of
unnecessary string interpolation is a good thing.
Hence, doing as Sam Holden suggested and using
open OUTPUT,'>', $cfile or die "Can't open $cfile: $!";
would be preferable.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 10 Dec 2003 20:20:11 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Beginners Program
Message-Id: <slrnbtevvr.pss.sholden@flexal.cs.usyd.edu.au>
On 10 Dec 2003 13:25:39 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> Perl treats interpolation of arrays differently than interpolation of
> scalars. Array interpolation was introduced rather late in the game.
> To make the transition as smooth as possible, Perl treats "@" in a string
> as a normal character whenever possible. The rather complex handling of
> "$" was already in place at the time and was, of course, not changed.
>
> So there really is no good reason for the different behavior, only
> history.
I guess that makes sense, after all there was probably at least one
perl script that used @ at the end of a string, but not in the middle
of a string... Maybe... :)
But "history" is as good an answer as any (and a very common one at that).
--
Sam Holden
------------------------------
Date: Wed, 10 Dec 2003 14:28:09 -0800
From: Gavin Sherlock <sherlock@genome.stanford.edu>
Subject: bug in lexically scoped array not reset in foreach loop
Message-Id: <101220031428091905%sherlock@genome.stanford.edu>
Hi,
I had a script that I was trying to track a bug down in for ages, and
I've finally reached the conclusion that it really is a bug in Perl,
OR, I misunderstand what should happen: I have created a reduced test
case which is:
#!/usr/bin/perl
use strict;
my @ids = qw (XXX_foo XXX_bar XXX_baz foo bar XXX_foo baz);
foreach my $id (@ids){
my @result = &GetResult if $id !~ /^XXX_/;
print join("\t", @result), "\n";
if (!@result){
@result = ("Should never print");
}
}
sub GetResult { return ("blah") }
and what gets printed is:
poppy 107 > bug.pl
Should never print
Should never print
blah
blah
blah
poppy 108 >
I had thought that the my @result declaration should have reset the
contents of the array each time through the loop. It appears that it
doesn't, if the regex fails. Maybe this is the correct behaviour, in
that when the regex fails, the lexical declaration of my @result does
not happen, as well as the call to GetResult(). Of course this is
unintuitive (at least to me), because it means that in a strict
program, I now have access to a completely undeclared variable on the
next line. Am I crazy?
My workaround of course was to simply split it into 2 lines:
my @result;
@result = &GetResult if $id !~ /^XXX_/;
I get this result with the following Perl installs:
SW-90-732-818-2 104 % perl -v
This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level
(with 1 registered patch, see perl -V for more detail)
belhaven 111 % perl -v
This is perl, v5.6.0 built for darwin
poppy 108 > perl -v
This is perl, v5.6.1 built for sun4-solaris
If anyone can tell me me why what happened is correct, I'd appreciate
it. If it's a bug, I hope the report is useful,
Cheers,
Gavin
------------------------------
Date: Wed, 10 Dec 2003 22:36:52 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: bug in lexically scoped array not reset in foreach loop
Message-Id: <x7vfoo8fln.fsf@mail.sysarch.com>
>>>>> "GS" == Gavin Sherlock <sherlock@genome.stanford.edu> writes:
> my @result = &GetResult if $id !~ /^XXX_/;
this is a known issue with my and statement modifiers. my has a compile
time (declaration) and a runtime (assignment of empty or data) effect.
your condition there precludes the assignment of either undef or your
sub call when it passes.
there is an obscure (and not officially supported and dumb) technique
for making a static variable inside a sub:
my $foo if 0 ;
it will never be reset and can keep its value from call to call.
it is not proper perl and could be removed in future versions.
so you inadvertantly stumbled onto the same bad trick. the answer is
don't do that. declare the my variable first and then conditionally
assign to it
> my @result;
> @result = &GetResult if $id !~ /^XXX_/;
that isn't just a workaround, it is correct code.
> it. If it's a bug, I hope the report is useful,
it is a known accidental misfeature. i would call it a bug. but it
doesn't need to be reported as it is well known among p5p.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 10 Dec 2003 09:18:24 -0800
From: g_klinedinst@hotmail.com (G Klinedinst)
Subject: CGI input variable - regular expression question
Message-Id: <168f035a.0312100918.1aed2e5d@posting.google.com>
Hi all,
I am writing a CGI program which will be receiving 5 variables via
the POST method and using them to query a DB. Everything is working
fine but I would like to limit the characters people can enter. My
problem is that perl's built in types aren't sufficient for me, and I
can't really figure out the proper way to do it.
I want to allow ONLY: A-Z a-z 1-9 _ / -
As you can see that is two extra characters than the Perl \w and !\W.
I can easily do something like this:
if( !( $name =~ /[\W]/ ))
but that excludes my hyphen and forward slash. I could also or it with
a search for the hyphen and forward slash, like this:
if( !( $name =~ /[\W]/ ) || ( $name =~ /[-\/]/ ) )
but that isn't what I want either because that will allow weird
characters as long as a hyphen or slash exists.
Can anyone point me in the right direction? Just maybe a suggestion of
a flag or something which would be useful and then I will figure it
out from there. Thanks a bunch.
-GPK
------------------------------
Date: Wed, 10 Dec 2003 18:38:31 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI input variable - regular expression question
Message-Id: <br7lri$9nd9$1@ID-184292.news.uni-berlin.de>
G Klinedinst wrote:
> I would like to limit the characters people can enter. My problem
> is that perl's built in types aren't sufficient for me, and I can't
> really figure out the proper way to do it.
> I want to allow ONLY: A-Z a-z 1-9 _ / -
> As you can see that is two extra characters than the Perl \w and
> !\W.
if ( $name !~ /[^\w\/-]/ ) {
# Okay
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 10 Dec 2003 17:43:02 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: CGI input variable - regular expression question
Message-Id: <br7lv6$gda$1@news.freedom2surf.net>
In article <168f035a.0312100918.1aed2e5d@posting.google.com>, "G
Klinedinst" <g_klinedinst@hotmail.com> wrote:
> Hi all,
> I am writing a CGI program which will be receiving 5 variables via
> the POST method and using them to query a DB. Everything is working fine
> but I would like to limit the characters people can enter. My problem is
> that perl's built in types aren't sufficient for me, and I can't really
> figure out the proper way to do it.
> I want to allow ONLY: A-Z a-z 1-9 _ / -
You can use character groups like this:
if ($name =~ m([-A-Za-z1-9_/]+) ) {
The hyphen must be the first character to avoid it being seen as a range
operator like the other hyphens. The regex above will match a string
which consists of 1 or more of the characters in the []'s.
BTW, are you sure you don't want to allow zero?
Rich
------------------------------
Date: 10 Dec 2003 17:46:46 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944D81FFC29CDasu1cornelledu@132.236.56.8>
g_klinedinst@hotmail.com (G Klinedinst) wrote in
news:168f035a.0312100918.1aed2e5d@posting.google.com:
> I want to allow ONLY: A-Z a-z 1-9 _ / -
> As you can see that is two extra characters than the Perl \w and !\W.
> I can easily do something like this:
>
> if( !( $name =~ /[\W]/ ))
First, as an aside:
\W already stands for a character class, no need to surround it with [ and
]. Also,
if($name =~ /\w\)
is more readily comprehensible and does the same thing as the statement
above. No need for clutter.
However, as you have shown it, the regex will match if $name contains at
least one character in the class whereas I assume you want to match strings
that consist only of the allowable characters.
So, what is wrong with:
if($name =~ m!([A-Za-z1-9_\-/])+!)
The parantheses are there because I am assuming your script will be running
in taint mode (as it should), and you'll need to untaint your variables.
> Can anyone point me in the right direction?
perldoc perlre
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 18:47:16 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI input variable - regular expression question
Message-Id: <br7mc2$98uu$1@ID-184292.news.uni-berlin.de>
Richard Gration wrote:
> "G Klinedinst" wrote:
>> I am writing a CGI program which will be receiving 5 variables
>> via the POST method and using them to query a DB. Everything is
>> working fine but I would like to limit the characters people can
>> enter. My problem is that perl's built in types aren't sufficient
>> for me, and I can't really figure out the proper way to do it.
>> I want to allow ONLY: A-Z a-z 1-9 _ / -
>
> You can use character groups like this:
>
> if ($name =~ m([-A-Za-z1-9_/]+) ) {
That tests something else. You need to anchor the beginning and the
end to use that approach:
if ($name =~ m(^[-A-Za-z1-9_/]+$) )
-------------------^---------------^
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 10 Dec 2003 17:53:44 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944D832E99EA7asu1cornelledu@132.236.56.8>
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in
news:Xns944D81FFC29CDasu1cornelledu@132.236.56.8:
>
> if($name =~ m!([A-Za-z1-9_\-/])+!)
I meant
if($name =~ m!^([A-Za-z1-9_\-/])+$!)
Sorry about that.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 17:56:34 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Pine.LNX.4.53.0312101755260.26201@ppepc56.ph.gla.ac.uk>
On Wed, 10 Dec 2003, A. Sinan Unur wrote:
> > if( !( $name =~ /[\W]/ ))
[..]
> if($name =~ /\w\)
>
> is more readily comprehensible and does the same thing as the statement
> above.
Would you like to reconsider that?
------------------------------
Date: 10 Dec 2003 19:08:19 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944D8FD334782asu1cornelledu@132.236.56.8>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in
news:Pine.LNX.4.53.0312101755260.26201@ppepc56.ph.gla.ac.uk:
> On Wed, 10 Dec 2003, A. Sinan Unur wrote:
>
>> > if( !( $name =~ /[\W]/ ))
> [..]
>> if($name =~ /\w\)
>>
>> is more readily comprehensible and does the same thing as the statement
>> above.
>
> Would you like to reconsider that?
Unfortunately, I am not sure why I need to. Could you explain please?
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 12:12:58 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: CGI input variable - regular expression question
Message-Id: <etoy8tkv64l.fsf@fc.hp.com>
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> writes:
> "Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in
> news:Pine.LNX.4.53.0312101755260.26201@ppepc56.ph.gla.ac.uk:
>> On Wed, 10 Dec 2003, A. Sinan Unur wrote:
>>
>>> > if( !( $name =~ /[\W]/ ))
>> [..]
>>> if($name =~ /\w\)
>>>
>>> is more readily comprehensible and does the same thing as the statement
>>> above.
>>
>> Would you like to reconsider that?
>
> Unfortunately, I am not sure why I need to. Could you explain please?
You said:
if($name =~ /\w\)
ITYM:
if($name =~ /\w/)
Note important difference in the direction of the final slash.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 10 Dec 2003 19:16:20 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944D912F138F5asu1cornelledu@132.236.56.8>
Eric Schwartz <emschwar@pobox.com> wrote in
news:etoy8tkv64l.fsf@fc.hp.com:
> You said:
>
> if($name =~ /\w\)
>
> ITYM:
>
> if($name =~ /\w/)
>
> Note important difference in the direction of the final slash.
Arrrrgh! I'll stop posting before I break the new record for the number of
errors in a single post.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 19:55:50 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Pine.LNX.4.53.0312101942540.26201@ppepc56.ph.gla.ac.uk>
On Wed, 10 Dec 2003, A. Sinan Unur wrote:
> >> > if( !( $name =~ /[\W]/ ))
> > [..]
> >> if($name =~ /\w\)
> >>
> >> is more readily comprehensible and does the same thing as the statement
> >> above.
> >
> > Would you like to reconsider that?
>
> Unfortunately, I am not sure why I need to.
Aside from the backslash typo, it seems to me that the two tests
aren't equivalent to each other - consider the null string?
------------------------------
Date: 10 Dec 2003 21:11:48 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944DA4C2FD27Dasu1cornelledu@132.236.56.8>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in
news:Pine.LNX.4.53.0312101942540.26201@ppepc56.ph.gla.ac.uk:
> On Wed, 10 Dec 2003, A. Sinan Unur wrote:
>
>> >> > if( !( $name =~ /[\W]/ ))
>> > [..]
>> >> if($name =~ /\w\)
>> >>
>> >> is more readily comprehensible and does the same thing as the
>> >> statement above.
>> >
>> > Would you like to reconsider that?
>>
>> Unfortunately, I am not sure why I need to.
>
> Aside from the backslash typo, it seems to me that the two tests
> aren't equivalent to each other - consider the null string?
Point well taken. Given the empty string, ($name =~ /\w/) will be false
whereas !($name =~ /[\W]/) will be true by virtue of the fact that the
empty string does not match any characters.
Are you a mathematician by any chance?
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 10 Dec 2003 14:55:40 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Character class [\W_] clarification
Message-Id: <slrnbted0v.srm.xx087@smeagol.ncf.ca>
Fiaz Idris <ifiaz@hotmail.com> wrote:
> s/[\W_]+//g
> i.e. to replace (all non-word character and underscore) with (nothing).
>
> First, I couldn't understand the above that is because I interpreted
> above regex as *** replace "\W" with "^a-zA-Z_0-9" ***
>
> s/[^a-zA-Z_0-9_]+//g -------------->(regex XXX)
[...]
An example to back up Fiaz's confusion:
$s = '=-_abc_-=';
($c=$s) =~ s/[\W]/./g; print "$c\n";
($c=$s) =~ s/[\W_]/./g; print "$c\n";
Clearly [\W] is not equivalent to [\W_], so \W is not merely replaced
with ^a-zA-Z_0-9 by Perl's regex engine.
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Wed, 10 Dec 2003 16:01:34 +0100
From: "tor" <torfinnk@hotmail.com>
Subject: Clearification--> HOWTO remove empty lines with Regex
Message-Id: <3fd73551$0$9764$edfadb0f@dread14.news.tele.dk>
This might clearify
I got this file:
-----------------
Line 1<newlin>
Line 2<newlin>
<newlin>
Line 4<newlin>
----------------
I want this
-----------------
Line 1<newlin>
Line 2<newlin>
Line 4<newlin>
----------------
I want to remove the line who only contains <newline>,
so that the array @var only lines that contains data.
while(<FILE>) {
s/<something>/<nothing>/;
#Where <something> the regular expression I'm missing
push(@var,$_);
}
"tor" <torfinnk@hotmail.com> wrote in message
news:3fd72270$0$9780$edfadb0f@dread14.news.tele.dk...
> Hi
> I wan't to remove all empty lines in a file.
> How can I do that with a regex:
> s/<something>//;
> What is this <something>
>
> Torfinn
>
>
------------------------------
Date: Wed, 10 Dec 2003 16:19:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Clearification--> HOWTO remove empty lines with Regex
Message-Id: <br7dlh$6kkm$1@ID-184292.news.uni-berlin.de>
tor wrote:
> This might clearify
> I got this file:
> -----------------
> Line 1<newlin>
> Line 2<newlin>
> <newlin>
> Line 4<newlin>
> ----------------
> I want this
> -----------------
> Line 1<newlin>
> Line 2<newlin>
> Line 4<newlin>
> ----------------
>
> I want to remove the line who only contains <newline>,
> so that the array @var only lines that contains data.
>
> while(<FILE>) {
> s/<something>/<nothing>/;
> #Where <something> the regular expression I'm missing
> push(@var,$_);
> }
In that case, you are on the wrong track with that s/// operator. You
can just do:
while (<FILE>) {
push @var, $_ unless $_ eq "\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 10 Dec 2003 19:57:21 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: connection fail with ppm
Message-Id: <20031210145721.6c1f8812.jwillmore@remove.adelphia.net>
On 9 Dec 2003 20:39:50 -0800
jeunghun@terrasem.com (jhhan) wrote:
> >ppm
> PPM>search pty claimed always
> Error connecting
> to'http://ppm.ActiveState.com/dgibin/PPM/ppmserver.pl?urn:/PPMServe
> r'.
>
> and I tried
>
> >ppm3
> ppm>search pty
> Searching in Active Repositories
> No matched for ;pty'; see 'help search'.
>
> ppm>rep add active
> http://www.ActiveState.com/cgibin/PPM/ppmserver.plex?urn:/PPMServer
> Error: 500 Can't read entity body: Unknown error at
> C:/Perl/site/lib/PPM/Repository.pm line 84
>
> line 84 of Repository.pm is my $soap_result = $client->ppm_protocol;
>
> Is anyone who can help me?
1) _update_ PPM and/or Perl - they *may* be out of date (I think that
was what I got when using an outdated version of Perl sometime back)
2) check the ActiveState knowledgebase to see what they have to say
about it.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Documentation is the castor oil of programming. Managers know it
must be good because the programmers hate it so much.
------------------------------
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:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
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 V10 Issue 5921
***************************************