[31169] in Perl-Users-Digest
Perl-Users Digest, Issue: 2414 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 14 00:09:48 2009
Date: Wed, 13 May 2009 21:09:11 -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 Wed, 13 May 2009 Volume: 11 Number: 2414
Today's topics:
How do I turn a list of strings into a list of regexps? <mahurshi@gmail.com>
Re: How do I turn a list of strings into a list of rege <jurgenex@hotmail.com>
Re: How do I turn a list of strings into a list of rege <ben@morrow.me.uk>
Re: How do I turn a list of strings into a list of rege <mahurshi@gmail.com>
Re: How do I turn a list of strings into a list of rege <tadmc@seesig.invalid>
Re: How do I turn a list of strings into a list of rege <ben@morrow.me.uk>
Re: How to replace c:\Program Files with Program Files <jurgenex@hotmail.com>
How to replace c:\Program Files with Program Files (x86 clearguy02@yahoo.com
Re: How to replace c:\Program Files with Program Files <veatchla@yahoo.com>
I would never use half those $' $" $`... little suckers jidanni@jidanni.org
Re: I would never use half those $' $" $`... little suc <jimsgibson@gmail.com>
Re: I would never use half those $' $" $`... little suc <uri@PerlOnCall.com>
Re: Loop aborts on web server davidfilmer@gmail.com
Re: Loop aborts on web server <whynot@pozharski.name>
Re: Loop aborts on web server <xhoster@gmail.com>
s/(The N)e(urdsburg Affair)/$1$2/ looks dumb jidanni@jidanni.org
Re: s/(The N)e(urdsburg Affair)/$1$2/ looks dumb <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 May 2009 17:02:45 -0700 (PDT)
From: Mahurshi Akilla <mahurshi@gmail.com>
Subject: How do I turn a list of strings into a list of regexps?
Message-Id: <9c68a9f7-59ff-45cd-b33c-de949a9eb02f@x31g2000prc.googlegroups.com>
I want to turn a list of strings into a list of regexps. Is there a
build in module/easy algorithm to do this?
******original_list******
string1
string2
string23
string24
anotherstring2
anothertstring5
******processed_compressed_list******
string*
anotherstring*
------------------------------
Date: Wed, 13 May 2009 17:20:16 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How do I turn a list of strings into a list of regexps?
Message-Id: <lkom0519v236680smlu57o7offvulsd5pk@4ax.com>
Mahurshi Akilla <mahurshi@gmail.com> wrote:
>I want to turn a list of strings into a list of regexps. Is there a
>build in module/easy algorithm to do this?
I don't understand your question.
Regular expressions are (double-quoted) strings. The fact that they are
regular expressions comes from them being used as specific argument in
some specific function, like the first argument in s, m. or split.
But there is no property or scalar class of "regexp" and you cannot
"turn a string into a regexp".
jue
------------------------------
Date: Thu, 14 May 2009 01:41:18 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How do I turn a list of strings into a list of regexps?
Message-Id: <eu5sd6-l0f.ln1@osiris.mauzo.dyndns.org>
Quoth Mahurshi Akilla <mahurshi@gmail.com>:
> I want to turn a list of strings into a list of regexps. Is there a
> build in module/easy algorithm to do this?
>
> ******original_list******
>
> string1
> string2
> string23
> string24
> anotherstring2
> anothertstring5
>
> ******processed_compressed_list******
>
> string*
> anotherstring*
Those regexes you list will match a lot more than just the strings you
have provided. How are you choosing which bits are important?
If you have a set of regexes and you want to combine them,
Regexp::Assemble may be what you want.
Ben
------------------------------
Date: Wed, 13 May 2009 19:44:50 -0700 (PDT)
From: Mahurshi Akilla <mahurshi@gmail.com>
Subject: Re: How do I turn a list of strings into a list of regexps?
Message-Id: <71f65b6a-e48d-41d3-9a6a-fd0c674f9fb5@k19g2000prh.googlegroups.com>
On May 13, 5:41=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Mahurshi Akilla <mahur...@gmail.com>:
>
>
>
>
>
> > I want to turn a list of strings into a list of regexps. =A0Is there a
> > build in module/easy algorithm to do this?
>
> > ******original_list******
>
> > string1
> > string2
> > string23
> > string24
> > anotherstring2
> > anothertstring5
>
> > ******processed_compressed_list******
>
> > string*
> > anotherstring*
>
> Those regexes you list will match a lot more than just the strings you
> have provided. How are you choosing which bits are important?
>
> If you have a set of regexes and you want to combine them,
> Regexp::Assemble may be what you want.
>
> Ben- Hide quoted text -
>
> - Show quoted text -
Thanks. This is similar to what I am looking for but not quite the
same. I do find this module interesting though.
http://search.cpan.org/dist/Regexp-Assemble/Assemble.pm#LIMITATIONS
Regexp::Assemble does not attempt to find common substrings. For
instance, it will not collapse /cabababc/ down to /c(?:ab){3}c/. If
there's a module out there that performs this sort of string analysis
I'd like to know about it. But keep in mind that the algorithms that
do this are very expensive: quadratic or worse.
Basically what I am looking for something that can do this string
"collapsing" for a list of strings. I am fine if it just puts a "*"
for the most common stuff. It doesn't have to be all that accurate.
It is okay if it can match other stuff as well.
If there is nothing out there, I will probably have to write my own
algorithm. I was just hoping I don't have to reinvent the wheel. :-)
------------------------------
Date: Wed, 13 May 2009 21:37:57 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How do I turn a list of strings into a list of regexps?
Message-Id: <slrnh0n105.s2k.tadmc@tadmc30.sbcglobal.net>
Mahurshi Akilla <mahurshi@gmail.com> wrote:
> I want to turn a list of strings into a list of regexps. Is there a
> build in module/easy algorithm to do this?
>
> ******original_list******
>
> string1
> string2
> string23
> string24
> anotherstring2
> anothertstring5
^
^
>
> ******processed_compressed_list******
>
> string*
> anotherstring*
All of these also match all of the strings above...
/^string/
/^another/
/string/
/s/
/\d/
/.*/
Which is "more correct"?
Why?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 14 May 2009 04:28:28 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How do I turn a list of strings into a list of regexps?
Message-Id: <snfsd6-s1k.ln1@osiris.mauzo.dyndns.org>
Quoth Tad J McClellan <tadmc@seesig.invalid>:
> Mahurshi Akilla <mahurshi@gmail.com> wrote:
> > I want to turn a list of strings into a list of regexps. Is there a
> > build in module/easy algorithm to do this?
> >
> > ******original_list******
> >
> > string1
> > string2
> > string23
> > string24
> > anotherstring2
> > anothertstring5
> ^
> ^
> >
> > ******processed_compressed_list******
> >
> > string*
> > anotherstring*
>
>
> All of these also match all of the strings above...
In fact, looking at it again, neither of the patterns given will match
any of the given strings... they only match things like
strin
string
stringg
stringgg
:)
Ben
------------------------------
Date: Wed, 13 May 2009 17:37:52 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to replace c:\Program Files with Program Files (x86) in all scripts?
Message-Id: <40pm051i0j0r987cf098dstpsbngklb3q8@4ax.com>
clearguy02@yahoo.com wrote:
>I have a parent folder, C:\Test and it has a few sub-folders (and its
>files) and files and I am now forced to do the following change in all
>files starting from its parent folder, c:\Test
>
>To replace a string, "c:\\program files\" or "c:\PROGRA~1" with "C:\
>\Program Files (x86)" in all files.
Use File::Find to recursively find all files, the test -f will probably
come in handy to determine if the file is a regular file, then open()
each file, and do the replace.
If the files are small you can possibly slurp them in and do the replace
globally before writing the content back in one go. If the files are
large you may need to loop through then line by line and write each
modified line back into a temporary file before renaming the new file
into the old.
>Here is some thing I am trying with:
>
>C:\>perl -i.bak -pe "s/Progra~1/Program Files (x86)/g" `find "C:\
>\Test" -type f -name "*.pl" `
>
>Error is:
>Can't open `find: No such file or directory.
>Can't do inplace edit: C:\\Test is not a regular file.
>Can't open -type: No such file or directory.
>Can't open f: No such file or directory.
>Can't open -name: No such file or directory.
>Can't open *.pl`: Invalid argument.
>
>When I run the find command (find C:\Test -type f -name "*.pl" ), it
>is returning the correct set of files, but it not working with the
>perl commandline.
>
>Where am I doing wrong?
It appears as if your shell(!) doesn't execute the command `find ....`
but passes it on to perl as just another command line argument. This
isn't a perl problem, but you need to check the documentation of your
shell if and how to execute parts of the command line as a separate
command first.
Having said that, I wouldn't go about it that way anyway. What if your
find returns 2000 results? I don't know of any CLI, that could handle
such a long command line.
Either write a little Perl script using File::Find as I explained above.
Or use the -exec option of the find program to run a simpler Perl script
for each file found, which does the replace on exactly this one file.
Or use SED, it's the perfect tool for such a simple job.
jue
------------------------------
Date: Wed, 13 May 2009 16:49:55 -0700 (PDT)
From: clearguy02@yahoo.com
Subject: How to replace c:\Program Files with Program Files (x86) in all scripts?
Message-Id: <e81109e7-cb30-40c6-aaf3-f5581782a1ea@d39g2000pra.googlegroups.com>
Hi experts,
I have a parent folder, C:\Test and it has a few sub-folders (and its
files) and files and I am now forced to do the following change in all
files starting from its parent folder, c:\Test
To replace a string, "c:\\program files\" or "c:\PROGRA~1" with "C:\
\Program Files (x86)" in all files.
Here is some thing I am trying with:
C:\>perl -i.bak -pe "s/Progra~1/Program Files (x86)/g" `find "C:\
\Test" -type f -name "*.pl" `
Error is:
Can't open `find: No such file or directory.
Can't do inplace edit: C:\\Test is not a regular file.
Can't open -type: No such file or directory.
Can't open f: No such file or directory.
Can't open -name: No such file or directory.
Can't open *.pl`: Invalid argument.
When I run the find command (find C:\Test -type f -name "*.pl" ), it
is returning the correct set of files, but it not working with the
perl commandline.
Where am I doing wrong?
--J
------------------------------
Date: Wed, 13 May 2009 21:36:25 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: How to replace c:\Program Files with Program Files (x86) in all scripts?
Message-Id: <DbqdnVSXcsk3HpbXnZ2dnUVZ_sqdnZ2d@supernews.com>
clearguy02@yahoo.com wrote:
> Hi experts,
>
> I have a parent folder, C:\Test and it has a few sub-folders (and its
> files) and files and I am now forced to do the following change in all
> files starting from its parent folder, c:\Test
>
> To replace a string, "c:\\program files\" or "c:\PROGRA~1" with "C:\
> \Program Files (x86)" in all files.
>
> Here is some thing I am trying with:
>
> C:\>perl -i.bak -pe "s/Progra~1/Program Files (x86)/g" `find "C:\
> \Test" -type f -name "*.pl" `
>
> Error is:
> Can't open `find: No such file or directory.
> Can't do inplace edit: C:\\Test is not a regular file.
> Can't open -type: No such file or directory.
> Can't open f: No such file or directory.
> Can't open -name: No such file or directory.
> Can't open *.pl`: Invalid argument.
>
> When I run the find command (find C:\Test -type f -name "*.pl" ), it
> is returning the correct set of files, but it not working with the
> perl commandline.
>
> Where am I doing wrong?
>
> --J
Assuming windows. Try the following on a single line.
for %F in (*.pl) do perl -i.bak -pe "s/Progra~1/Program Files (x86)/g" "%F"
--
Len
------------------------------
Date: Thu, 14 May 2009 06:28:49 +0800
From: jidanni@jidanni.org
Subject: I would never use half those $' $" $`... little suckers
Message-Id: <87ljp0wsbi.fsf@jidanni.org>
Where's the (official) document with all the $' $" $` etc. all
concentrated on one line? The best I could do is
$ perl -nwe '$h{$_}++ for /^X<(\$[^>A-Z\d]+)/;END{print "$_ " for keys %h}' /usr/share/perl/5.10.0/pod/perlvar.pod
$& $) $% $| $] $/ $. $! $; ${^ $( $@ $= $, $a $\ $? $[ $$ $^ $` $" $~ $- $_ $: $+ $'
Anyway, I would never use half those little suckers. You see often I use
one liners in Makefiles, and all the escaping and Emacs font color wrong
guessing is just not worth the excitement.
------------------------------
Date: Wed, 13 May 2009 16:05:40 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: I would never use half those $' $" $`... little suckers
Message-Id: <130520091605401545%jimsgibson@gmail.com>
In article <87ljp0wsbi.fsf@jidanni.org>, <jidanni@jidanni.org> wrote:
> Where's the (official) document with all the $' $" $` etc. all
> concentrated on one line? The best I could do is
> $ perl -nwe '$h{$_}++ for /^X<(\$[^>A-Z\d]+)/;END{print "$_ " for keys %h}'
> /usr/share/perl/5.10.0/pod/perlvar.pod
> $& $) $% $| $] $/ $. $! $; ${^ $( $@ $= $, $a $\ $? $[ $$ $^ $` $" $~ $- $_
> $: $+ $'
> Anyway, I would never use half those little suckers. You see often I use
> one liners in Makefiles, and all the escaping and Emacs font color wrong
> guessing is just not worth the excitement.
The predefined Perl variables are described in 'perldoc perlvar'. They
are not listed on one line, but that wouldn't be very useful.
--
Jim Gibson
------------------------------
Date: Wed, 13 May 2009 19:47:22 -0400
From: "Uri Guttman" <uri@PerlOnCall.com>
Subject: Re: I would never use half those $' $" $`... little suckers
Message-Id: <873ab8o99x.fsf@quad.sysarch.com>
>>>>> "JG" == Jim Gibson <jimsgibson@gmail.com> writes:
JG> In article <87ljp0wsbi.fsf@jidanni.org>, <jidanni@jidanni.org> wrote:
>> Where's the (official) document with all the $' $" $` etc. all
>> concentrated on one line? The best I could do is
>> $ perl -nwe '$h{$_}++ for /^X<(\$[^>A-Z\d]+)/;END{print "$_ " for keys %h}'
>> /usr/share/perl/5.10.0/pod/perlvar.pod
>> $& $) $% $| $] $/ $. $! $; ${^ $( $@ $= $, $a $\ $? $[ $$ $^ $` $" $~ $- $_
>> $: $+ $'
>> Anyway, I would never use half those little suckers. You see often I use
>> one liners in Makefiles, and all the escaping and Emacs font color wrong
>> guessing is just not worth the excitement.
JG> The predefined Perl variables are described in 'perldoc perlvar'. They
JG> are not listed on one line, but that wouldn't be very useful.
and the OP is shrugging them off like noise. some are critical to know
and others are close to useless. others are very valuable in certain
situations (e.g. $- and $+ after regexes with many grabs). so knowing
them in general is a good thing as is knowing where to find the docs for
them.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 13 May 2009 17:00:10 -0700 (PDT)
From: davidfilmer@gmail.com
Subject: Re: Loop aborts on web server
Message-Id: <90ca7669-e7a7-4ea4-9db3-f151013a95e7@y6g2000prf.googlegroups.com>
On May 13, 10:26=A0am, "Emil Horowitz" <i...@nexo.de> wrote:
> I am afraid that a time limit is not the reason for the problem.
Yes it is.
Type the command "ulimit -a" on your local machine.
Now create a file on your webserver called ulimit.cgi and put this in
it:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print `ulimit -a`;
chmod the file to 755 and run it in a browser.
Compare the values for "time" (which is the CPU time limit, and has
nothing to do with wallclock time).
------------------------------
Date: Wed, 13 May 2009 23:32:08 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Loop aborts on web server
Message-Id: <slrnh0mbig.kat.whynot@orphan.zombinet>
On 2009-05-13, Emil Horowitz <info@nexo.de> wrote:
Learn what "properl attribution" is
>> On May 13, 9:20 am, "Emil Horowitz" <i...@nexo.de> wrote:
>>> Hi,
>>>
>>> I have noticed that a large For loop (10,000 to 20,000 loops) aborts
>>> after
>>> about 500 to 600 loops and terminates script execution when running on
>>> the
>>> web server of my ISP. On my local host, the complete loop runs without
>>> problems. Any idea about this?
>>>
>>> Thanks, Emil
>>
>> Web servers put a time limit on CGIs. Does your
>> server allow you to fork a long-running process?
>
> I am afraid that a time limit is not the reason for the problem. I made this
> test: I put a one second's "sleep" into each loop, extending the runtime of
> the script many times over. Still the script aborts after about 500 loops,
> as before without the "sleep" command. Any ideas?
"CPU time" isn't the same as "wallclock time". You've increased the
latter. Consider asking administrator of your hosting, in case you have
such option.
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Wed, 13 May 2009 20:19:39 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Loop aborts on web server
Message-Id: <4a0b8d46$1$20027$ed362ca5@nr5-q3a.newsreader.com>
Eric Pozharski wrote:
> On 2009-05-13, Emil Horowitz <info@nexo.de> wrote:
>> I am afraid that a time limit is not the reason for the problem. I made this
>> test: I put a one second's "sleep" into each loop, extending the runtime of
>> the script many times over. Still the script aborts after about 500 loops,
>> as before without the "sleep" command. Any ideas?
>
> "CPU time" isn't the same as "wallclock time". You've increased the
> latter. Consider asking administrator of your hosting, in case you have
> such option.
Or looking at the server's error log.
Xho
------------------------------
Date: Thu, 14 May 2009 11:00:28 +0800
From: jidanni@jidanni.org
Subject: s/(The N)e(urdsburg Affair)/$1$2/ looks dumb
Message-Id: <87precs81f.fsf@jidanni.org>
Sure I can do
s/(The N)e(urdsburg Affair)/$1$2/;
but something tells me that there ought to be a smarter looking way to
get the same functionality. Something like
s/The N(e)urdsburg Affair/... but what?
------------------------------
Date: Thu, 14 May 2009 04:33:34 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: s/(The N)e(urdsburg Affair)/$1$2/ looks dumb
Message-Id: <e1gsd6-s1k.ln1@osiris.mauzo.dyndns.org>
Quoth jidanni@jidanni.org:
> Sure I can do
> s/(The N)e(urdsburg Affair)/$1$2/;
> but something tells me that there ought to be a smarter looking way to
> get the same functionality. Something like
> s/The N(e)urdsburg Affair/... but what?
s/(?<=The N)e(?=urdsburg Affair)//;
See perldoc perlre. Note that look-behind (?<=) can only match
constant-length strings; if you need variable-length look-behind you
need to use perl 5.10 or Regexp::Keep and
s/The N\Ke(?=urdsburg Affair)//;
For simple cases the s//$1$2/ solution is probably cleaner.
Ben
------------------------------
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 2414
***************************************