[29130] in Perl-Users-Digest
Perl-Users Digest, Issue: 374 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 24 00:09:52 2007
Date: Mon, 23 Apr 2007 21:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 23 Apr 2007 Volume: 11 Number: 374
Today's topics:
Re: FAQ 4.32 How do I strip blank space from the beginn <stoupa@practisoft.cz>
Re: FAQ 4.32 How do I strip blank space from the beginn <uri@stemsystems.com>
Re: FAQ 4.32 How do I strip blank space from the beginn <someone@example.com>
Re: file name length must not exceed 260 characters... <nitte.sudhir@gmail.com>
graemesmith2@youbanking.com j1234smit@gmail.com
grep causes internal server error davidzxz@gmail.com
Re: grep causes internal server error usenet@DavidFilmer.com
Re: grep causes internal server error <mritty@gmail.com>
Re: grep causes internal server error <jurgenex@hotmail.com>
Re: grep causes internal server error <someone@example.com>
Re: Manipulate fields <noreply@invalid.net>
Re: Manipulate fields <purlgurl@purlgurl.net>
Re: regular expression for wc <abigail@abigail.be>
Re: regular expression for wc <chefmuetze@web.de>
Re: regular expression for wc <chefmuetze@web.de>
Re: regular expression for wc <wahab-mail@gmx.de>
Re: regular expression for wc <abigail@abigail.be>
Re: regular expression for wc <noreply@invalid.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 24 Apr 2007 03:01:49 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <f0jld9$kgv$1@ns.felk.cvut.cz>
> 4.32: How do I strip blank space from the beginning/end of a string?
>
> s/^\s+//;
> s/\s+$//;
>
> You can also write that as a single substitution, although it turns out
> the combined statement is slower than the separate ones. That might not
> matter to you, though.
>
> s/^\s+|\s+$//g;
>
I'm using this
s/^\s*(.*?)\s*$/$1/;
Is this better or poorer then examples above?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Mon, 23 Apr 2007 21:32:34 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <x74pn6ftfx.fsf@mail.sysarch.com>
>>>>> "PV" == Petr Vileta <stoupa@practisoft.cz> writes:
>> 4.32: How do I strip blank space from the beginning/end of a string?
>>
>> s/^\s+//;
>> s/\s+$//;
>>
>> You can also write that as a single substitution, although it turns out
>> the combined statement is slower than the separate ones. That might not
>> matter to you, though.
>>
>> s/^\s+|\s+$//g;
>>
PV> I'm using this
PV> s/^\s*(.*?)\s*$/$1/;
PV> Is this better or poorer then examples above?
well, compare what happens in your regex vs the others. one, you grab
the text in the middle and replace the whole string with that. grabbing
is slower. you also match white space with * which means yours always
matches even when there is no white space and so it will always grab and
replace. yours uses ? which i don't think is needed as the regex is
anchored on both sides so a maximum match in the middle is fine. yours
won't work if there is a newline in the main text as . won't match that
without /s.
so there are plenty of differences and they point out that yours will
likely be slower than either of the FAQ answers (and definitely slower
if no whitespace is found).
so the final result is trust the FAQ and don't try to beat it as it is
has been tested over many years
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: Tue, 24 Apr 2007 02:42:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <o8eXh.30581$GV5.15636@edtnps89>
Uri Guttman wrote:
>>>>>>"PV" == Petr Vileta <stoupa@practisoft.cz> writes:
>
> >> 4.32: How do I strip blank space from the beginning/end of a string?
> >>
> >> s/^\s+//;
> >> s/\s+$//;
> >>
> >> You can also write that as a single substitution, although it turns out
> >> the combined statement is slower than the separate ones. That might not
> >> matter to you, though.
> >>
> >> s/^\s+|\s+$//g;
> >>
> PV> I'm using this
> PV> s/^\s*(.*?)\s*$/$1/;
> PV> Is this better or poorer then examples above?
>
> well, compare what happens in your regex vs the others. one, you grab
> the text in the middle and replace the whole string with that. grabbing
> is slower. you also match white space with * which means yours always
> matches even when there is no white space and so it will always grab and
> replace. yours uses ? which i don't think is needed as the regex is
> anchored on both sides so a maximum match in the middle is fine.
It is needed because .* is greedy so any trailing whitespace will be included
in the capture and the final \s* will always match nothing.
> yours
> won't work if there is a newline in the main text as . won't match that
> without /s.
>
> so there are plenty of differences and they point out that yours will
> likely be slower than either of the FAQ answers (and definitely slower
> if no whitespace is found).
>
> so the final result is trust the FAQ and don't try to beat it as it is
> has been tested over many years
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: 23 Apr 2007 20:57:40 -0700
From: kath <nitte.sudhir@gmail.com>
Subject: Re: file name length must not exceed 260 characters...
Message-Id: <1177387060.893422.143570@l77g2000hsb.googlegroups.com>
On Apr 23, 7:01 pm, anno4...@radom.zrz.tu-berlin.de wrote:
> Haggling about the length which should nominally suffice won't
> get you anywhere. When you're forced to operate that close to
> the limit, you must increase the limit. You can probably modify
> the kernel to accept longer path names.
Hi Anno,
You think we can increase the limit? because i don't have any idea..
Any ways thanks for you information.
kath.
------------------------------
Date: 23 Apr 2007 12:23:21 -0700
From: j1234smit@gmail.com
Subject: graemesmith2@youbanking.com
Message-Id: <1177356201.497599.59510@n76g2000hsh.googlegroups.com>
graemesmith2@youbanking.com
visit:
http://www.youbanking.com
------------------------------
Date: 23 Apr 2007 14:14:15 -0700
From: davidzxz@gmail.com
Subject: grep causes internal server error
Message-Id: <1177362855.662806.6330@n59g2000hsh.googlegroups.com>
Hi
I have trouble with the grep command.
My script has these lines:
opendir(DIR, "photodir") || do {&open_failed;};
@photofiles = readdir(DIR);
closedir(DIR);
@photofiles = grep ($_ !~ /^\.\.?$/, @photofiles);
@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);
The last line causes an internal server error, but why?
The line before that works fine though...
Appreciate your time!
/David - Sweden
------------------------------
Date: 23 Apr 2007 14:35:45 -0700
From: usenet@DavidFilmer.com
Subject: Re: grep causes internal server error
Message-Id: <1177364145.104053.77870@e65g2000hsc.googlegroups.com>
On Apr 23, 2:14 pm, david...@gmail.com wrote:
> @photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);
Did you mean =~ or !~ (instead of plain '~" for your comparison
operator)?
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 23 Apr 2007 15:26:27 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: grep causes internal server error
Message-Id: <1177367187.425716.220580@n59g2000hsh.googlegroups.com>
On Apr 23, 5:14 pm, david...@gmail.com wrote:
> Hi
>
> I have trouble with the grep command.
> My script has these lines:
>
> opendir(DIR, "photodir") || do {&open_failed;};
> @photofiles = readdir(DIR);
> closedir(DIR);
> @photofiles = grep ($_ !~ /^\.\.?$/, @photofiles);
> @photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);
>
> The last line causes an internal server error, but why?
Probably because it's a syntax error. If for some reason you don't
have access to your CGI server's error logs, you can put this line
into your CGI script to have the syntax errors show up in the browser:
use CGI::Carp 'fatalsToBrowser';
> The line before that works fine though...
The line before it isn't a syntax error. The ~ operator makes no
sense there. I'd have to guess you meant to use either the =~ or !~
operator there.
Paul Lalli
------------------------------
Date: Tue, 24 Apr 2007 01:34:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: grep causes internal server error
Message-Id: <L8dXh.6496$dM1.5563@trndny07>
Paul Lalli wrote:
> On Apr 23, 5:14 pm, david...@gmail.com wrote:
>> Hi
>>
>> I have trouble with the grep command.
>> My script has these lines:
>>
>> opendir(DIR, "photodir") || do {&open_failed;};
>> @photofiles = readdir(DIR);
>> closedir(DIR);
>> @photofiles = grep ($_ !~ /^\.\.?$/, @photofiles);
>> @photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);
>>
>> The last line causes an internal server error, but why?
>
> Probably because it's a syntax error.
Actually no (with t.pl containing exactly the lines above):
C:\tmp>perl -c t.pl
t.pl syntax OK
> The ~ operator makes no sense there.
That on the other hand seems to be quite true.
jue
------------------------------
Date: Tue, 24 Apr 2007 02:49:13 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: grep causes internal server error
Message-Id: <JeeXh.16810$VF5.15637@edtnps82>
Jürgen Exner wrote:
> Paul Lalli wrote:
>> On Apr 23, 5:14 pm, david...@gmail.com wrote:
>>> Hi
>>>
>>> I have trouble with the grep command.
>>> My script has these lines:
>>>
>>> opendir(DIR, "photodir") || do {&open_failed;};
>>> @photofiles = readdir(DIR);
>>> closedir(DIR);
>>> @photofiles = grep ($_ !~ /^\.\.?$/, @photofiles);
>>> @photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);
>>>
>>> The last line causes an internal server error, but why?
>> Probably because it's a syntax error.
>
> Actually no (with t.pl containing exactly the lines above):
> C:\tmp>perl -c t.pl
> t.pl syntax OK
It *should* be a syntax error:
$ perl -MO=Deparse -e'$_ ~ /^photo\d+\.jpg$/'
syntax error at -e line 1, near "$_ ~"
-e had compilation errors.
But apparently grep is interpreting the first scalar as a code block?
$ perl -MO=Deparse -e'@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles)'
@photofiles = grep($_, ~/^photo\d+\.jpg$/, @photofiles);
-e syntax OK
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Mon, 23 Apr 2007 16:20:55 GMT
From: Ala Qumsieh <noreply@invalid.net>
Subject: Re: Manipulate fields
Message-Id: <H15Xh.12674$Kd3.1779@newssvr27.news.prodigy.net>
Purl Gurl wrote:
> Ala Qumsieh wrote:
>
>> Purl Gurl wrote:
>
> (snipped confusion on the part of Ala Qumsieh)
>
> You have responded to the wrong person. I did not
> present a question to this group. You should be
> responding to the author who did ask a question.
Actually I was trying to teach YOU something new, since after all those
years lurking on this newsgroup, your coding still lacks.
Btw, didn't I killfile you a while ago? how come I'm still seeing your
posts? hmmm ..
--Ala
------------------------------
Date: Mon, 23 Apr 2007 09:54:51 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Manipulate fields
Message-Id: <9emdnWVpLYBGebHbnZ2dnUVZ_sCinZ2d@giganews.com>
Ala Qumsieh wrote:
> Purl Gurl wrote:
>> Ala Qumsieh wrote:
>>> Purl Gurl wrote:
>>(snipped confusion on the part of Ala Qumsieh)
>> You have responded to the wrong person. I did not
>> present a question to this group. You should be
>> responding to the author who did ask a question.
> Actually I was trying to teach YOU something new, since after all those
> years lurking on this newsgroup, your coding still lacks.
My, how arrogantly white of you.
> Btw, didn't I killfile you a while ago? how come I'm still seeing your
> posts? hmmm ..
How would I know? I am not you. You are flaunting your stupidity.
Purl Gurl
------------------------------
Date: 23 Apr 2007 16:11:01 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: regular expression for wc
Message-Id: <slrnf2pmk1.cu.abigail@alexandra.abigail.be>
Zeh Mau (chefmuetze@web.de) wrote on MMMMCMLXXXIII September MCMXCIII in
<URL:news:1177329762.361546.301780@q75g2000hsh.googlegroups.com>:
{} Please go to this thread:
{}
{} http://groups.google.de/group/regex/browse_thread/thread/e25c3e39aaafcd30?hl=de
{}
{} Thanks for your support,
Well, that's quite rude.
If you have a question, ask it here. Don't post an URL to the question.
Anyway, the question depends on what you think is a 'regular expression'.
If you consider a 'regular expression' to be anything between two /'s,
then the answer is "yes", because you can just go back to Perl itself
(using (??{ }) or (?{ })), and do anything you like (except call a
regular expression).
If you restrict yourself to what the regular expression engine can without
falling back to Perl, than the answer is "no", for a very simple reason:
you can only match what is present in the string you match against. And
usually, the number of lines, words, or characters isn't present in
the file.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54";
print if s/<<EOT/<<EOT/e;
Just another Perl Hacker
EOT
------------------------------
Date: 23 Apr 2007 10:07:57 -0700
From: Zeh Mau <chefmuetze@web.de>
Subject: Re: regular expression for wc
Message-Id: <1177348077.376158.4680@n76g2000hsh.googlegroups.com>
> Well, that's quite rude.
Sorry, I did not know where to reach most of the people,
so I have chosen the groups which seems reasonable for me. I hope to
have not offended anyone by doing this so :)
------------------------------
Date: 23 Apr 2007 10:12:36 -0700
From: Zeh Mau <chefmuetze@web.de>
Subject: Re: regular expression for wc
Message-Id: <1177348355.988376.16420@n76g2000hsh.googlegroups.com>
> If you restrict yourself to what the regular expression engine can without
> falling back to Perl, than the answer is "no", for a very simple reason:
> you can only match what is present in the string you match against. And
> usually, the number of lines, words, or characters isn't present in
> the file.
In LEX, I may specify
&&
\n {CountLines++;}
So I get the numbers of lines. So every match increments the variable
CountLines++;
But how do can I separate whole words from the rest of the text?
Zeh
------------------------------
Date: Mon, 23 Apr 2007 20:34:22 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: regular expression for wc
Message-Id: <f0iui8$qcj$1@mlucom4.urz.uni-halle.de>
Mirco Wahab wrote:
>
> Needs some more thinking (will look
> at it today on evening again ;-)
As Abigail mentioned in another post,
Perls Regexes allow code assertions,
so this task isn't too hard.
The following should work as
poor-mans wc ;-)
[wc.pl] ==>
use strict;
use warnings;
my %wc = (lines=>1, words=>0, chars=>0);
my $re = qr/ \b (?{ $wc{words} += 0.25 })
| \n (?{ $wc{lines} ++ })
| . (?{ $wc{chars} ++ })
/x;
my $text = do { local$/; <> };
print map "$wc{$_} $_, ", keys %wc
if () = $text =~ /$re/g;
<==
Regards
M.
------------------------------
Date: 23 Apr 2007 19:45:14 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: regular expression for wc
Message-Id: <slrnf2q35l.cu.abigail@alexandra.abigail.be>
Zeh Mau (chefmuetze@web.de) wrote on MMMMCMLXXXIII September MCMXCIII in
<URL:news:1177348355.988376.16420@n76g2000hsh.googlegroups.com>:
## > If you restrict yourself to what the regular expression engine can without
## > falling back to Perl, than the answer is "no", for a very simple reason:
## > you can only match what is present in the string you match against. And
## > usually, the number of lines, words, or characters isn't present in
## > the file.
##
## In LEX, I may specify
## &&
## \n {CountLines++;}
##
## So I get the numbers of lines. So every match increments the variable
## CountLines++;
Your question was to do it in a regexp. CountLines++ isn't a regexp.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Mon, 23 Apr 2007 20:22:02 GMT
From: Ala Qumsieh <noreply@invalid.net>
Subject: Re: regular expression for wc
Message-Id: <Kz8Xh.498$RX.229@newssvr11.news.prodigy.net>
Zeh Mau wrote:
> Please go to this thread:
>
>
http://groups.google.de/group/regex/browse_thread/thread/e25c3e39aaafcd30?hl=de
>
If you want to recreate wc in Perl, then it has been already done for you:
http://ppt.cvs.sourceforge.net/*checkout*/ppt/ppt/bin/wc
--Ala
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 374
**************************************