[29087] in Perl-Users-Digest
Perl-Users Digest, Issue: 331 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 13 09:09:51 2007
Date: Fri, 13 Apr 2007 06:09:08 -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 Fri, 13 Apr 2007 Volume: 11 Number: 331
Today's topics:
Re: Absolute Path errors <nikos1337@gmail.com>
Re: Absolute Path errors <nikos1337@gmail.com>
Can anyone see why this skips the remaining username/pa <nospam@home.com>
Re: Can anyone see why this skips the remaining usernam <tadmc@augustmail.com>
Re: Can anyone see why this skips the remaining usernam <nospam@home.com>
Re: Can anyone see why this skips the remaining usernam <mritty@gmail.com>
Re: Can anyone see why this skips the remaining usernam <mritty@gmail.com>
Extracting text between two market lines. (FAQ variatio <scobloke2@infotop.co.uk>
Re: Extracting text between two market lines. (FAQ vari anno4000@radom.zrz.tu-berlin.de
Re: Extracting text between two market lines. (FAQ vari <abigail@abigail.be>
How to change decimal point ',' to decimal comma ',' <pero@pero.pero>
Re: How to change decimal point ',' to decimal comma ', <rprp@gmx.net>
Re: How to change decimal point ',' to decimal comma ', <stoupa@practisoft.cz>
Re: How to change decimal point ',' to decimal comma ', <josef.moellers@fujitsu-siemens.com>
Re: How to change decimal point ',' to decimal comma ', <wahab-mail@gmx.de>
Re: My Perl Ode to Purl Gurl <tadmc@augustmail.com>
Re: My Perl Ode to Purl Gurl <clarke@n_o_s_p_a_m_hyperformix.com>
Re: perl regular expression kiranmn@my-deja.com
Re: perl regular expression <spamtrap@dot-app.org>
Re: perl regular expression <thepoet_nospam@arcor.de>
Re: perl regular expression <thepoet_nospam@arcor.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Apr 2007 02:00:24 -0700
From: "skieros" <nikos1337@gmail.com>
Subject: Re: Absolute Path errors
Message-Id: <1176454823.960015.183080@y5g2000hsa.googlegroups.com>
=CF/=C7 Michele Dondi =DD=E3=F1=E1=F8=E5:
> One last (really, eh!) try: it's Perl, not apache that does the
> open()s and previously by a pure chance the relative urls were
> corresponding to the correct relative paths. But generally this is in
> fact a circumstance.
Yes it is Perl that handle the open() requests as by its turn it gives
the open() requests to OS to control and handle
but its Apache that locates its files(only locates and handle links)
that is in fact residing to a subdir of the webserver's DocumentRoot.
So although the path were relative Apache can locate them and Perl
open() them with the use of the OS. No?!
If you want tou can answer, i know i tired you with this matter.....
------------------------------
Date: 13 Apr 2007 02:03:54 -0700
From: "skieros" <nikos1337@gmail.com>
Subject: Re: Absolute Path errors
Message-Id: <1176455033.993282.137700@w1g2000hsg.googlegroups.com>
=CE=9F/=CE=97 Jos=C3=A9 Luis P=C3=A9rez Diez =CE=AD=CE=B3=CF=81=CE=B1=CF=88=
=CE=B5:
> What happens in both cases can be known if index.pl informs of it's
> current work directory
Yes, maybe...
Because i cannot else explain how Apache could locate all files for
opening with the redirection method and after removed the redirection
it couldnt.....
If it could in the first place it can locate them and i can use them
with relative apth only.
------------------------------
Date: Fri, 13 Apr 2007 10:19:44 GMT
From: "Nospam" <nospam@home.com>
Subject: Can anyone see why this skips the remaining username/pass hash elements
Message-Id: <4PITh.35$M_3.29@newsfe1-gui.ntli.net>
The below code only runs the first username/password combination in the
program, but goes through the motions for the second and third, just
printing out the urls, and not using the username and passwords:
use strict;
use WWW::Mechanize;
use HTML::TokeParser::Simple;
use Text::CSV;
use LWP::Useragent;
use LWP::Debug;
my %names = qw(
1 => 'user1@example.com',
2 => 'user2@example.com',
3 => 'user3@example.com');
my $number;
my $email1;
while(($number, $email1) = each(%names))
{
my $username = "$email1";
my $password = 'password';
my $file = 'file.txt';
my $csv = Text::CSV->new();
open (CSV, "<", $file) or die $!;
open (textFile, ">user.csv");
my $agent = WWW::Mechanize->new();
my $tag;
my $urlWithuserID;
my $userIdToAdd;
my $whereToSplit;
my %array;
my $key;
my $value;
my $i;
my $sleepTime = 7;
my $openLink;
$agent->get("http://www.example.com");
$agent->form_name("theForm");
$agent->field( "email", $username);
$agent->field( "password", $password );
$agent->click('login');
print textFile $agent->{content};
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
foreach (@columns){
$agent->get("@columns[0]");
if ($agent->success()) {
print "\nGetting info for @columns[0]\n";
my $stream = HTML::TokeParser::Simple->new(\$agent->{content});
while ($tag = $stream->get_tag("a")){
$_ = $tag->get_attr("href");
if ( /user[iI][dD]/ ){
$urlWithuserID = $_;
$whereToSplit = rindex($urlWithuserID, "=") + 1;
$userIdToAdd = substr($urlWithuserID, $whereToSplit);
createPair($userIdToAdd, "0");
}
}
while (($key, $value) = each %array) {
$agent->get("http://www.example.com");
if ($agent->success()) {
print "Adding user $key...";
$agent->form("adduser");
$agent->submit();
$_ = $agent->{content};
if ( /news.added/ ){
print "success\n";
sleep $sleepTime;
}
else{
print "No news ";
}
}
delete($array{$key});
};
}
else {
print "$agent->{content};"
}
$i++;
}
}
}
sub createPair{
my($key, $value) = @_ ;
$array{$key} = $value;
};
}
------------------------------
Date: Fri, 13 Apr 2007 06:58:32 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can anyone see why this skips the remaining username/pass hash elements
Message-Id: <slrnf1us38.omf.tadmc@tadmc30.august.net>
Nospam <nospam@home.com> wrote:
> my %names = qw(
^^
^^
> 1 => 'user1@example.com',
> 2 => 'user2@example.com',
> 3 => 'user3@example.com');
You should always enable warnings when developing Perl code!
> my $username = "$email1";
perldoc -q vars
What’s wrong with always quoting "$vars"?
> open (CSV, "<", $file) or die $!;
You check the return value from open. Good.
> open (textFile, ">user.csv");
You do not check the return value from open. Bad.
> $_ = $agent->{content};
You should use the accessor method to access the content:
$_ = $agent->content;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 13 Apr 2007 12:10:53 GMT
From: "Nospam" <nospam@home.com>
Subject: Re: Can anyone see why this skips the remaining username/pass hash elements
Message-Id: <hrKTh.45$7D4.10@newsfe6-win.ntli.net>
With the amendments I am still getting the same problem, it just skips over
the other username/password elements in the hash not running them through
the program, saying it's "getting info..." but the program is not run,
except for the first username/password combination of the hash:
use strict;
use WWW::Mechanize;
use HTML::TokeParser::Simple;
use Text::CSV;
use LWP::Useragent;
use LWP::Debug;
my %names = (
1 => 'user1@example.com',
2 => 'user2@example.com',
3 => 'user3@example.com');
my $number;
my $email1;
while(($number, $email1) = each(%names))
{
my $username = $email1;
my $password = 'password';
my $file = 'file.txt';
my $csv = Text::CSV->new();
open (CSV, "<", $file) or die $!;
open (textFile, ">user.csv") or die $!;
my $agent = WWW::Mechanize->new();
my $tag;
my $urlWithuserID;
my $userIdToAdd;
my $whereToSplit;
my %array;
my $key;
my $value;
my $i;
my $sleepTime = 7;
my $openLink;
$agent->get("http://www.example.com");
$agent->form_name("theForm");
$agent->field( "email", $username);
$agent->field( "password", $password );
$agent->click('login');
print textFile $agent->content;
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
foreach (@columns){
$agent->get("@columns[0]");
if ($agent->success()) {
print "\nGetting info for @columns[0]\n";
my $stream = HTML::TokeParser::Simple->new(\$agent->content);
while ($tag = $stream->get_tag("a")){
$_ = $tag->get_attr("href");
if ( /user[iI][dD]/ ){
$urlWithuserID = $_;
$whereToSplit = rindex($urlWithuserID, "=") + 1;
$userIdToAdd = substr($urlWithuserID, $whereToSplit);
createPair($userIdToAdd, "0");
}
}
while (($key, $value) = each %array) {
$agent->get("http://www.example.com");
if ($agent->success()) {
print "Adding user $key...";
$agent->form("adduser");
$agent->submit();
$_ = $agent->content;
if ( /news.added/ ){
print "success\n";
sleep $sleepTime;
}
else{
print "No news ";
}
}
delete($array{$key});
};
}
else {
print "$agent->content;"
}
$i++;
}
}
}
sub createPair{
my($key, $value) = @_ ;
$array{$key} = $value;
};
}
------------------------------
Date: 13 Apr 2007 05:34:36 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Can anyone see why this skips the remaining username/pass hash elements
Message-Id: <1176467676.855893.320550@q75g2000hsh.googlegroups.com>
On Apr 13, 8:10 am, "Nospam" <nos...@home.com> wrote:
> With the amendments
You mean, all except "always enable warnings when developing Perl
code", I assume. Why would you ignore that piece of advice?
> I am still getting the same problem, it just skips over
> the other username/password elements in the hash not running them
> through the program, saying it's "getting info..."
This sentence is contradictory. You're saying the program "isn't
running", yet it is printing out the getting info line. So then what
"isn't running"? Please provide exact output, rather than making us
guess what the heck you're talking about.
> but the program is not run,
That's a flat out lie. If it's not run, it couldn't produce any
output. You may know exactly what you mean. I, however, have no way
of knowing.
> except for the first username/password combination of the hash:
>
> while (<CSV>) {
> if ($csv->parse($_)) {
> my @columns = $csv->fields();
> foreach (@columns){
>
> $agent->get("@columns[0]");
Is that seriously what you meant to do? For each column, you want to
get just the first column?
> if ($agent->success()) {
>
> print "\nGetting info for @columns[0]\n";
>
> my $stream = HTML::TokeParser::Simple->new(\$agent->content);
> while ($tag = $stream->get_tag("a")){
> $_ = $tag->get_attr("href");
> if ( /user[iI][dD]/ ){
> $urlWithuserID = $_;
> $whereToSplit = rindex($urlWithuserID, "=") + 1;
> $userIdToAdd = substr($urlWithuserID, $whereToSplit);
> createPair($userIdToAdd, "0");
> }
> }
>
> while (($key, $value) = each %array) {
> $agent->get("http://www.example.com");
>
> if ($agent->success()) {
> print "Adding user $key...";
> $agent->form("adduser");
> $agent->submit();
>
> $_ = $agent->content;
> if ( /news.added/ ){
> print "success\n";
> sleep $sleepTime;
> }
> else{
> print "No news ";
> }
> }
> delete($array{$key});
> };
> }
> else {
> print "$agent->content;"
> }
> $i++;
>
> }
> }
>
> }
>
> sub createPair{
>
> my($key, $value) = @_ ;
> $array{$key} = $value;
>
> };
> }
This, however, is your actual problem, I believe. You chose to define
this subroutine within a loop block. That means that it has access
only to the variables declared in the FIRST iteration of that loop.
On the second iteration, you've declared a new `my %array`, but this
subroutine is still accessing that first `my %array`;
Declare your subroutines and variables properly, and you won't run
into this mess. If you have a variable that's needed both in the loop
and in the subroutine, it needs to be declared outside the loop.
Subroutines should almost *never* be declared inside a loop.
Alternatively (and perphaps preferably), declare the %array variable
in the loop, and pass a reference to it to the subroutine, rather than
using it as a pseudo-global.
Paul Lalli
------------------------------
Date: 13 Apr 2007 05:40:03 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Can anyone see why this skips the remaining username/pass hash elements
Message-Id: <1176468003.451507.273100@e65g2000hsc.googlegroups.com>
On Apr 13, 8:34 am, "Paul Lalli" <mri...@gmail.com> wrote:
> This, however, is your actual problem, I believe. You chose to define
> this subroutine within a loop block. That means that it has access
> only to the variables declared in the FIRST iteration of that loop.
> On the second iteration, you've declared a new `my %array`, but this
> subroutine is still accessing that first `my %array`;
>
> Declare your subroutines and variables properly, and you won't run
> into this mess. If you have a variable that's needed both in the loop
> and in the subroutine, it needs to be declared outside the loop.
> Subroutines should almost *never* be declared inside a loop.
> Alternatively (and perphaps preferably), declare the %array variable
> in the loop, and pass a reference to it to the subroutine, rather than
> using it as a pseudo-global.
Here, btw, is a short-but-complete script that demonstrates this
issue:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
for (0..3) {
my %foo;
bar($_);
print Dumper(\%foo);
sub bar {
my $num = shift;
$foo{$num} = 1;
}
}
__END__
$VAR1 = {
'0' => 1
};
$VAR1 = {};
$VAR1 = {};
$VAR1 = {};
Compare and contrast with:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my %foo;
for (0..3) {
bar($_);
print Dumper(\%foo);
}
sub bar {
my $num = shift;
$foo{$num} = 1;
}
__END__
$VAR1 = {
'0' => 1
};
$VAR1 = {
'1' => 1,
'0' => 1
};
$VAR1 = {
'1' => 1,
'0' => 1,
'2' => 1
};
$VAR1 = {
'1' => 1,
'3' => 1,
'0' => 1,
'2' => 1
};
Or with:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
for (0..3) {
my %foo;
bar($_, \%foo);
print Dumper(\%foo);
}
sub bar {
my $num = shift;
my $foo_ref = shift;
$foo_ref->{$num} = 1;
}
__END__
$VAR1 = {
'0' => 1
};
$VAR1 = {
'1' => 1
};
$VAR1 = {
'2' => 1
};
$VAR1 = {
'3' => 1
};
Use the one that makes sense for your given situation.
Paul Lalli
------------------------------
Date: Fri, 13 Apr 2007 11:43:45 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Extracting text between two market lines. (FAQ variation?)
Message-Id: <461f5eea$0$19258$da0feed9@news.zen.co.uk>
The following program extracts a portion of text between two marker lines.
----------------------------------8<------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $cert;
while(<DATA>) {
$cert .= $_ if /BEGIN CERTIFICATE/ .. /END CERTIFICATE/;
}
print "*** cert is [$cert] ***\n";
__DATA__
foo
bar
-----BEGIN CERTIFICATE-----
This is a certificate
it has several lines
this is the last
-----END CERTIFICATE-----
whizz
bang
------------------------------------------------------------------
I've read the FAQ. I'm unsure how best to modify this so that the
extracted text omits the markers.
My best attempt:
----------------------------------8<------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $cert;
while(<DATA>) { $cert .= $_; }
$cert =~ s/.*BEGIN CERTIFICATE-----\n(.*)\n-----END CERT.*/$1/s;
print "*** cert is [$cert] ***\n";
__DATA__
foo
bar
-----BEGIN CERTIFICATE-----
This is a certificate
it has several lines
this is the last
-----END CERTIFICATE-----
whizz
bang
------------------------------------------------------------------
Anyone have suggestions for "better", clearer or more succinct code?
~
------------------------------
Date: 13 Apr 2007 11:10:02 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Extracting text between two market lines. (FAQ variation?)
Message-Id: <5896oaF2f72ciU1@mid.dfncis.de>
Ian Wilson <scobloke2@infotop.co.uk> wrote in comp.lang.perl.misc:
> The following program extracts a portion of text between two marker lines.
>
> ----------------------------------8<------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $cert;
> while(<DATA>) {
> $cert .= $_ if /BEGIN CERTIFICATE/ .. /END CERTIFICATE/;
> }
>
> print "*** cert is [$cert] ***\n";
>
> __DATA__
> foo
> bar
> -----BEGIN CERTIFICATE-----
> This is a certificate
> it has several lines
> this is the last
> -----END CERTIFICATE-----
> whizz
> bang
> ------------------------------------------------------------------
>
> I've read the FAQ. I'm unsure how best to modify this so that the
> extracted text omits the markers.
> My best attempt:
[slurp, s/// solution snipped]
A straightforward way is to modify the condition accordingly:
my $cert;
while(<DATA>) {
$cert .= $_ if
/BEGIN CERTIFICATE/ .. /END CERTIFICATE/ and
!( /BEGIN CERTIFICATE/ or /END CERTIFICATE/);
}
print "*** cert is [$cert] ***\n";
Here is another approach:
my @cert;
while(<DATA>) {
push @cert, $_ if /BEGIN CERTIFICATE/ .. /END CERTIFICATE/;
}
my $cert = join '', @cert[ 1 .. $#cert - 1];
print "*** cert is [$cert] ***\n";
That can be compressed to
my $cert = do {
my @cert = grep /BEGIN CERTIFICATE/ .. /END CERTIFICATE/, <DATA>;
join '', @cert[ 1 .. $#cert - 1];
};
though that slurps the data again.
Anno
------------------------------
Date: 13 Apr 2007 11:23:20 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Extracting text between two market lines. (FAQ variation?)
Message-Id: <slrnf1uq18.24e.abigail@alexandra.abigail.be>
Ian Wilson (scobloke2@infotop.co.uk) wrote on MMMMCMLXXIII September
MCMXCIII in <URL:news:461f5eea$0$19258$da0feed9@news.zen.co.uk>:
^^ The following program extracts a portion of text between two marker lines.
^^
^^ ----------------------------------8<------------------------------
^^ #!/usr/bin/perl
^^ use strict;
^^ use warnings;
^^
^^ my $cert;
^^ while(<DATA>) {
^^ $cert .= $_ if /BEGIN CERTIFICATE/ .. /END CERTIFICATE/;
^^ }
^^
^^ print "*** cert is [$cert] ***\n";
^^
^^ __DATA__
^^ foo
^^ bar
^^ -----BEGIN CERTIFICATE-----
^^ This is a certificate
^^ it has several lines
^^ this is the last
^^ -----END CERTIFICATE-----
^^ whizz
^^ bang
^^ ------------------------------------------------------------------
^^
^^ I've read the FAQ. I'm unsure how best to modify this so that the
^^ extracted text omits the markers.
^^ My best attempt:
^^
^^ ----------------------------------8<------------------------------
^^ #!/usr/bin/perl
^^ use strict;
^^ use warnings;
^^
^^ my $cert;
^^ while(<DATA>) { $cert .= $_; }
^^ $cert =~ s/.*BEGIN CERTIFICATE-----\n(.*)\n-----END CERT.*/$1/s;
^^
^^ print "*** cert is [$cert] ***\n";
^^
^^ __DATA__
^^ foo
^^ bar
^^ -----BEGIN CERTIFICATE-----
^^ This is a certificate
^^ it has several lines
^^ this is the last
^^ -----END CERTIFICATE-----
^^ whizz
^^ bang
^^ ------------------------------------------------------------------
^^
^^ Anyone have suggestions for "better", clearer or more succinct code?
One way would be:
my $cert;
my $flag;
while (<DATA>) {
$flag = 1, next if /BEGIN CERTIFICATE/;
$flag = 0, next if /END CERTIFICATE/;
$cert .= $_ if $flag;
}
Replace the second line in the loop with
last if /END CERTIFICATE/;
if there's just one CERTIFICATE block you want to extract.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Fri, 13 Apr 2007 14:09:34 +0200
From: "PERO" <pero@pero.pero>
Subject: How to change decimal point ',' to decimal comma ','
Message-Id: <evnrtt$2o8$1@ss408.t-com.hr>
How to change decimal point ',' to decimal comma ','
eg:
$num=1345,25;
TNX
------------------------------
Date: Fri, 13 Apr 2007 14:29:35 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: How to change decimal point ',' to decimal comma ','
Message-Id: <461f77af$0$90262$14726298@news.sunsite.dk>
PERO wrote:
> How to change decimal point ',' to decimal comma ','
>
> eg:
>
> $num=1345,25;
> TNX
>
>
my $num=120.269;
print $num, "\n";
$num =~ s/\./,/;
print $num, "\n";
regards,
Reinhard
--
PM Mails an rpirpag <at> gmx dot at
------------------------------
Date: Fri, 13 Apr 2007 14:14:15 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: How to change decimal point ',' to decimal comma ','
Message-Id: <evnsfq$nfm$1@ns.felk.cvut.cz>
"PERO" <pero@pero.pero> píše v diskusním příspěvku
news:evnrtt$2o8$1@ss408.t-com.hr...
> How to change decimal point ',' to decimal comma ','
>
> eg:
>
> $num=1345,25;
> TNX
>
$num=1345.25;
$num =~s/\./,/;
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Fri, 13 Apr 2007 14:32:05 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to change decimal point ',' to decimal comma ','
Message-Id: <evnt8b$4is$1@nntp.fujitsu-siemens.com>
PERO wrote:
> How to change decimal point ',' to decimal comma ','
Huh?
> eg:
>=20
> $num=3D1345,25;
You could try using a text editor.
Ages ago, a suitable suggestion would be to post it on Usenet ...
What exactly are you trying to accomplish, what code have you written so =
far and where does your code not meet your expectations?
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Fri, 13 Apr 2007 15:06:23 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: How to change decimal point ',' to decimal comma ','
Message-Id: <evnvit$bpt$1@mlucom4.urz.uni-halle.de>
PERO wrote:
> How to change decimal point ',' to decimal comma ','
>
> eg:
>
> $num=1345,25;
> TNX
Wild guess:
...
use POSIX;
my $num = "1345,25"; # ==> '1345,25' as "numeric literal"
setlocale(LC_ALL, "de_DE"); # "de" has comma as decimal point
my $m = strtod( $num ); # $m ==> '1345.25' now converted!
printf "%.3f\n", $m+$m;
setlocale(LC_ALL, "C");
printf "%.3f\n", $m+$m;
...
prints here (5.8.8 on Linux):
2690,500
2690.500
which is what one would expect.
Regards
Mirco
------------------------------
Date: Fri, 13 Apr 2007 07:00:27 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: My Perl Ode to Purl Gurl
Message-Id: <slrnf1us6r.omf.tadmc@tadmc30.august.net>
grocery_stocker <cdalten@gmail.com> wrote:
> On Apr 12, 2:28 pm, Purl Gurl <purlg...@purlgurl.net> wrote:
>> * autographed copies are $5.00 each via Paypal
>
> autographed copies are $5.00?! You can't be serious.
That poster is never serious.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 13 Apr 2007 07:43:09 -0500
From: "AC" <clarke@n_o_s_p_a_m_hyperformix.com>
Subject: Re: My Perl Ode to Purl Gurl
Message-Id: <461f7aec$0$17209$39cecf19@news.twtelecom.net>
"Purl Gurl" <purlgurl@purlgurl.net> wrote in message
news:KPOdnQU-ptYYOYPbnZ2dnUVZ_uKknZ2d@giganews.com...
> purllad wrote:
>
[snip]
>
> In exchange for your endearing love for me, a
> photograph* or two.
>
> http://www.purlgurl.net/aue/dressy.jpg
>
> Purl Gurl
>
> * autographed copies are $5.00 each via Paypal
I hope I don't burst anyone's bubble here, but in those photos, "Purl Gurl"
is the leftmost person in the first photo.
AC
------------------------------
Date: 13 Apr 2007 00:27:39 -0700
From: kiranmn@my-deja.com
Subject: Re: perl regular expression
Message-Id: <1176449259.274061.188120@b75g2000hsg.googlegroups.com>
Thankyou, it is working, but why it is failing in my RE, what is wrong
in that. Sorry just i want to learn more about RE.
Can you please give some good url or good book title, which covers
zero-width look-behind assertion.
Thanking you once again
kiran
On Apr 13, 11:51 am, Sherm Pendley <spamt...@dot-app.org> wrote:
> kira...@my-deja.com writes:
> > I want all doublequote in a string to be prefixed with '\'. I want
> > to achive this with a regular expression and this regular expression
> > will be in a loop, so for the same input if this same RE runs multiple
> > times, it will add multiple '\` before doublequote, to avoid that i
> > am checking for " NOT A BACKSLASH" in following RE.
>
> > Following RE works for me, but it fails for two consecutive
> > doublequotes.
> > Why RE is failing to replace second double quote, even with /g ?
>
> > regards,
> > kiran
>
> > ------------------------------------------
> > Expect output
> > input is abc "" c " de
> > output is abc \"\" c \" de
> > ------------------------------------------
> > current output
> > input is abc "" c " de
> > output is abc \"" c \" de
> > =========================
> > $input='abc "" c " de';
> > print "input is $input\n";;
> > $input=~ s/([^\\x])"/$1\\"/g;
> > print "output is $input\n";;
> > ============================
>
> My regex-fu isn't up to the task of explaining why your character class
> approach isn't working - sorry. But, when I need to express a pattern of
> the type "foo not preceded by bar", I do it with a zero-width look-behind
> assertion:
>
> $input=~ s/(?<!\\)"/\\"/g;
>
> That produces the expected output:
>
> input is abc "" c " de
> output is abc \"\" c \" de
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net
------------------------------
Date: Fri, 13 Apr 2007 03:37:52 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: perl regular expression
Message-Id: <m23b34lo6n.fsf@local.wv-www.com>
kiranmn@my-deja.com writes:
Upside-down. Please don't do that.
> On Apr 13, 11:51 am, Sherm Pendley <spamt...@dot-app.org> wrote:
>> kira...@my-deja.com writes:
>> > I want all doublequote in a string to be prefixed with '\'. I want
>> > to achive this with a regular expression and this regular expression
>> > will be in a loop, so for the same input if this same RE runs multiple
>> > times, it will add multiple '\` before doublequote, to avoid that i
>> > am checking for " NOT A BACKSLASH" in following RE.
>>
>> > Following RE works for me, but it fails for two consecutive
>> > doublequotes.
>> > Why RE is failing to replace second double quote, even with /g ?
>>
>> > regards,
>> > kiran
>>
>> > ------------------------------------------
>> > Expect output
>> > input is abc "" c " de
>> > output is abc \"\" c \" de
>> > ------------------------------------------
>> > current output
>> > input is abc "" c " de
>> > output is abc \"" c \" de
>> > =========================
>> > $input='abc "" c " de';
>> > print "input is $input\n";;
>> > $input=~ s/([^\\x])"/$1\\"/g;
>> > print "output is $input\n";;
>> > ============================
>>
>> My regex-fu isn't up to the task of explaining why your character class
>> approach isn't working - sorry. But, when I need to express a pattern of
>> the type "foo not preceded by bar", I do it with a zero-width look-behind
>> assertion:
>>
>> $input=~ s/(?<!\\)"/\\"/g;
>>
>> That produces the expected output:
>>
>> input is abc "" c " de
>> output is abc \"\" c \" de
>
> Thankyou, it is working, but why it is failing in my RE, what is wrong
> in that. Sorry just i want to learn more about RE.
Like I said - I'm not up to explaining that. All I did was replace it with
my usual approach for expressing "foo not preceded by bar." I'm honestly
quite interested in having someone explain the failure in your original
approach too. :-)
> Can you please give some good url or good book title, which covers
> zero-width look-behind assertion.
Have a look in "perldoc perlretut", Part 2 "Power Tools".
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Fri, 13 Apr 2007 09:48:17 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: perl regular expression
Message-Id: <461f35c1$0$23149$9b4e6d93@newsspool1.arcor-online.net>
kiranmn@my-deja.com wrote:
> I want all doublequote in a string to be prefixed with '\'. I want
> to achive this with a regular expression and this regular expression
> will be in a loop, so for the same input if this same RE runs multiple
> times, it will add multiple '\` before doublequote, to avoid that i
> am checking for " NOT A BACKSLASH" in following RE.
>
> Following RE works for me, but it fails for two consecutive
> doublequotes.
> Why RE is failing to replace second double quote, even with /g ?
>
> regards,
> kiran
>
> ------------------------------------------
> Expect output
> input is abc "" c " de
> output is abc \"\" c \" de
> ------------------------------------------
> current output
> input is abc "" c " de
> output is abc \"" c \" de
> =========================
> $input='abc "" c " de';
> print "input is $input\n";;
> $input=~ s/([^\\x])"/$1\\"/g;
> print "output is $input\n";;
> ============================
The reason it doesn't DWYM is that you are matching a two char pattern,
and after the first doublequote is encountered, the regex position
pointer is after the doublequote. In detail:
The regex (not backslash or x, followed by doublequote) is first matched
against 'abc "" c " de'. It hits on the first doublequote, does the
replacement and moves the regex position pointer after the doublequote.
So now the string the regex is matched against is only '" c " de'.
This, of course, doesn't match, because the '"' is already consumed by
the "not backslash or x" part.
You can use a zero width look-behind assertion to avoid that
(quite common) pitfall (see "perldoc perlre" for a description of
zero width assertions).
$input =~ s/(?<![\\x])"/\\"/g;
should do the trick. If you want to see what goes on with regexes you
can put "use re 'debug';" in your script, then you get verbose output
of all the steps in the matching process.
-Chris
------------------------------
Date: Fri, 13 Apr 2007 10:36:31 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: perl regular expression
Message-Id: <461f410f$0$6394$9b4e6d93@newsspool2.arcor-online.net>
Christian Winter wrote:
> kiranmn@my-deja.com wrote:
>> I want all doublequote in a string to be prefixed with '\'. I want
>> to achive this with a regular expression and this regular expression
>> will be in a loop, so for the same input if this same RE runs multiple
>> times, it will add multiple '\` before doublequote, to avoid that i
>> am checking for " NOT A BACKSLASH" in following RE.
>>
>> Following RE works for me, but it fails for two consecutive
>> doublequotes.
>> Why RE is failing to replace second double quote, even with /g ?
>>
>> regards,
>> kiran
>>
>> ------------------------------------------
>> Expect output
>> input is abc "" c " de
>> output is abc \"\" c \" de
>> ------------------------------------------
>> current output
>> input is abc "" c " de
>> output is abc \"" c \" de
>> =========================
>> $input='abc "" c " de';
>> print "input is $input\n";;
>> $input=~ s/([^\\x])"/$1\\"/g;
>> print "output is $input\n";;
>> ============================
>
> The reason it doesn't DWYM is that you are matching a two char pattern,
> and after the first doublequote is encountered, the regex position
> pointer is after the doublequote. In detail:
>
> The regex (not backslash or x, followed by doublequote) is first matched
> against 'abc "" c " de'. It hits on the first doublequote, does the
> replacement and moves the regex position pointer after the doublequote.
> So now the string the regex is matched against is only '" c " de'.
> This, of course, doesn't match,
Should have been "doesn't match where you intend it to", of course.
> because the first '"' is already consumed by the "not backslash or x" part.
[...]
-Chris
------------------------------
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 331
**************************************