[31062] in Perl-Users-Digest
Perl-Users Digest, Issue: 2307 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 30 14:24:59 2009
Date: Mon, 30 Mar 2009 11:24:52 -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, 30 Mar 2009 Volume: 11 Number: 2307
Today's topics:
Regex compiler not showing backtracking for * <schaitan@gmail.com>
Re: Regex compiler not showing backtracking for * sln@netherlands.com
Re: Regex compiler not showing backtracking for * sln@netherlands.com
Re: Regex compiler not showing backtracking for * <nospam-abuse@ilyaz.org>
Re: Regex compiler not showing backtracking for * <schaitan@gmail.com>
Re: Regex compiler not showing backtracking for * <ben@morrow.me.uk>
Re: Regex compiler not showing backtracking for * <1usa@llenroc.ude.invalid>
Re: Regex compiler not showing backtracking for * sln@netherlands.com
Re: Regex compiler not showing backtracking for * <schaitan@gmail.com>
search/replace <molsted@gmail.com>
Re: search/replace <tadmc@seesig.invalid>
Re: search/replace <glennj@ncf.ca>
Re: Typeglobs vs References <Peter@PSDT.com>
Re: Typeglobs vs References <ben@morrow.me.uk>
Re: upgrading modules perl 5.8.8 -> 5.10.0 <friendly@yorku.ca>
Re: upgrading modules perl 5.8.8 -> 5.10.0 <ben@morrow.me.uk>
Re: upgrading modules perl 5.8.8 -> 5.10.0 <friendly@yorku.ca>
Re: upgrading modules perl 5.8.8 -> 5.10.0 <noreply@gunnar.cc>
Re: upgrading modules perl 5.8.8 -> 5.10.0 <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Mar 2009 05:19:28 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Regex compiler not showing backtracking for *
Message-Id: <484e1c3b-a0b4-4d04-8629-9c12ba29d91d@j9g2000prh.googlegroups.com>
Hi, am trying out the "Smeagol" example from "Programming
Perl" (section 5.9.3) :
#!/usr/bin/perl
use re "debug";
"Smeagol" =~ /^Sm(.*)g[aeiou]l$/;
Am using perl 5.10.0 on 32-bit Windows XP. Following is the output:
====================================
Compiling REx "^Sm(.*)g[aeiou]l$"
Final program:
1: BOL (2)
2: EXACT <Sm> (4)
4: OPEN1 (6)
6: STAR (8)
7: REG_ANY (0)
8: CLOSE1 (10)
10: EXACT <g> (12)
12: ANYOF[aeiou] (23)
23: EXACT <l> (25)
25: EOL (26)
26: END (0)
anchored "Sm" at 0 floating "l"$ at 4..2147483647 (checking anchored)
anchored(BOL) minlen 5
Guessing start of match in sv for REx "^Sm(.*)g[aeiou]l$" against
"Smeagol"
Guessed: match at offset 0
Matching REx "^Sm(.*)g[aeiou]l$" against "Smeagol"
0 <> <Smeagol> | 1:BOL(2)
0 <> <Smeagol> | 2:EXACT <Sm>(4)
2 <Sm> <eagol> | 4:OPEN1(6)
2 <Sm> <eagol> | 6:STAR(8)
REG_ANY can match 5 times out of
2147483647...
4 <Smea> <gol> | 8: CLOSE1(10)
4 <Smea> <gol> | 10: EXACT <g>(12)
5 <Smeag> <ol> | 12: ANYOF[aeiou](23)
6 <Smeago> <l> | 23: EXACT <l>(25)
7 <Smeagol> <> | 25: EOL(26)
7 <Smeagol> <> | 26: END(0)
Match successful!
Freeing REx: "^Sm(.*)g[aeiou]l$"
====================================
Why is there no backtracking for the maximal match quantifier " * "?
Or backtracking is actually happening but the pragma re "debug" output
is different (not showing backtracking)? Could someone please point
out if I'm missing anything?
Thanks
------------------------------
Date: Sat, 28 Mar 2009 16:30:39 GMT
From: sln@netherlands.com
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <uojss4h3rmbuna7fh696l40cshj8e88pfg@4ax.com>
On Sat, 28 Mar 2009 05:19:28 -0700 (PDT), Krishna Chaitanya <schaitan@gmail.com> wrote:
>Hi, am trying out the "Smeagol" example from "Programming
>Perl" (section 5.9.3) :
>
>#!/usr/bin/perl
>use re "debug";
>"Smeagol" =~ /^Sm(.*)g[aeiou]l$/;
>
>Am using perl 5.10.0 on 32-bit Windows XP. Following is the output:
>
[snip]
>
>Why is there no backtracking for the maximal match quantifier " * "?
>Or backtracking is actually happening but the pragma re "debug" output
>is different (not showing backtracking)? Could someone please point
>out if I'm missing anything?
>
>Thanks
I don't think the results show back tracking, it shows a differential
of eval stacks that directly matched or did not match the pattern.
But if you want to see backtracking, put in more than one quantifier and
set up back track condition. The one below demonstrates that, and exhausts
all possibillities, then fails.
-sln
-------------------------------------------
use re "debug";
"Smeaeagol2" =~ /^Sm(.*)g*[aeiou]l$/;
-------------------------------------------
Compiling REx `^Sm(.*)g*[aeiou]l$'
size 27 Got 220 bytes for offset annotations.
first at 2
1: BOL(2)
2: EXACT <Sm>(4)
4: OPEN1(6)
6: STAR(8)
7: REG_ANY(0)
8: CLOSE1(10)
10: STAR(13)
11: EXACT <g>(0)
13: ANYOF[aeiou](24)
24: EXACT <l>(26)
26: EOL(27)
27: END(0)
anchored `Sm' at 0 floating `l'$ at 3..2147483647 (checking anchored) anchored(B
OL) minlen 4
Offsets: [27]
1[1] 2[2] 0[0] 4[1] 0[0] 6[1] 5[1] 7[1] 0[0] 9[1] 8[1] 0[0] 10[7] 0[0] 0
[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 17[1] 0[0] 18[1] 19[0]
Guessing start of match, REx `^Sm(.*)g*[aeiou]l$' against `Smeaeagol2'...
Guessed: match at offset 0
Matching REx `^Sm(.*)g*[aeiou]l$' against `Smeaeagol2'
Setting an EVAL scope, savestack=3
0 <> <Smeaeagol2> | 1: BOL
0 <> <Smeaeagol2> | 2: EXACT <Sm>
2 <Sm> <eaeagol2> | 4: OPEN1
2 <Sm> <eaeagol2> | 6: STAR
REG_ANY can match 8 times out of 2147483647...
Setting an EVAL scope, savestack=3
10 <Smeaeagol2> <> | 8: CLOSE1
10 <Smeaeagol2> <> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
10 <Smeaeagol2> <> | 13: ANYOF[aeiou]
failed...
failed...
9 <Smeaeagol> <2> | 8: CLOSE1
9 <Smeaeagol> <2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
9 <Smeaeagol> <2> | 13: ANYOF[aeiou]
failed...
failed...
8 <Smeaeago> <l2> | 8: CLOSE1
8 <Smeaeago> <l2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
8 <Smeaeago> <l2> | 13: ANYOF[aeiou]
failed...
failed...
7 <Smeaeag> <ol2> | 8: CLOSE1
7 <Smeaeag> <ol2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
7 <Smeaeag> <ol2> | 13: ANYOF[aeiou]
8 <Smeaeago> <l2> | 24: EXACT <l>
9 <Smeaeagol> <2> | 26: EOL
failed...
failed...
6 <Smeaea> <gol2> | 8: CLOSE1
6 <Smeaea> <gol2> | 10: STAR
EXACT <g> can match 1 times out of 2147483647...
Setting an EVAL scope, savestack=3
7 <Smeaeag> <ol2> | 13: ANYOF[aeiou]
8 <Smeaeago> <l2> | 24: EXACT <l>
9 <Smeaeagol> <2> | 26: EOL
failed...
6 <Smeaea> <gol2> | 13: ANYOF[aeiou]
failed...
failed...
5 <Smeae> <agol2> | 8: CLOSE1
5 <Smeae> <agol2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
5 <Smeae> <agol2> | 13: ANYOF[aeiou]
6 <Smeaea> <gol2> | 24: EXACT <l>
failed...
failed...
4 <Smea> <eagol2> | 8: CLOSE1
4 <Smea> <eagol2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
4 <Smea> <eagol2> | 13: ANYOF[aeiou]
5 <Smeae> <agol2> | 24: EXACT <l>
failed...
failed...
3 <Sme> <aeagol2> | 8: CLOSE1
3 <Sme> <aeagol2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
3 <Sme> <aeagol2> | 13: ANYOF[aeiou]
4 <Smea> <eagol2> | 24: EXACT <l>
failed...
failed...
2 <Sm> <eaeagol2> | 8: CLOSE1
2 <Sm> <eaeagol2> | 10: STAR
EXACT <g> can match 0 times out of 2147483647...
Setting an EVAL scope, savestack=3
2 <Sm> <eaeagol2> | 13: ANYOF[aeiou]
3 <Sme> <aeagol2> | 24: EXACT <l>
failed...
failed...
failed...
Match failed
Freeing REx: `"^Sm(.*)g*[aeiou]l$"'
------------------------------
Date: Sat, 28 Mar 2009 17:01:12 GMT
From: sln@netherlands.com
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <31lss419675omt3m8bnvdlggt79v0mojs8@4ax.com>
On Sat, 28 Mar 2009 05:19:28 -0700 (PDT), Krishna Chaitanya <schaitan@gmail.com> wrote:
>Hi, am trying out the "Smeagol" example from "Programming
>Perl" (section 5.9.3) :
>
>#!/usr/bin/perl
>use re "debug";
>"Smeagol" =~ /^Sm(.*)g[aeiou]l$/;
>
>Am using perl 5.10.0 on 32-bit Windows XP. Following is the output:
>
>====================================
>
>Compiling REx "^Sm(.*)g[aeiou]l$"
>Final program:
> 1: BOL (2)
> 2: EXACT <Sm> (4)
> 4: OPEN1 (6)
> 6: STAR (8)
> 7: REG_ANY (0)
> 8: CLOSE1 (10)
> 10: EXACT <g> (12)
> 12: ANYOF[aeiou] (23)
> 23: EXACT <l> (25)
> 25: EOL (26)
> 26: END (0)
>anchored "Sm" at 0 floating "l"$ at 4..2147483647 (checking anchored)
>anchored(BOL) minlen 5
>Guessing start of match in sv for REx "^Sm(.*)g[aeiou]l$" against
>"Smeagol"
>Guessed: match at offset 0
>Matching REx "^Sm(.*)g[aeiou]l$" against "Smeagol"
> 0 <> <Smeagol> | 1:BOL(2)
> 0 <> <Smeagol> | 2:EXACT <Sm>(4)
^^
found 'Sm', take off 'Sm'
> 2 <Sm> <eagol> | 4:OPEN1(6)
> 2 <Sm> <eagol> | 6:STAR(8)
^
found 'g', take off 'ea' (end of quantifier *)
> REG_ANY can match 5 times out of
>2147483647...
> 4 <Smea> <gol> | 8: CLOSE1(10)
> 4 <Smea> <gol> | 10: EXACT <g>(12)
^
found 'g', take off 'g'
> 5 <Smeag> <ol> | 12: ANYOF[aeiou](23)
^
found 'o', take off 'o'
> 6 <Smeago> <l> | 23: EXACT <l>(25)
^
found 'l', take off 'l
I goes all the way to the end without backtracking.
That is becuase all the other characters after 'ea' match and
they are no other quantifiers. Even if the characters
after Sm did not match the constants after '.*' in the regex,
there would be no backtracking, there is no other variability in the
regex.
-sln
Match failed, still no backtracking:
---------------------------------------------
use re "debug";
"Smeagol2" =~ /^Sm(.*)g[aeiou]l$/;
-----------------------------------------
Compiling REx `^Sm(.*)g[aeiou]l$'
size 26 Got 212 bytes for offset annotations.
first at 2
1: BOL(2)
2: EXACT <Sm>(4)
4: OPEN1(6)
6: STAR(8)
7: REG_ANY(0)
8: CLOSE1(10)
10: EXACT <g>(12)
12: ANYOF[aeiou](23)
23: EXACT <l>(25)
25: EOL(26)
26: END(0)
anchored `Sm' at 0 floating `l'$ at 4..2147483647 (checking anchored) anchored(B
OL) minlen 5
Offsets: [26]
1[1] 2[2] 0[0] 4[1] 0[0] 6[1] 5[1] 7[1] 0[0] 8[1] 0[0] 9[7] 0[0] 0[0] 0[
0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 16[1] 0[0] 17[1] 18[0]
Guessing start of match, REx `^Sm(.*)g[aeiou]l$' against `Smeagol2'...
Guessed: match at offset 0
Matching REx `^Sm(.*)g[aeiou]l$' against `Smeagol2'
Setting an EVAL scope, savestack=3
0 <> <Smeagol2> | 1: BOL
0 <> <Smeagol2> | 2: EXACT <Sm>
2 <Sm> <eagol2> | 4: OPEN1
2 <Sm> <eagol2> | 6: STAR
REG_ANY can match 6 times out of 2147483647...
Setting an EVAL scope, savestack=3
4 <Smea> <gol2> | 8: CLOSE1
4 <Smea> <gol2> | 10: EXACT <g>
5 <Smeag> <ol2> | 12: ANYOF[aeiou]
6 <Smeago> <l2> | 23: EXACT <l>
7 <Smeagol> <2> | 25: EOL
failed...
failed...
Match failed
Freeing REx: `"^Sm(.*)g[aeiou]l$"'
-sln
------------------------------
Date: Sat, 28 Mar 2009 19:49:24 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <slrngst009.qr3.nospam-abuse@chorin.math.berkeley.edu>
On 2009-03-28, Krishna Chaitanya <schaitan@gmail.com> wrote:
I do not remember details, and did not look into the source today, so
it might be all bogus...
> Compiling REx "^Sm(.*)g[aeiou]l$"
...
> 6: STAR (8)
> 7: REG_ANY (0)
...
I suspect it is a lie...
> 2 <Sm> <eagol> | 6:STAR(8)
> REG_ANY can match 5 times out of INF...
> 4 <Smea> <gol> | 8: CLOSE1(10)
> 4 <Smea> <gol> | 10: EXACT <g>(12)
My conjecture is that the actual node in the compiled REx is not
STAR(REG_ANY), but OPTIMIZED_STAR_ANCHOREDBY(REG_ANY, <g>) (invented
name ;-). This would mean that what follows the node "7:" is checked
ONLY IF it starts with "g".
This is not contradicted by the effect of having an extra g after Sm
perl -Mre=debug -wle "q(Smeagogl) =~ /^Sm(.*)g[aeiou]l$/"
2 <Sm> <eagogl> | 6: STAR
REG_ANY can match 6 times out of INF...
Setting an EVAL scope, savestack=3
6 <Smeago> <gl> | 8: CLOSE1
6 <Smeago> <gl> | 10: EXACT <g>
7 <Smeagog> <l> | 12: ANYOF[aeiou]
failed...
4 <Smea> <gogl> | 8: CLOSE1
4 <Smea> <gogl> | 10: EXACT <g>
Hope this helps,
Ilya
------------------------------
Date: Sat, 28 Mar 2009 13:15:11 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <8d2bde63-16f6-44e6-b964-46668c0f5930@s38g2000prg.googlegroups.com>
What surprises me is the example in the camel book actually shows
backtracking for this example. But executing the same here did not.
How is this difference arising?
------------------------------
Date: Sat, 28 Mar 2009 20:26:20 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <cod2a6-75k.ln1@osiris.mauzo.dyndns.org>
Quoth Krishna Chaitanya <schaitan@gmail.com>:
> What surprises me is the example in the camel book actually shows
> backtracking for this example. But executing the same here did not.
> How is this difference arising?
The Camel was written shortly before the release of 5.6. You are almost
certainly using 5.8.8, 5.8.9 or 5.10.0. Quite a lot has changed in the
regex engine between those points, so I would not be surprised if
something that once required backtracking is now optimised into
something that doesn't.
Ben
------------------------------
Date: Sat, 28 Mar 2009 20:36:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <Xns9BDCA8E358474asu1cornelledu@127.0.0.1>
Krishna Chaitanya <schaitan@gmail.com> wrote in news:8d2bde63-16f6-44e6-
b964-46668c0f5930@s38g2000prg.googlegroups.com:
> What surprises me is the example in the camel book actually shows
> backtracking for this example. But executing the same here did not.
> How is this difference arising?
You are going to have to bite the bullet and learn how to quote.
Please read the posting guidelines. Understand them. Apply them.
The answer to your question: Maybe, just maybe, the authors used a
different version of perl when they were writing the book.
Have you considered that possibility?
Maybe what they wrote back then no longer applies.
I don't have the book with me but I have a vague recollection of that
section.
The authors were just describing behavior rather than explaining a
specification.
Therefore, I find your expectation that pathalogical behavior that was
exhibited by the regex engine back then to have remained with us at
least mildly perturbing.
Now, please, before you go back to studying typeglobs, read the posting
guidelines.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Sat, 28 Mar 2009 20:45:37 GMT
From: sln@netherlands.com
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <3l2ts494ppkcjc015alkma744m5977bhnp@4ax.com>
On Sat, 28 Mar 2009 19:49:24 GMT, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>On 2009-03-28, Krishna Chaitanya <schaitan@gmail.com> wrote:
>
>I do not remember details, and did not look into the source today, so
>it might be all bogus...
>
>> Compiling REx "^Sm(.*)g[aeiou]l$"
>...
>> 6: STAR (8)
>> 7: REG_ANY (0)
>...
>
>I suspect it is a lie...
>
>> 2 <Sm> <eagol> | 6:STAR(8)
>> REG_ANY can match 5 times out of INF...
>> 4 <Smea> <gol> | 8: CLOSE1(10)
>> 4 <Smea> <gol> | 10: EXACT <g>(12)
>
>My conjecture is that the actual node in the compiled REx is not
>STAR(REG_ANY), but OPTIMIZED_STAR_ANCHOREDBY(REG_ANY, <g>) (invented
>name ;-). This would mean that what follows the node "7:" is checked
>ONLY IF it starts with "g".
>
>This is not contradicted by the effect of having an extra g after Sm
>
> perl -Mre=debug -wle "q(Smeagogl) =~ /^Sm(.*)g[aeiou]l$/"
>
> 2 <Sm> <eagogl> | 6: STAR
> REG_ANY can match 6 times out of INF...
> Setting an EVAL scope, savestack=3
> 6 <Smeago> <gl> | 8: CLOSE1
> 6 <Smeago> <gl> | 10: EXACT <g>
> 7 <Smeagog> <l> | 12: ANYOF[aeiou]
> failed...
> 4 <Smea> <gogl> | 8: CLOSE1
> 4 <Smea> <gogl> | 10: EXACT <g>
>
>Hope this helps,
>Ilya
Yes, but the point is that backtracking only occurs on a failed match
where there are other possibilities given classes and quantifiers,
and the available target string.
None of those conditions applied in her case.
"this is the one" =~ /.*r/
doesen't cut it. No backtracking at all.
-sln
------------------------------
Date: Sun, 29 Mar 2009 00:58:26 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Regex compiler not showing backtracking for *
Message-Id: <21061ba4-cff2-4ae2-99d9-2b1b19563cd4@c18g2000prh.googlegroups.com>
> The answer to your question: Maybe, just maybe, the authors used a
> different version of perl when they were writing the book.
>
> Have you considered that possibility?
Yes. I couldn't have missed it. I stated I am using 5.10.0 and I could
see the book was written during (or covering) 5.6.
>
> Maybe what they wrote back then no longer applies.
>
> I don't have the book with me but I have a vague recollection of that
> section.
>
> The authors were just describing behavior rather than explaining a
> specification.
>
But, the example's output definitely showed the (.*) eating up the
rest of the string and yielding a character at a time till a 'g' was
found.
> Therefore, I find your expectation that pathalogical behavior that was
> exhibited by the regex engine back then to have remained with us at
> least mildly perturbing.
>
Let's agree with you here. What must have changed? The regex rules?
The pragma's output? If so, what is the authoritative text now for me?
I'll just go back and read my way through. My ecstatic feeling was
that using the pragma and the rules from the book, I can learn to
write better regexes.
------------------------------
Date: Mon, 30 Mar 2009 04:13:28 -0700 (PDT)
From: molsted <molsted@gmail.com>
Subject: search/replace
Message-Id: <c230a99c-0a47-4fe6-b822-69d10e557e9c@3g2000yqk.googlegroups.com>
Hi all
I'm trying to relpace some strings in a textfile like this:
&00Antiques^M&00Antiquit<0x00E4>ten^M&00Antiquit<0x00E9>s^M&00Antig<0x00FC>edades^M&00Antikviteter^M
I've tried the following:
s/&00(.+?)\r\n&00(.+?)\r\n&00(.+?)\r\n&00(.+?)\r\n&00(.+?)\r\n/
<Style:GB>$1\n<Style:DE>$2\n<Style:FR>$3\n<Style:ES>$4\n<Style:DK>$5/
g;
with no luck.
--
Rene
------------------------------
Date: Mon, 30 Mar 2009 07:41:06 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: search/replace
Message-Id: <slrngt1ff2.228.tadmc@tadmc30.sbcglobal.net>
molsted <molsted@gmail.com> wrote:
> I'm trying to relpace some strings in a textfile like this:
> &00Antiques^M&00Antiquit<0x00E4>ten^M&00Antiquit<0x00E9>s^M&00Antig<0x00FC>edades^M&00Antikviteter^M
Does your data really have caret-M in it or does it instead have
carriage return-linefeed in it?
You should write the data in Real Perl Code so that there is no ambiguity.
Have you seen the Posting Guidelines that are posted here frequently?
--------------------------
#!/usr/bin/perl
use warnings;
use strict;
my @lang = qw/ <Style:GB> <Style:DE> <Style:FR> <Style:ES> <Style:DK> /;
$_ = "&00Antiques\r\n&00Antiquit<0x00E4>ten\r\n&00Antiquit<0x00E9>s\r\n"
. "&00Antig<0x00FC>edades\r\n&00Antikviteter\r\n";
print;
print "\n";
my $capture_num = 0;
s/&00([^\r]+)\r\n/$lang[$capture_num++]$1\n/g;
print;
--------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 30 Mar 2009 14:51:07 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: search/replace
Message-Id: <slrngt1n2s.ijf.glennj@smeagol.ncf.ca>
At 2009-03-30 07:13AM, "molsted" wrote:
> Hi all
> I'm trying to relpace some strings in a textfile like this:
> &00Antiques^M&00Antiquit<0x00E4>ten^M&00Antiquit<0x00E9>s^M&00Antig<0x00FC>edades^M&00Antikviteter^M
>
> I've tried the following:
> s/&00(.+?)\r\n&00(.+?)\r\n&00(.+?)\r\n&00(.+?)\r\n&00(.+?)\r\n/
> <Style:GB>$1\n<Style:DE>$2\n<Style:FR>$3\n<Style:ES>$4\n<Style:DK>$5/
> g;
I'd use split and join here. The delimiter is clear and you don't
really care what's in between:
my $delim = '&00';
my $str = '&00Antiques^M&00Antiquit<0x00E4>ten^M&00Antiquit<0x00E9>s^M&00Antig<0x00FC>edades^M&00Antikviteter^M';
my @words = split /$delim/, $str;
my @langs = ('','GB','DE','FR','ES','DK');
for (my $i = 1; $i < $#words; $i++) {
$words[$i] = '<Style:' . $langs[$i] . '>' . $words[$i];
}
$_ = join $delim, @words;
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Sat, 28 Mar 2009 01:53:14 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Typeglobs vs References
Message-Id: <eqfzl.44445$5t4.6026@newsfe24.iad>
On Fri, 27 Mar 2009 15:59:37 -0400, Charlton Wilbur wrote:
>>>>>> "KC" == Krishna Chaitanya <schaitan@gmail.com> writes:
>
> KC> But as a matter of curiosity, is it everyone's opinion here that
> KC> trying to understand type-globs is totally unproductive and not
> KC> worth one's time?
>
> It is my opinion that trying to understand typeglobs is something you
> should do only when you need to use typeglobs for something.
>
> This has been my attitude with formats, for instance, and the last time
> I looked at them was in 1996. I have no idea how they work, and it
> hasn't hampered me in the slightest.
Well said. Sometimes I think that most of the use of typeglobs in the
last decade has been for MJD to produce mind-bending "Tricks of the
Wizards" talks...
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
------------------------------
Date: Sat, 28 Mar 2009 03:51:30 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Typeglobs vs References
Message-Id: <2fj0a6-qu6.ln1@osiris.mauzo.dyndns.org>
Quoth Peter Scott <Peter@PSDT.com>:
> On Fri, 27 Mar 2009 15:59:37 -0400, Charlton Wilbur wrote:
> >>>>>> "KC" == Krishna Chaitanya <schaitan@gmail.com> writes:
> >
> > KC> But as a matter of curiosity, is it everyone's opinion here that
> > KC> trying to understand type-globs is totally unproductive and not
> > KC> worth one's time?
> >
> > It is my opinion that trying to understand typeglobs is something you
> > should do only when you need to use typeglobs for something.
> >
> > This has been my attitude with formats, for instance, and the last time
> > I looked at them was in 1996. I have no idea how they work, and it
> > hasn't hampered me in the slightest.
>
> Well said. Sometimes I think that most of the use of typeglobs in the
> last decade has been for MJD to produce mind-bending "Tricks of the
> Wizards" talks...
Well, there's Exporter, which relies critically on typeglobs to work.
But yeah, anyone who's not trying to reimplement Exporter or IO::Handle
doesn't really need to understand typeglobs at all.
Ben
------------------------------
Date: Fri, 27 Mar 2009 21:32:16 -0700 (PDT)
From: "friendly@yorku.ca" <friendly@yorku.ca>
Subject: Re: upgrading modules perl 5.8.8 -> 5.10.0
Message-Id: <7fafb260-309b-451a-9217-d7ee1d1aff64@r18g2000vbi.googlegroups.com>
On Mar 27, 6:04=A0pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> The best way to do that is to install 5.10.0 so that 5.8.8 paths to pure
> Perl modules are included in @INC. Try this link for further guidance on
> the topic:http://search.cpan.org/~rgarcia/perl-5.10.0/INSTALL#Coexistence=
_with_...
>
> Otherwise you may want to play with the PERL5LIB environment variable or
> the lib pragma.
>
Thanks for the reply.
OK, setting PERL5LIB seems like the easiest way for non-compiled
modules.
How could I find the 5.8.8 modules I have which *are* compiled?
-Michael
------------------------------
Date: Sat, 28 Mar 2009 14:00:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: upgrading modules perl 5.8.8 -> 5.10.0
Message-Id: <i4n1a6-2sh.ln1@osiris.mauzo.dyndns.org>
Quoth "friendly@yorku.ca" <friendly@yorku.ca>:
> On Mar 27, 6:04 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> > The best way to do that is to install 5.10.0 so that 5.8.8 paths to pure
> > Perl modules are included in @INC. Try this link for further guidance on
> > the
> topic:http://search.cpan.org/~rgarcia/perl-5.10.0/INSTALL#Coexistence_with_...
> >
> > Otherwise you may want to play with the PERL5LIB environment variable or
> > the lib pragma.
> >
> Thanks for the reply.
>
> OK, setting PERL5LIB seems like the easiest way for non-compiled
> modules.
> How could I find the 5.8.8 modules I have which *are* compiled?
Assuming you've set PERL5LIB to include all the relevant paths,
perl -MExtUtils::Installed -le'
my $I = ExtUtils::Installed->new;
print for
grep /\.so$/,
map $I->files($_),
$I->modules;'
I would expect, though, that Debian provides a tool called 'I've broken
perl bincompat; re-install everything for me'. Most OS distributions do.
Ben
------------------------------
Date: Mon, 30 Mar 2009 10:28:17 -0400
From: Michael Friendly <friendly@yorku.ca>
Subject: Re: upgrading modules perl 5.8.8 -> 5.10.0
Message-Id: <gqqku2$2i6$1@sunburst.ccs.yorku.ca>
Gunnar Hjalmarsson wrote:
> Michael Friendly wrote:
>> [Running debian linux]
>> As part of a routine upgrade of some of my software, apt insisted on
>> upgrading perl from 5..8.8 to 5.10.0.
>>
>> I had many CPAN modules installed, under
>> /usr/local/lib/perl/5.8.8/
>> /usr/local/share/perl/5.8.8/
>>
>> and now, of course, my scripts that try to USE them fail.
>
> That's not apparent to me out from your description. Paths containing
> pure Perl modules typically should work under 5.10.0 as well. Of course,
> you have to make sure that your 5.10.0 perl finds them.
>
> The best way to do that is to install 5.10.0 so that 5.8.8 paths to pure
> Perl modules are included in @INC. Try this link for further guidance on
> the topic:
> http://search.cpan.org/~rgarcia/perl-5.10.0/INSTALL#Coexistence_with_earlier_versions_of_perl_5
Is there any way to append my previous 5.8.8 paths to @INC without
recompiling perl or modifying my script files. That would be the
cleanest solution. Then I could update any modules in 5.10.0 I
needed using the cpan tool and the updated versions would be found
first. Alternatively, something like
cpan upgrade
where it looks in my 5.8.8 libraries and upgrades these to 5.10.0
As a temporary measure, I modified PERL5LIB,
PERL5LIB=/home/friendly/lib/perl:/usr/local/share/perl/5.8.8/:/usr/local/lib/perl/5.8.8/
but I realized this means that anything under 5.8.8 would take
precedence over anything newer in 5.10.0
>
> Otherwise you may want to play with the PERL5LIB environment variable or
> the lib pragma.
--
Michael Friendly Email: friendly@yorku.ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA
------------------------------
Date: Mon, 30 Mar 2009 17:44:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: upgrading modules perl 5.8.8 -> 5.10.0
Message-Id: <73c7noFtvdt1U1@mid.individual.net>
Michael Friendly wrote:
> Gunnar Hjalmarsson wrote:
>> Michael Friendly wrote:
>>> [Running debian linux]
>>> As part of a routine upgrade of some of my software, apt insisted on
>>> upgrading perl from 5..8.8 to 5.10.0.
>>>
>>> I had many CPAN modules installed, under
>>> /usr/local/lib/perl/5.8.8/
>>> /usr/local/share/perl/5.8.8/
>>>
>>> and now, of course, my scripts that try to USE them fail.
>>
>> That's not apparent to me out from your description. Paths containing
>> pure Perl modules typically should work under 5.10.0 as well. Of
>> course, you have to make sure that your 5.10.0 perl finds them.
>>
>> The best way to do that is to install 5.10.0 so that 5.8.8 paths to
>> pure Perl modules are included in @INC. Try this link for further
>> guidance on the topic:
>> http://search.cpan.org/~rgarcia/perl-5.10.0/INSTALL#Coexistence_with_earlier_versions_of_perl_5
>
> Is there any way to append my previous 5.8.8 paths to @INC without
> recompiling perl or modifying my script files. That would be the
> cleanest solution. Then I could update any modules in 5.10.0 I
> needed using the cpan tool and the updated versions would be found
> first. Alternatively, something like
> cpan upgrade
> where it looks in my 5.8.8 libraries and upgrades these to 5.10.0
>
> As a temporary measure, I modified PERL5LIB,
> PERL5LIB=/home/friendly/lib/perl:/usr/local/share/perl/5.8.8/:/usr/local/lib/perl/5.8.8/
>
> but I realized this means that anything under 5.8.8 would take
> precedence over anything newer in 5.10.0
Right. So, to summarize, you don't want to
- recompile perl
- modify the script files
- make older modules take precedence over modules installed in 5.10.0
Well, that equation is over my head. ;-)
If you are ready to give up your wish to not change the script files,
you can use push() to append paths to @INC:
BEGIN {
push @INC, qw(
/home/friendly/lib/perl
/usr/local/share/perl/5.8.8/
/usr/local/lib/perl/5.8.8/
);
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 30 Mar 2009 18:02:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: upgrading modules perl 5.8.8 -> 5.10.0
Message-Id: <pha7a6-ej1.ln1@osiris.mauzo.dyndns.org>
Quoth Michael Friendly <friendly@yorku.ca>:
>
> Is there any way to append my previous 5.8.8 paths to @INC without
> recompiling perl or modifying my script files. That would be the
> cleanest solution. Then I could update any modules in 5.10.0 I
> needed using the cpan tool and the updated versions would be found
> first. Alternatively, something like
> cpan upgrade
> where it looks in my 5.8.8 libraries and upgrades these to 5.10.0
You're going about this the wrong way. If you're using a vendor-provided
perl and vendor-provided perl modules, you should be using vendor tools
to upgrade. If the vendor tools don't upgrade correctly (assuming you've
used them right) you should file a bug with your vendor.
Have you checked if your OS provides a tool to upgrade all XS modules
when perl bincompat breaks? Have you read any available instructions
about upgrading perl provided by your vendor?
If you are dealing with modules you have installed by hand, then you
really ought to have made a CPAN autobundle (see the docs for CPAN.pm)
before you upgraded. Since you haven't, use ExtUtils::Installed to list
the installed modules and reinstall them. You will need to use
inc_override or PERL5LIB to tell E::I where to look.
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 2307
***************************************