[30204] in Perl-Users-Digest
Perl-Users Digest, Issue: 1447 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 15 16:15:49 2008
Date: Tue, 15 Apr 2008 13:15:38 -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 Tue, 15 Apr 2008 Volume: 11 Number: 1447
Today's topics:
Print a separator between each iteration of a foreach l <sjackman@gmail.com>
Re: Print a separator between each iteration of a forea <jurgenex@hotmail.com>
Re: Print a separator between each iteration of a forea xhoster@gmail.com
Re: Print a separator between each iteration of a forea <willem@stack.nl>
Re: Print a separator between each iteration of a forea <smallpond@juno.com>
Re: Print a separator between each iteration of a forea <sjackman@gmail.com>
Re: Print a separator between each iteration of a forea <uri@stemsystems.com>
Re: Print a separator between each iteration of a forea <uri@stemsystems.com>
Re: Print a separator between each iteration of a forea <ben@morrow.me.uk>
Re: problem using system() <benkasminbullock@gmail.com>
Proposal for a new group <jjcassidy@gmail.com>
Quality of rand() <source@netcom.com>
Re: Quality of rand() xhoster@gmail.com
Re: Quality of rand() <smallpond@juno.com>
Re: Quality of rand() <reply_in_group@mouse-potato.com>
Re: Quality of rand() <abigail@abigail.be>
Re: Quality of rand() <source@netcom.com>
Re: Quality of rand() <nospam-abuse@ilyaz.org>
Re: RE Perl Pattern matching <m@rtij.nl.invlalid>
s replace p modifier <loreleunoeg@gmx.net>
Re: s replace p modifier <1usa@llenroc.ude.invalid>
Re: s replace p modifier <tadmc@seesig.invalid>
Re: s replace p modifier <szrRE@szromanMO.comVE>
Re: s replace p modifier <abigail@abigail.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Apr 2008 10:24:59 -0700 (PDT)
From: ShaunJ <sjackman@gmail.com>
Subject: Print a separator between each iteration of a foreach loop
Message-Id: <55081448-ccdf-44ea-b819-cfba5d7b4e27@w8g2000prd.googlegroups.com>
I want to print a separator between each iteration of a foreach loop,
but not after the last element. How do I avoid printing the last
extraneous comma in the following code snippet?
foreach (@ARGV) {
print $_, ',';
}
print "\n";
In this simple example join ',' would suffice, but the real body of
the foreach loop is more complicated. What I want to do is something
like this:
foreach (@ARGV) {
print $_;
print ',' unless last_element;
}
print "\n";
Thanks,
Shaun
------------------------------
Date: Tue, 15 Apr 2008 17:40:13 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <mqp904pb73mdh7tor2ib6d9v3r4au6fpkr@4ax.com>
ShaunJ <sjackman@gmail.com> wrote:
>I want to print a separator between each iteration of a foreach loop,
>but not after the last element.
That's a standard problem in CS. You need to process the first or last
element outside the loop.
> How do I avoid printing the last
>extraneous comma in the following code snippet?
>[...] What I want to do is something like this:
>
>foreach (@ARGV) {
> print $_;
> print ',' unless last_element;
>}
>print "\n";
print $ARGV[0]; shift @ARGV
for (@ARGV) {
print ',';
print $_;
}
OR
for (@ARGV[0..@ARGV-2]) {
print $_;
print ',';
}
print $ARGV[$#ARGV];
jue
------------------------------
Date: 15 Apr 2008 17:44:17 GMT
From: xhoster@gmail.com
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <20080415134419.181$43@newsreader.com>
ShaunJ <sjackman@gmail.com> wrote:
> I want to print a separator between each iteration of a foreach loop,
> but not after the last element. How do I avoid printing the last
> extraneous comma in the following code snippet?
>
> foreach (@ARGV) {
> print $_, ',';
> }
> print "\n";
>
> In this simple example join ',' would suffice, but the real body of
> the foreach loop is more complicated.
Unless it is huge, you could just change the print to be push @results, $_;
and then do the join on @results.
> What I want to do is something
> like this:
>
> foreach (@ARGV) {
> print $_;
> print ',' unless last_element;
> }
> print "\n";
I don't think there is a clean way to do it with a foreach loop. You
could use a counter, but if you are going to do that I'd just as soon
change to a C style loop:
for (my $i=0; $i<=$#ARGV; $i++) {
print $ARGV[$i];
print "," unless $i==$#ARGV;
};
But actually, I might go for:
for (my $i=0; $i<@ARGV; $i++) {
print "," unless $i==0;
print $ARGV[$i];
};
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 15 Apr 2008 17:47:24 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <slrng09qhc.1aud.willem@snail.stack.nl>
ShaunJ wrote:
) I want to print a separator between each iteration of a foreach loop,
) but not after the last element. How do I avoid printing the last
) extraneous comma in the following code snippet?
)
) foreach (@ARGV) {
) print $_, ',';
) }
) print "\n";
)
) In this simple example join ',' would suffice, but the real body of
) the foreach loop is more complicated. What I want to do is something
) like this:
)
) foreach (@ARGV) {
) print $_;
) print ',' unless last_element;
) }
) print "\n";
One sometimes-seen useful trick is this:
my $sep = '';
foreach (@ARGV) {
print $sep; $sep = ',';
print $_;
}
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Tue, 15 Apr 2008 10:48:55 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <88644e98-5991-492e-9231-97dd4d78cdce@s33g2000pri.googlegroups.com>
On Apr 15, 1:24 pm, ShaunJ <sjack...@gmail.com> wrote:
> I want to print a separator between each iteration of a foreach loop,
> but not after the last element. How do I avoid printing the last
> extraneous comma in the following code snippet?
>
> foreach (@ARGV) {
> print $_, ',';}
>
> print "\n";
>
> In this simple example join ',' would suffice, but the real body of
> the foreach loop is more complicated. What I want to do is something
> like this:
>
> foreach (@ARGV) {
> print $_;
> print ',' unless last_element;}
>
> print "\n";
>
> Thanks,
> Shaun
my $notlast = $#ARGV;
foreach (@ARGV) {
print $_;
last unless $notlast;
$notlast--;
print ',';
}
------------------------------
Date: Tue, 15 Apr 2008 11:00:16 -0700 (PDT)
From: ShaunJ <sjackman@gmail.com>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <8ef1cfac-78b4-49bb-a4df-5d48dbde8f16@1g2000prg.googlegroups.com>
On Apr 15, 10:36 am, Frank Seitz <devnull4...@web.de> wrote:
> ShaunJ wrote:
> > foreach (@ARGV) {
> > print $_;
> > print ',' unless last_element;
>
> ^^^^^^^^^^^^
> \$_ eq \$ARGV[-1]
>
> > }
> > print "\n";
That works. Thanks, Frank!
This problem is common enough that it almost warrants special syntax,
similar to the contine block.
foreach (@_) {
print $_;
} separator {
print ',';
}
Not a serious proposal, just a "wouldn't it be nice if".
Cheers,
Shaun
------------------------------
Date: Tue, 15 Apr 2008 18:11:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <x7od8b56pz.fsf@mail.sysarch.com>
>>>>> "W" == Willem <willem@stack.nl> writes:
W> One sometimes-seen useful trick is this:
W> my $sep = '';
W> foreach (@ARGV) {
W> print $sep; $sep = ',';
minor optimization which works but is data dependent:
print $sep;
$sep ||= ',';
W> print $_;
and $_ is the default for print (as it is for many other funcs ).
and if it is really just the argv array, join has to be better. the
array would have to be slightly oversized to make join slow down.
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: Tue, 15 Apr 2008 18:13:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <x7k5iz56ma.fsf@mail.sysarch.com>
>>>>> "S" == ShaunJ <sjackman@gmail.com> writes:
S> On Apr 15, 10:36 am, Frank Seitz <devnull4...@web.de> wrote:
>> ShaunJ wrote:
>> > foreach (@ARGV) {
>> > print $_;
>> > print ',' unless last_element;
>>
>> ^^^^^^^^^^^^
>> \$_ eq \$ARGV[-1]
>>
>> > }
>> > print "\n";
S> That works. Thanks, Frank!
S> This problem is common enough that it almost warrants special syntax,
S> similar to the contine block.
S> foreach (@_) {
S> print $_;
S> } separator {
S> print ',';
S> }
S> Not a serious proposal, just a "wouldn't it be nice if".
perl6 has those flow control blocks. there is FIRST, LAST, BEGIN and a
bunch of others (all upper case names) that trap conditions/exceptions
inside their outer blocks.
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: Tue, 15 Apr 2008 19:31:59 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <vt8fd5-9ub.ln1@osiris.mauzo.dyndns.org>
Quoth xhoster@gmail.com:
> ShaunJ <sjackman@gmail.com> wrote:
> > I want to print a separator between each iteration of a foreach loop,
> > but not after the last element. How do I avoid printing the last
> > extraneous comma in the following code snippet?
> >
> > foreach (@ARGV) {
> > print $_, ',';
> > }
> > print "\n";
> >
> > In this simple example join ',' would suffice, but the real body of
> > the foreach loop is more complicated.
>
> Unless it is huge, you could just change the print to be push @results, $_;
> and then do the join on @results.
print join ',', map {...} @ARGV; is cleaner than pushing onto an
intermediate array. Or you can set $, and $\ and avoid the join and "\n"
altogether.
Ben
------------------------------
Date: Wed, 9 Apr 2008 22:22:04 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: problem using system()
Message-Id: <ftjfic$1s1$1@ml.accsnet.ne.jp>
On Wed, 09 Apr 2008 10:21:14 -0500, J. Gleixner wrote:
> mike wrote:
>> my @args = ($User_Preferences{asadminexecutable}, 'deploy', "--user=
>> $User_Preferences{user}","--passwordfile=
>> $User_Preferences{passwordfile}","--host=$User_Preferences{host}","--
>> port=$User_Preferences{port}","$User_Preferences{pathdeployunit}");
> Could also make that easier to read:
> my @args = (
> $User_Preferences{asadminexecutable}, 'deploy',
> "--user=$User_Preferences{user}",
> "--passwordfile=$User_Preferences{passwordfile}",
> "--host=$User_Preferences{host}",
> "--port=$User_Preferences{port}",
> "$User_Preferences{pathdeployunit}",
> );
my @jazz = qw/user passwordfile host port/;
my @args = ($User_Preferences{asadminexecutable},
'deploy',
(map "--$_=$User_Preferences{$_}", @jazz),
$User_Preferences{pathdeployunit},
);
------------------------------
Date: Thu, 10 Apr 2008 23:23:47 -0700 (PDT)
From: A Dude <jjcassidy@gmail.com>
Subject: Proposal for a new group
Message-Id: <8de43b19-8c7c-4c5f-b16c-3a321d60ef68@k37g2000hsf.googlegroups.com>
comp.lang.perl.stupid.stupid.stupid.flamewar.over.the.nameofperl
Did I mention stupid?
------------------------------
Date: Fri, 11 Apr 2008 10:44:25 -0700
From: David Harmon <source@netcom.com>
Subject: Quality of rand()
Message-Id: <x9mdnRoKurggPmLanZ2dnUVZ_smnnZ2d@earthlink.com>
Elsewhere I saw someone making an argument and using a Perl program
to support it, one in which he calls rand() in a loop 2000000 times.
Now, in my native C, rand() typically falls apart statistically long
before that many iterations. Is there any guarantee in Perl on the
randomness and/or length of the period of rand?
"perldoc -f rand" doesn't tell.
------------------------------
Date: 11 Apr 2008 18:15:34 GMT
From: xhoster@gmail.com
Subject: Re: Quality of rand()
Message-Id: <20080411141536.213$fl@newsreader.com>
"Newsgroup only please, address is no longer replyable."
<bad@example.invalid> wrote:
> Elsewhere I saw someone making an argument and using a Perl program
> to support it, one in which he calls rand() in a loop 2000000 times.
And then what? We can't critique the argument if we don't know what it is.
> Now, in my native C,
I don't have a native C. I doubt you do either. Your computer might.
If your computer's native C has crappy random number generators, I suspect
your perl will inherit that crappiness.
> rand() typically falls apart statistically long
> before that many iterations.
All psuedorandom number generators will fall about if your statistical
criteria are stringent enough and you are willing to spend enough time
finding the problem. So it is kind of meaningless to say that without
specifying exactly what type of falling apart you are looking for.
> Is there any guarantee in Perl on the
> randomness and/or length of the period of rand?
> "perldoc -f rand" doesn't tell.
I don't think perl makes any guarantees about anything.
By running ltrace on a simple program, I see that my perl calls drand48
to get its random numbers. Therefore, it inherits the same limitations as
discussed in "man drand48". I find this good enough, but if you don't
there are modules for Perl that try to give you cryptographic strength
random numbers. I suspect they are God-awful slow.
perl -le 'foreach(1..2e6) {die if $h{rand()}++}'
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Fri, 11 Apr 2008 14:04:19 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Quality of rand()
Message-Id: <45f278f2-ea71-4bef-b80b-1b4856650c65@m44g2000hsc.googlegroups.com>
On Apr 11, 1:44 pm, David Harmon <sou...@netcom.com> wrote:
> Elsewhere I saw someone making an argument and using a Perl program
> to support it, one in which he calls rand() in a loop 2000000 times.
> Now, in my native C, rand() typically falls apart statistically long
> before that many iterations. Is there any guarantee in Perl on the
> randomness and/or length of the period of rand?
> "perldoc -f rand" doesn't tell.
If you don't want to use a PRNG, use Crypt::Random.
------------------------------
Date: Fri, 11 Apr 2008 19:43:00 -0700
From: Tim Smith <reply_in_group@mouse-potato.com>
Subject: Re: Quality of rand()
Message-Id: <reply_in_group-67492E.19430011042008@news.supernews.com>
In article
<45f278f2-ea71-4bef-b80b-1b4856650c65@m44g2000hsc.googlegroups.com>,
smallpond <smallpond@juno.com> wrote:
>
> If you don't want to use a PRNG, use Crypt::Random.
If the documentation on CPAN is right, that uses /dev/random. On some
Unix systems, /dev/random is a PRNG. E.g., on FreeBSD, /dev/random uses
the Yarrow PRNG. (Same for OS X).
--
--Tim Smith
------------------------------
Date: 12 Apr 2008 10:55:43 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Quality of rand()
Message-Id: <slrng0159f.fs.abigail@alexandra.abigail.be>
_
xhoster@gmail.com (xhoster@gmail.com) wrote on VCCCXXXVII September
MCMXCIII in <URL:news:20080411141536.213$fl@newsreader.com>:
~~ "Newsgroup only please, address is no longer replyable."
~~ <bad@example.invalid> wrote:
~~ > Elsewhere I saw someone making an argument and using a Perl program
~~ > to support it, one in which he calls rand() in a loop 2000000 times.
~~
~~ And then what? We can't critique the argument if we don't know what it is.
~~
~~ > Now, in my native C,
~~
~~ I don't have a native C. I doubt you do either. Your computer might.
~~ If your computer's native C has crappy random number generators, I suspect
~~ your perl will inherit that crappiness.
~~
~~ > rand() typically falls apart statistically long
~~ > before that many iterations.
~~
~~ All psuedorandom number generators will fall about if your statistical
~~ criteria are stringent enough and you are willing to spend enough time
~~ finding the problem. So it is kind of meaningless to say that without
~~ specifying exactly what type of falling apart you are looking for.
~~
~~ > Is there any guarantee in Perl on the
~~ > randomness and/or length of the period of rand?
~~ > "perldoc -f rand" doesn't tell.
~~
~~ I don't think perl makes any guarantees about anything.
~~
~~ By running ltrace on a simple program, I see that my perl calls drand48
~~ to get its random numbers. Therefore, it inherits the same limitations as
~~ discussed in "man drand48". I find this good enough, but if you don't
~~ there are modules for Perl that try to give you cryptographic strength
~~ random numbers. I suspect they are God-awful slow.
To see what function Perl uses for random numbers:
perl -MConfig -E 'say $Config::Config {randfunc}'
For its number of bits:
perl -MConfig -E 'say $Config::Config {randbits}'
Abigail
~~
~~ perl -le 'foreach(1..2e6) {die if $h{rand()}++}'
~~
~~ Xho
~~
--
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:
------------------------------
Date: Mon, 14 Apr 2008 11:36:47 -0700
From: David Harmon <source@netcom.com>
Subject: Re: Quality of rand()
Message-Id: <jIGdnWrX6vSiOZ7VnZ2dnUVZ_tTinZ2d@earthlink.com>
On 12 Apr 2008 10:55:43 GMT in comp.lang.perl.misc, Abigail
<abigail@abigail.be> wrote,
>To see what function Perl uses for random numbers:
>
> perl -MConfig -E 'say $Config::Config {randfunc}'
>
>For its number of bits:
>
> perl -MConfig -E 'say $Config::Config {randbits}'
Thanks, Abigail; that is very helpful.
After fixing minor syntax errors, I get:
C:\USR\perl>perl -MConfig -e "print $Config::Config {randfunc}"
rand
C:\USR\perl>perl -MConfig -e "print $Config::Config {randbits}"
15
------------------------------
Date: Mon, 14 Apr 2008 19:39:43 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Quality of rand()
Message-Id: <fu0btv$20l7$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Abigail
<abigail@abigail.be>], who wrote in article <slrng0159f.fs.abigail@alexandra.abigail.be>:
> To see what function Perl uses for random numbers:
>
> perl -MConfig -E 'say $Config::Config {randfunc}'
>
> For its number of bits:
>
> perl -MConfig -E 'say $Config::Config {randbits}'
Most probably, Abigail meant
perl -V:"randfunc|randbits"
One can do
perl -V:".*rand.*"
but it also will get some "detected pre-build" stuff which is not
actually used by perl; so it is better to see "randfunc|randbits"
first.
Hope this helps,
Ilya
------------------------------
Date: Wed, 9 Apr 2008 23:40:16 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: RE Perl Pattern matching
Message-Id: <pan.2008.04.09.21.40.15@rtij.nl.invlalid>
On Wed, 02 Apr 2008 22:16:09 +0000, Ben Bullock wrote:
> On Wed, 02 Apr 2008 10:53:34 -0500, Chris Mattern wrote:
>
>
>> You're trying to parse XML with regular expressions. Don't do that.
>> Perl has a large selection of excellent modules for processing XML. Use
>> them.
>
> Chris, do you talk like that to people in real life, or is it just the
> internet?
I do. Even (especially?) if someone is new around here and is making a
mistake thousands have made before.
M4
------------------------------
Date: Tue, 15 Apr 2008 01:13:05 +0200
From: "Lore Leunoeg" <loreleunoeg@gmx.net>
Subject: s replace p modifier
Message-Id: <fu0o1b$vt0$1@news01.versatel.de>
Hello
I'd like to encapsulate each number in a textfile with dollar-signs ($). I
thougt to replace each number by a $-sign followed by the pattern matched
number itself and another $-sign.
How can I get the exact pattern which was replaced by
s/PATTERN/PREPLACEMENT/modifier?
In the perl docs I read that the p preserve modifier would save the replaced
pattern in a variable $<^MATCH>. But the p modifier isn't known by my perl
installation (vers5.8).
Does anybody know another way to solve the encapsulation problem? Or does
anyone can give me a hint why the p modifier isn't known?
Thank you
Sincerely
Lore
------------------------------
Date: Mon, 14 Apr 2008 23:13:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: s replace p modifier
Message-Id: <Xns9A80C38188716asu1cornelledu@127.0.0.1>
"Lore Leunoeg" <loreleunoeg@gmx.net> wrote in
news:fu0o1b$vt0$1@news01.versatel.de:
> I'd like to encapsulate each number in a textfile with
> dollar-signs ($). I thougt to replace each number by a $-sign
> followed by the pattern matched number itself and another $-sign.
OK, stop here. The rest of your post is extremely confusing to me
because I cannot see why you would need the p modifier.
#!/usr/bin/perl
use strict;
use warnings;
while ( <DATA> ) {
s/(\d+)/\$$1\$/g;
print "$_\n";
}
__DATA__
a 1 2 3
b 2 3 4
c 3 4 g
d 4 h i
e 5 9 a
> Does anybody know another way to solve the encapsulation problem?
I don't know what *the* encapsulation problem is.
> Or does anyone can give me a hint why the p modifier isn't known?
Because you don't have perl 5.10.
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: Mon, 14 Apr 2008 19:44:12 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: s replace p modifier
Message-Id: <slrng07uis.rdq.tadmc@tadmc30.sbcglobal.net>
Lore Leunoeg <loreleunoeg@gmx.net> wrote:
> Hello
>
> I'd like to encapsulate each number in a textfile with dollar-signs ($). I
> thougt to replace each number by a $-sign followed by the pattern matched
> number itself and another $-sign.
That's a very good thought.
> How can I get the exact pattern which was replaced by
> s/PATTERN/PREPLACEMENT/modifier?
[ Please copy/paste code rather than (attempt to) retype it. ]
By enclosing the PATTERN in parenthesis and using the $1 variable
in the REPLACEMENT part.
> In the perl docs I read that the p preserve modifier would save the replaced
> pattern in a variable $<^MATCH>. But the p modifier isn't known by my perl
> installation (vers5.8).
You should not read random Perl docs from the web.
You should read the Perl docs that *came with* your perl distribution.
They are already on your disk somewhere. Find out where.
> Does anybody know another way to solve the encapsulation problem? Or does
> anyone can give me a hint why the p modifier isn't known?
You were reading docs that did not apply to the software
that you currently have available.
That can never happen if you read the docs that came with the
software that you currently have available.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 14 Apr 2008 20:24:51 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: s replace p modifier
Message-Id: <fu176302v46@news2.newsguy.com>
Tad J McClellan wrote:
> Lore Leunoeg <loreleunoeg@gmx.net> wrote:
>> Hello
>>
>> I'd like to encapsulate each number in a textfile with dollar-signs
>> ($). I thougt to replace each number by a $-sign followed by the
>> pattern matched number itself and another $-sign.
>
>
> That's a very good thought.
>
>
>> How can I get the exact pattern which was replaced by
>> s/PATTERN/PREPLACEMENT/modifier?
>
>
> [ Please copy/paste code rather than (attempt to) retype it. ]
>
>
> By enclosing the PATTERN in parenthesis and using the $1 variable
> in the REPLACEMENT part.
>
>
>> In the perl docs I read that the p preserve modifier would save the
>> replaced pattern in a variable $<^MATCH>. But the p modifier isn't
>> known by my perl installation (vers5.8).
>
>
> You should not read random Perl docs from the web.
>
> You should read the Perl docs that *came with* your perl distribution.
>
> They are already on your disk somewhere. Find out where.
>
>
>> Does anybody know another way to solve the encapsulation problem? Or
>> does anyone can give me a hint why the p modifier isn't known?
>
>
> You were reading docs that did not apply to the software
> that you currently have available.
>
> That can never happen if you read the docs that came with the
> software that you currently have available.
True enough, though it is possible to read the wrong documents if one's
system has multiple installs (for instance, one that came bundled with
your system and one and compiled by hand afterwards), and also some
people use systems they did not set up (i.e., in a work place
environment.)
If in doubt, invoke perldoc by absolute path.
For example, I my own system, I have 5.10.0 and 5.8.8 installed in
/usr/local/ perl5.8.8 and perl5.10.0 and have symlinked binaries from
each (perl, perldoc, etc) as /usr/local/bin perl5.8.8 and perldoc5.8.8
and similar for 5.10.0, respectively, that way I am always sure of which
one I am invoking (though I use 5.10.0 as my primary Perl now... perl
and perldoc are too symlinked to 5.10.0's binaries.)
--
szr
------------------------------
Date: 15 Apr 2008 08:53:14 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: s replace p modifier
Message-Id: <slrng08r7p.ak2.abigail@alexandra.abigail.be>
_
Lore Leunoeg (loreleunoeg@gmx.net) wrote on VCCCXL September MCMXCIII in
<URL:news:fu0o1b$vt0$1@news01.versatel.de>:
-- Hello
--
-- I'd like to encapsulate each number in a textfile with dollar-signs ($). I
-- thougt to replace each number by a $-sign followed by the pattern matched
-- number itself and another $-sign.
--
-- How can I get the exact pattern which was replaced by
-- s/PATTERN/PREPLACEMENT/modifier?
-- In the perl docs I read that the p preserve modifier would save the replaced
-- pattern in a variable $<^MATCH>. But the p modifier isn't known by my perl
-- installation (vers5.8).
It really would help if you used the documentation that comes with your Perl.
None of the 5.8 versions will document the /p modifier. It wasn't documented
until perl 5.10, which does know the /p modifier.
But it doesn't say $<^MATCH>. The variable is called ${^MATCH}.
-- Does anybody know another way to solve the encapsulation problem? Or does
-- anyone can give me a hint why the p modifier isn't known?
No need for /p and ${^MATCH}. The following ought to do (not tested):
s/([0-9]+)/\$$1\$/g;
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
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 1447
***************************************