[29786] in Perl-Users-Digest
Perl-Users Digest, Issue: 1029 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 13 09:09:37 2007
Date: Tue, 13 Nov 2007 06:09:06 -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 Tue, 13 Nov 2007 Volume: 11 Number: 1029
Today's topics:
Re: Distributed RVS, Darcs, tech love <piet@cs.uu.nl>
Re: Index of first and last non-"\xff" in a long string w.c.humann@arcor.de
Re: peculiar behaviour with prototyped routines sheinrich@my-deja.com
Processing a while within a while Russell.Mottram@gmail.com
Re: Processing a while within a while <wyzelli@yahoo.com.au>
Re: Processing a while within a while Russell.Mottram@gmail.com
Re: Processing a while within a while sheinrich@my-deja.com
Re: Processing a while within a while Russell.Mottram@gmail.com
Re: Processing a while within a while Russell.Mottram@gmail.com
Regexp substitution with dynamic replacement string augukarl@yahoo.se
Re: Regexp substitution with dynamic replacement string <peter@makholm.net>
Re: Regexp substitution with dynamic replacement string augukarl@yahoo.se
Re: replace string contaning \n <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Nov 2007 13:52:57 +0100
From: Piet van Oostrum <piet@cs.uu.nl>
Subject: Re: Distributed RVS, Darcs, tech love
Message-Id: <m2fxza9uja.fsf@cochabamba.cs.uu.nl>
>>>>> Lew <lew@lewscanon.com> (L) wrote:
>L> Evidence is that TeX development is dead. There is not yet firm evidence
>L> that Tex is a "dead end" (or even what that means), and there has been none
>L> (nor, I expect, is there any) that any of that reflects on Knuth's skill as
>L> a programmer.
According to Knuth's definition the name 'TeX' is reserved for a program
that passes the trip test. Under this assumption TeX is dead by definition.
However in a broader sense TeX is still actively developed, but it may not
be called just 'TeX' because these new versions contain extensions. So
they get new names with 'tex' being part of their name. PdfTeX and LuaTeX
are new versions that are being developed right now.
--
Piet van Oostrum <piet@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet@vanoostrum.org
------------------------------
Date: Tue, 13 Nov 2007 03:34:23 -0800
From: w.c.humann@arcor.de
Subject: Re: Index of first and last non-"\xff" in a long string
Message-Id: <1194953663.767442.236280@o3g2000hsb.googlegroups.com>
On Nov 12, 10:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Interesting... which version of perl? With
> This is perl, v5.8.8 built for i386-freebsd-64int
Mine is:
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
>
> and adding this
>
> innerm => sub {
> local $_ = $str;
> /[^\xff].*[^\xff]/s;
> 161 == ($-[0] + 1) or die "innerm \$+ failed: " . ($-[0] + 1);
> 10_160 == $+[0] or die "innerm \$- failed: " . $+[0];
> },
>
> to my previous benchmark, I get
>
> Rate match index innerm C
> match 9609/s -- -41% -53% -91%
> index 16398/s 71% -- -21% -85%
> innerm 20641/s 115% 26% -- -81%
> C 109225/s 1037% 566% 429% --
Well, with your test-string I get:
Rate subst sloop chop match index reverse
innerm
subst 1306/s -- -91% -94% -94% -94% -95%
-97%
sloop 13917/s 965% -- -33% -41% -41% -52%
-72%
chop 20894/s 1499% 50% -- -11% -11% -28%
-59%
match 23417/s 1693% 68% 12% -- -1% -19%
-54%
index 23561/s 1704% 69% 13% 1% -- -18%
-53%
reverse 28902/s 2112% 108% 38% 23% 23% --
-43%
innerm 50510/s 3767% 263% 142% 116% 114% 75%
--
so indeed 'innerm' wins, but...
> though seriously increasing the number of trailing "\xff"s causes both
> 'match' and 'innerm' to perform dramatically badly, so maybe this is an
> artefact of my test string.
typical files have blank lines at top and bottom and if I modify your
script like this:
# lenght of left, middle and right part of string
#my ($l,$m,$r) = (160, 10_000, 150);
my ($l,$m,$r) = (5000, 2, 5000);
my $str = ("\xff" x $l) . ("f" x $m) . ("\xff" x $r);
my $len = length $str;
cmpthese -3, {
match => sub {
local $_ = $str;
# this is the fastest single match I can come up with
/^((?>\xff*)).*[^\xff]((?>\xff*))$/;
$l+1 == 1 + $+[1] or die "\$+ failed: " . (1 + $+[1]);
$l+$m == $-[2] or die "\$- failed: " . $-[2];
},
etc.
the result is:
Rate subst sloop chop match innerm
reverse index
subst 1.44/s -- -100% -100% -100% -100%
-100% -100%
sloop 462/s 32117% -- -37% -75% -82%
-86% -98%
chop 737/s 51284% 59% -- -60% -71%
-78% -96%
match 1844/s 128383% 299% 150% -- -28%
-45% -91%
innerm 2575/s 179348% 457% 249% 40% --
-23% -87%
reverse 3352/s 233498% 625% 355% 82% 30%
-- -84%
index 20452/s 1424967% 4323% 2673% 1009% 694%
510% --
Stange enough with my ($l,$m,$r) = (5000, 1, 5000); 'innerm' fails!?
An optimization not considered so far: Once I've found a left and
right bound in a line, I only need to check from the edges up these
bounds in all following lines, because my bounding-box can only grow
(and never shrink) while checking further lines. As a faked test I've
used this:
index2 => sub {
my $left = substr($str,0,$l+500);
my $right = substr($str,$l+$m-500,$r+500);
$left =~ tr,\x00-\xfe,\x00,;
$right =~ tr,\x00-\xfe,\x00,;
$l+1 == 1 + index $left, "\x00"
or die "index failed: " . (1 + index $left, "\x00");
500 == 1 + rindex $right, "\x00"
or die "rindex failed: " . (1 + rindex $right, "\x00");
},
The potential savings are big but of course highly dependent on the
actual image:
Rate index reverse innerm index2
index 23924/s -- -17% -53% -82%
reverse 28749/s 20% -- -43% -79%
innerm 50574/s 111% 76% -- -63%
index2 136616/s 471% 375% 170% --
Wolfram
------------------------------
Date: Tue, 13 Nov 2007 03:42:26 -0800
From: sheinrich@my-deja.com
Subject: Re: peculiar behaviour with prototyped routines
Message-Id: <1194954146.648134.280110@d55g2000hsg.googlegroups.com>
From, e.g. Tom Christiansen's "FMTEYEWTK about Prototypes in Perl" at
http://library.n0i.net/programming/perl/articles/fm_prototypes/
"Make sure that that definition is seen by the compiler before it
compiles any calls to the function."
Because testlib.pl is required at runtime the calls to your functions
have already been compiled inside your main script and the prototypes
can not be applied anymore. The result is exactly the same as if you'd
remove the prototypes.
Mixing arrays (or hashes) with any other parameters is generally not a
good idea.
If there is only one array put it at the end, behind other scalars.
Better still, use references which is also much more efficient when it
comes to large arrays.
And you also have the choice whether or not to change the values
inside your sub.
Cheers,
Steffen
------------------------------
Date: Tue, 13 Nov 2007 12:54:07 -0000
From: Russell.Mottram@gmail.com
Subject: Processing a while within a while
Message-Id: <1194958447.706382.117260@v23g2000prn.googlegroups.com>
Hi,
I'm currently studying a relatively basic PERL course, and have an end
of semester assignment due very soon.
I've managed to get through everything so far, except I'm now stuck on
the very last bit, which is printing a comparison between two hashes.
Essentially, the problem is this:
The system log (system.evt) has been searched for Telnet entries, and
positive matches have been moved into %TelnetEntry.
Then the security log (security.evt) has been searched for users who
were logged on at the time, excluding Network Service, Local Service,
and one other random user. Users have been moved into %SecTime.
I now need to iterate through both to determine at the time the Telnet
service was started, who was logged on?
This is the code I'm working on:
while (($TelnetTime,$Telnetvalue)= each(%TelnetEntry))
{
while (($SecTime,$SecUser) = each(%SecTime))
{
if ($SecTime < $TelnetTime) # If the time the user logged on is less
than the time that Telnet was started, then do the following:
{
print "\n";
print "The Telnet Service was run by $SecTime{$SecTime}"; #
Prints the user logged on at that time.
print "\n";
print "The time was: ".scalar localtime $TelnetTime; # Prints the
time that Telnet was started. The key and value are the same in this
hash.
print "\n";
}
}
}
I'm pretty sure the problem lies in - if ($SecTime < $TelnetTime) - as
the current result of this code running is that all of the values in
both tables are printing out.
We haven't covered while loops inside while loops in much detail, and
I can't help but think that this problem is so easy that I'm going to
be quite annoyed when it is actually figured out. I know something is
missing!!
Please help... ASAP if possible :)
Cheers
Russ
------------------------------
Date: Tue, 13 Nov 2007 13:11:22 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com.au>
Subject: Re: Processing a while within a while
Message-Id: <_nh_i.12036$CN4.6409@news-server.bigpond.net.au>
<Russell.Mottram@gmail.com> wrote in message
news:1194958447.706382.117260@v23g2000prn.googlegroups.com...
> Hi,
>
> I'm currently studying a relatively basic PERL course, and have an end
> of semester assignment due very soon.
> I've managed to get through everything so far, except I'm now stuck on
> the very last bit, which is printing a comparison between two hashes.
>
> Essentially, the problem is this:
>
> The system log (system.evt) has been searched for Telnet entries, and
> positive matches have been moved into %TelnetEntry.
>
> Then the security log (security.evt) has been searched for users who
> were logged on at the time, excluding Network Service, Local Service,
> and one other random user. Users have been moved into %SecTime.
>
> I now need to iterate through both to determine at the time the Telnet
> service was started, who was logged on?
>
> This is the code I'm working on:
>
> while (($TelnetTime,$Telnetvalue)= each(%TelnetEntry))
> {
> while (($SecTime,$SecUser) = each(%SecTime))
> {
> if ($SecTime < $TelnetTime) # If the time the user logged on is less
> than the time that Telnet was started, then do the following:
> {
> print "\n";
> print "The Telnet Service was run by $SecTime{$SecTime}"; #
> Prints the user logged on at that time.
> print "\n";
> print "The time was: ".scalar localtime $TelnetTime; # Prints the
> time that Telnet was started. The key and value are the same in this
> hash.
> print "\n";
> }
> }
> }
>
> I'm pretty sure the problem lies in - if ($SecTime < $TelnetTime) - as
> the current result of this code running is that all of the values in
> both tables are printing out.
>
> We haven't covered while loops inside while loops in much detail, and
> I can't help but think that this problem is so easy that I'm going to
> be quite annoyed when it is actually figured out. I know something is
> missing!!
>
> Please help... ASAP if possible :)
Do you have an example of what some of the data in those hashes actually
looks like? Without seeing that it is a bit hard to tell. One common
problem is forgetting to chomp entries into one of the hashes so you do a
numeric comparison on a string which isn't what you are really trying to
do... But it could be something else entirely.
P
------------------------------
Date: Tue, 13 Nov 2007 13:37:49 -0000
From: Russell.Mottram@gmail.com
Subject: Re: Processing a while within a while
Message-Id: <1194961069.236004.202710@i13g2000prf.googlegroups.com>
Thanks for replying! I was hoping someone would soon :)
Here is the contents of %TelnetEntry:
11929403381192940338
11917632661191763266
11905538451190553845
11929809061192980906
11924529191192452919
11917583541191758354
11924529301192452930
11905536661190553666
11929792871192979287
11917581701191758170
11905527891190552789
11929533691192953369
11924527891192452789
11929534021192953402
11917579801191757980
11929746761192974676
11930031091193003109
11924529091192452909
11924527951192452795
And here is the contents of %SecTime:
1192658788default
1192571374default
1192950646Sally
1192832626default
1193002890Geoff
1192510043default
1192953674default
1192784691default
1192708778default
1193002332default
1192865201default
1192921241default
1192744166default
1192950649Sally
1192708779default
1193003814default
1192949678default
1192679121default
1192744165default
1192510044default
1192953673default
1192865204default
1192489060default
1192658787default
1192953485Sally
1192950582default
1192950864default
1192397205default
1192888366default
On Nov 14, 12:11 am, "Peter Wyzl" <wyze...@yahoo.com.au> wrote:
> <Russell.Mott...@gmail.com> wrote in message
>
> news:1194958447.706382.117260@v23g2000prn.googlegroups.com...
>
>
>
> > Hi,
>
> > I'm currently studying a relatively basic PERL course, and have an end
> > of semester assignment due very soon.
> > I've managed to get through everything so far, except I'm now stuck on
> > the very last bit, which is printing a comparison between two hashes.
>
> > Essentially, the problem is this:
>
> > The system log (system.evt) has been searched for Telnet entries, and
> > positive matches have been moved into %TelnetEntry.
>
> > Then the security log (security.evt) has been searched for users who
> > were logged on at the time, excluding Network Service, Local Service,
> > and one other random user. Users have been moved into %SecTime.
>
> > I now need to iterate through both to determine at the time the Telnet
> > service was started, who was logged on?
>
> > This is the code I'm working on:
>
> > while (($TelnetTime,$Telnetvalue)= each(%TelnetEntry))
> > {
> > while (($SecTime,$SecUser) = each(%SecTime))
> > {
> > if ($SecTime < $TelnetTime) # If the time the user logged on is less
> > than the time that Telnet was started, then do the following:
> > {
> > print "\n";
> > print "The Telnet Service was run by $SecTime{$SecTime}"; #
> > Prints the user logged on at that time.
> > print "\n";
> > print "The time was: ".scalar localtime $TelnetTime; # Prints the
> > time that Telnet was started. The key and value are the same in this
> > hash.
> > print "\n";
> > }
> > }
> > }
>
> > I'm pretty sure the problem lies in - if ($SecTime < $TelnetTime) - as
> > the current result of this code running is that all of the values in
> > both tables are printing out.
>
> > We haven't covered while loops inside while loops in much detail, and
> > I can't help but think that this problem is so easy that I'm going to
> > be quite annoyed when it is actually figured out. I know something is
> > missing!!
>
> > Please help... ASAP if possible :)
>
> Do you have an example of what some of the data in those hashes actually
> looks like? Without seeing that it is a bit hard to tell. One common
> problem is forgetting to chomp entries into one of the hashes so you do a
> numeric comparison on a string which isn't what you are really trying to
> do... But it could be something else entirely.
>
> P
------------------------------
Date: Tue, 13 Nov 2007 05:39:01 -0800
From: sheinrich@my-deja.com
Subject: Re: Processing a while within a while
Message-Id: <1194961141.563119.179210@50g2000hsm.googlegroups.com>
On Nov 13, 1:54 pm, Russell.Mott...@gmail.com wrote:
...
>
> I'm pretty sure the problem lies in - if ($SecTime < $TelnetTime) - as
> the current result of this code running is that all of the values in
> both tables are printing out.
...
The timestamps from the logs which are usually a human readable
representation must be converted to either system ticks or, more easy,
to a comparable string representation like 'YYYYMMHHSS'.
Both can be taken for numerical comparison, but only the latter for a
string comparison (cmp) which is the default for the sort() function.
Cheers,
Steffen
------------------------------
Date: Tue, 13 Nov 2007 13:40:13 -0000
From: Russell.Mottram@gmail.com
Subject: Re: Processing a while within a while
Message-Id: <1194961213.932356.118240@z24g2000prh.googlegroups.com>
I used this to get the User ID out of the security log file:
$SecUser=substr($securitymessage,33,10);
$SecUser =~ s/\s*$//;
On Nov 14, 12:37 am, Russell.Mott...@gmail.com wrote:
> Thanks for replying! I was hoping someone would soon :)
>
> Here is the contents of %TelnetEntry:
>
> 11929403381192940338
> 11917632661191763266
> 11905538451190553845
> 11929809061192980906
> 11924529191192452919
> 11917583541191758354
> 11924529301192452930
> 11905536661190553666
> 11929792871192979287
> 11917581701191758170
> 11905527891190552789
> 11929533691192953369
> 11924527891192452789
> 11929534021192953402
> 11917579801191757980
> 11929746761192974676
> 11930031091193003109
> 11924529091192452909
> 11924527951192452795
>
> And here is the contents of %SecTime:
>
> 1192658788default
> 1192571374default
> 1192950646Sally
> 1192832626default
> 1193002890Geoff
> 1192510043default
> 1192953674default
> 1192784691default
> 1192708778default
> 1193002332default
> 1192865201default
> 1192921241default
> 1192744166default
> 1192950649Sally
> 1192708779default
> 1193003814default
> 1192949678default
> 1192679121default
> 1192744165default
> 1192510044default
> 1192953673default
> 1192865204default
> 1192489060default
> 1192658787default
> 1192953485Sally
> 1192950582default
> 1192950864default
> 1192397205default
> 1192888366default
> On Nov 14, 12:11 am, "Peter Wyzl" <wyze...@yahoo.com.au> wrote:
>
> > <Russell.Mott...@gmail.com> wrote in message
>
> >news:1194958447.706382.117260@v23g2000prn.googlegroups.com...
>
> > > Hi,
>
> > > I'm currently studying a relatively basic PERL course, and have an end
> > > of semester assignment due very soon.
> > > I've managed to get through everything so far, except I'm now stuck on
> > > the very last bit, which is printing a comparison between two hashes.
>
> > > Essentially, the problem is this:
>
> > > The system log (system.evt) has been searched for Telnet entries, and
> > > positive matches have been moved into %TelnetEntry.
>
> > > Then the security log (security.evt) has been searched for users who
> > > were logged on at the time, excluding Network Service, Local Service,
> > > and one other random user. Users have been moved into %SecTime.
>
> > > I now need to iterate through both to determine at the time the Telnet
> > > service was started, who was logged on?
>
> > > This is the code I'm working on:
>
> > > while (($TelnetTime,$Telnetvalue)= each(%TelnetEntry))
> > > {
> > > while (($SecTime,$SecUser) = each(%SecTime))
> > > {
> > > if ($SecTime < $TelnetTime) # If the time the user logged on is less
> > > than the time that Telnet was started, then do the following:
> > > {
> > > print "\n";
> > > print "The Telnet Service was run by $SecTime{$SecTime}"; #
> > > Prints the user logged on at that time.
> > > print "\n";
> > > print "The time was: ".scalar localtime $TelnetTime; # Prints the
> > > time that Telnet was started. The key and value are the same in this
> > > hash.
> > > print "\n";
> > > }
> > > }
> > > }
>
> > > I'm pretty sure the problem lies in - if ($SecTime < $TelnetTime) - as
> > > the current result of this code running is that all of the values in
> > > both tables are printing out.
>
> > > We haven't covered while loops inside while loops in much detail, and
> > > I can't help but think that this problem is so easy that I'm going to
> > > be quite annoyed when it is actually figured out. I know something is
> > > missing!!
>
> > > Please help... ASAP if possible :)
>
> > Do you have an example of what some of the data in those hashes actually
> > looks like? Without seeing that it is a bit hard to tell. One common
> > problem is forgetting to chomp entries into one of the hashes so you do a
> > numeric comparison on a string which isn't what you are really trying to
> > do... But it could be something else entirely.
>
> > P
------------------------------
Date: Tue, 13 Nov 2007 14:05:19 -0000
From: Russell.Mottram@gmail.com
Subject: Re: Processing a while within a while
Message-Id: <1194962719.269671.153580@q5g2000prf.googlegroups.com>
Hey,
I've been working with the timestamps as whatever the format is called
when it's however many seconds have passed since January 1 1970.
On Nov 14, 12:40 am, Russell.Mott...@gmail.com wrote:
> I used this to get the User ID out of the security log file:
>
> $SecUser=substr($securitymessage,33,10);
> $SecUser =~ s/\s*$//;
>
> On Nov 14, 12:37 am, Russell.Mott...@gmail.com wrote:
>
> > Thanks for replying! I was hoping someone would soon :)
>
> > Here is the contents of %TelnetEntry:
>
> > 11929403381192940338
> > 11917632661191763266
> > 11905538451190553845
> > 11929809061192980906
> > 11924529191192452919
> > 11917583541191758354
> > 11924529301192452930
> > 11905536661190553666
> > 11929792871192979287
> > 11917581701191758170
> > 11905527891190552789
> > 11929533691192953369
> > 11924527891192452789
> > 11929534021192953402
> > 11917579801191757980
> > 11929746761192974676
> > 11930031091193003109
> > 11924529091192452909
> > 11924527951192452795
>
> > And here is the contents of %SecTime:
>
> > 1192658788default
> > 1192571374default
> > 1192950646Sally
> > 1192832626default
> > 1193002890Geoff
> > 1192510043default
> > 1192953674default
> > 1192784691default
> > 1192708778default
> > 1193002332default
> > 1192865201default
> > 1192921241default
> > 1192744166default
> > 1192950649Sally
> > 1192708779default
> > 1193003814default
> > 1192949678default
> > 1192679121default
> > 1192744165default
> > 1192510044default
> > 1192953673default
> > 1192865204default
> > 1192489060default
> > 1192658787default
> > 1192953485Sally
> > 1192950582default
> > 1192950864default
> > 1192397205default
> > 1192888366default
> > On Nov 14, 12:11 am, "Peter Wyzl" <wyze...@yahoo.com.au> wrote:
>
> > > <Russell.Mott...@gmail.com> wrote in message
>
> > >news:1194958447.706382.117260@v23g2000prn.googlegroups.com...
>
> > > > Hi,
>
> > > > I'm currently studying a relatively basic PERL course, and have an end
> > > > of semester assignment due very soon.
> > > > I've managed to get through everything so far, except I'm now stuck on
> > > > the very last bit, which is printing a comparison between two hashes.
>
> > > > Essentially, the problem is this:
>
> > > > The system log (system.evt) has been searched for Telnet entries, and
> > > > positive matches have been moved into %TelnetEntry.
>
> > > > Then the security log (security.evt) has been searched for users who
> > > > were logged on at the time, excluding Network Service, Local Service,
> > > > and one other random user. Users have been moved into %SecTime.
>
> > > > I now need to iterate through both to determine at the time the Telnet
> > > > service was started, who was logged on?
>
> > > > This is the code I'm working on:
>
> > > > while (($TelnetTime,$Telnetvalue)= each(%TelnetEntry))
> > > > {
> > > > while (($SecTime,$SecUser) = each(%SecTime))
> > > > {
> > > > if ($SecTime < $TelnetTime) # If the time the user logged on is less
> > > > than the time that Telnet was started, then do the following:
> > > > {
> > > > print "\n";
> > > > print "The Telnet Service was run by $SecTime{$SecTime}"; #
> > > > Prints the user logged on at that time.
> > > > print "\n";
> > > > print "The time was: ".scalar localtime $TelnetTime; # Prints the
> > > > time that Telnet was started. The key and value are the same in this
> > > > hash.
> > > > print "\n";
> > > > }
> > > > }
> > > > }
>
> > > > I'm pretty sure the problem lies in - if ($SecTime < $TelnetTime) - as
> > > > the current result of this code running is that all of the values in
> > > > both tables are printing out.
>
> > > > We haven't covered while loops inside while loops in much detail, and
> > > > I can't help but think that this problem is so easy that I'm going to
> > > > be quite annoyed when it is actually figured out. I know something is
> > > > missing!!
>
> > > > Please help... ASAP if possible :)
>
> > > Do you have an example of what some of the data in those hashes actually
> > > looks like? Without seeing that it is a bit hard to tell. One common
> > > problem is forgetting to chomp entries into one of the hashes so you do a
> > > numeric comparison on a string which isn't what you are really trying to
> > > do... But it could be something else entirely.
>
> > > P
------------------------------
Date: Tue, 13 Nov 2007 05:14:58 -0800
From: augukarl@yahoo.se
Subject: Regexp substitution with dynamic replacement string
Message-Id: <1194959698.907895.102380@22g2000hsm.googlegroups.com>
Hi everyone,
Let's say, for instance, that I would like to replace each instance of
the letter 'e' in this sentence with a random integer between 0 and 9.
How would I do that? The following does not work obviously:
my $s = 'Let's say, for instance...';
while ($s =~ /e/g) {
$0 = int(rand(10));
}
Regards,
August
------------------------------
Date: Tue, 13 Nov 2007 13:20:09 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Regexp substitution with dynamic replacement string
Message-Id: <871waub7ue.fsf@hacking.dk>
augukarl@yahoo.se writes:
> Let's say, for instance, that I would like to replace each instance of
> the letter 'e' in this sentence with a random integer between 0 and 9.
> How would I do that? The following does not work obviously:
No, but by using the /e-modifier to a substitution you can use the
result of an expression as replacement. Read the parts of 'perldoc
perlop' about s/PATTERN/REPLACEMENT/egimosx
//Makholm
------------------------------
Date: Tue, 13 Nov 2007 05:44:36 -0800
From: augukarl@yahoo.se
Subject: Re: Regexp substitution with dynamic replacement string
Message-Id: <1194961476.661182.200820@k79g2000hse.googlegroups.com>
On 13 Nov, 14:20, Peter Makholm <pe...@makholm.net> wrote:
> auguk...@yahoo.se writes:
> > Let's say, for instance, that I would like to replace each instance of
> > the letter 'e' in this sentence with a random integer between 0 and 9.
> > How would I do that? The following does not work obviously:
>
> No, but by using the /e-modifier to a substitution you can use the
> result of an expression as replacement. Read the parts of 'perldoc
> perlop' about s/PATTERN/REPLACEMENT/egimosx
Ah, thanks! Works like a charm.
August
------------------------------
Date: Tue, 13 Nov 2007 05:59:27 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: replace string contaning \n
Message-Id: <slrnfjj4cv.ji0.tadmc@tadmc30.sbcglobal.net>
cieux87-fin@yahoo.com <cieux87-fin@yahoo.com> wrote:
> I try to change the string \nE by # E without success.
>
> $line=~ s/(\n\E/#E/g;
That does not even compile.
Two pieces of information are needed to evaluate the behavior
of a pattern match, the pattern and the string that it is
trying to match against.
We need to see the contents of $line.
Your choice of variable name implies that the answer is
given in the Perl FAQ:
perldoc -q match
I'm having trouble matching over more than one line. What's wrong?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
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 1029
***************************************