[22320] in Perl-Users-Digest
Perl-Users Digest, Issue: 4541 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 10 19:07:05 2003
Date: Mon, 10 Feb 2003 16:01:41 -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 Mon, 10 Feb 2003 Volume: 10 Number: 4541
Today's topics:
RegEx Questions <mememe@meme.com>
Re: RegEx Questions (Tad McClellan)
Re: RegEx Questions <goldbb2@earthlink.net>
Re: RegEx Questions <lockner@cse.psu.edu>
Re: RegEx Questions <tore@aursand.no>
remove non-numerical characters from a string <abayny@hotmail.com>
Re: remove non-numerical characters from a string <xyf@nixnotes.org>
Re: remove non-numerical characters from a string <noreply@gunnar.cc>
Re: remove non-numerical characters from a string <xyf@nixnotes.org>
Re: remove non-numerical characters from a string <krahnj@acm.org>
Request help with this script (Julia Briggs)
Re: Request help with this script <mgjv@tradingpost.com.au>
Re: Request help with this script <bob@fourtheye.REMOVEME.org>
Re: Return the index of an array <alex@alexbanks.com>
Scope of a global lexical (Greg)
Re: Scope of a global lexical <eric.ehlers@btopenworld.com.nospam>
Re: Scope of a global lexical <tassilo.parseval@post.rwth-aachen.de>
Re: Scope of a global lexical <tore@aursand.no>
Re: Script Problem - PLEASE help <abigail@abigail.nl>
Re: Simple regexp gots me stuck... (OJ)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 10 Feb 2003 10:42:14 -0700
From: "ColdCathoids" <mememe@meme.com>
Subject: RegEx Questions
Message-Id: <b28o9q$19l7ih$1@ID-158028.news.dfncis.de>
Hello all,
I have a string that contains entries such as the following:
MSIE 6.0 on Windows XP 24.49 18.14 + 6.35
MSIE 6.0 on Windows 98 10.91 10.43 + 0.48
MSIE 6.0 (AOL) on Windows 2000 0.16 0.10 - 0.06
MSIE 5.5 on Other 0.03 0.03 0.00
Ideally what I would like to do is make this a csv looking like this:
MSIE 6.0,Windows XP,24.49,18.14,+ 6.35
MSIE 6.0,Windows 98,10.91,10.43,+ 0.48
MSIE 6.0 (AOL),Windows 2000,0.16,0.10,- 0.06
MSIE 5.5,Other,0.03,0.03,0.00
In my head I know how to do it. But getting perl to do what my head says is
a bit of a challange. =)
First off the easy part:
$string =~ s/ on /,/g;
I am thinking if you start at the end and go character by character until
you hit a space. If the next character is not a + or - substitute all the
spaces with a comma. Otherwise put a comma before the +or-. Then keep
reading to the left until you hit more numbers .. next space replace with
comma, repeat again to get third and final comma.
Does this make sense at all or am I going about this the total ghetto way?
Any help with this would be MOST appreciated.
------------------------------
Date: Mon, 10 Feb 2003 13:02:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: RegEx Questions
Message-Id: <slrnb4ftpc.5i3.tadmc@magna.augustmail.com>
ColdCathoids <mememe@meme.com> wrote:
> Ideally what I would like to do is make this a csv looking like this:
>
> MSIE 6.0,Windows XP,24.49,18.14,+ 6.35
> MSIE 6.0,Windows 98,10.91,10.43,+ 0.48
> MSIE 6.0 (AOL),Windows 2000,0.16,0.10,- 0.06
> MSIE 5.5,Other,0.03,0.03,0.00
>
> In my head I know how to do it. But getting perl to do what my head says is
> a bit of a challange. =)
substr() as an lvalue will come in handy.
> Any help with this would be MOST appreciated.
--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
while ( <DATA> ) {
my $on = index $_, ' on '; # locate the "on"
substr($_, $on, 4) = ','; # replace it with a comma
substr($_, $on+4) =~ s/ (\d+\.\d+)/,$1/; # comma before first
substr($_, $on+4) =~ s/(\d+\.\d+) /$1,/g; # comma after all the others
s/\s*,\s*/,/g;
print;
}
__DATA__
MSIE 6.0 on Windows XP 24.49 18.14 + 6.35
MSIE 6.0 on Windows 98 10.91 10.43 + 0.48
MSIE 6.0 (AOL) on Windows 2000 0.16 0.10 - 0.06
MSIE 5.5 on Other 0.03 0.03 0.00
--------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 10 Feb 2003 16:16:11 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: RegEx Questions
Message-Id: <3E48169B.70871773@earthlink.net>
ColdCathoids wrote:
>
> Hello all,
>
> I have a string that contains entries such as the following:
>
> MSIE 6.0 on Windows XP 24.49 18.14 + 6.35
> MSIE 6.0 on Windows 98 10.91 10.43 + 0.48
> MSIE 6.0 (AOL) on Windows 2000 0.16 0.10 - 0.06
> MSIE 5.5 on Other 0.03 0.03 0.00
>
> Ideally what I would like to do is make this a csv looking like this:
>
> MSIE 6.0,Windows XP,24.49,18.14,+ 6.35
> MSIE 6.0,Windows 98,10.91,10.43,+ 0.48
> MSIE 6.0 (AOL),Windows 2000,0.16,0.10,- 0.06
> MSIE 5.5,Other,0.03,0.03,0.00
while( <> ) {
my ($msie, $windows, $numbers) =
/^\s*(.*?) on (.*?) (\d+\.\d.*)/;
print join(",", $msie, $windows,
$numbers =~ / *(.*?\d+\.\d+)/g), "\n";
}
[untested]
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: Mon, 10 Feb 2003 16:23:44 -0500
From: Matthew Lockner <lockner@cse.psu.edu>
Subject: Re: RegEx Questions
Message-Id: <b29590$1d7c$1@f04n12.cac.psu.edu>
ColdCathoids wrote:
> Hello all,
>
> I have a string that contains entries such as the following:
>
> MSIE 6.0 on Windows XP 24.49 18.14 + 6.35
> MSIE 6.0 on Windows 98 10.91 10.43 + 0.48
> MSIE 6.0 (AOL) on Windows 2000 0.16 0.10 - 0.06
> MSIE 5.5 on Other 0.03 0.03 0.00
>
> Ideally what I would like to do is make this a csv looking like this:
>
> MSIE 6.0,Windows XP,24.49,18.14,+ 6.35
> MSIE 6.0,Windows 98,10.91,10.43,+ 0.48
> MSIE 6.0 (AOL),Windows 2000,0.16,0.10,- 0.06
> MSIE 5.5,Other,0.03,0.03,0.00
>
Pretty ad hoc, and won't strip the spaces from the front of the numbers:
while (my $line = <>) {
my ($browser, $rest) = split / on /, $line;
$rest =~ s/ *([+-]? \d+\.\d+)/,$1/g;
print $browser, ',', $rest;
}
The regex matches the most general of your numbers, that being an optional
sign and space, some digits, a point, and more digits.
Good luck,
MJL
------------------------------
Date: Mon, 10 Feb 2003 23:39:36 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: RegEx Questions
Message-Id: <pan.2003.02.10.22.29.23.411656@aursand.no>
On Mon, 10 Feb 2003 10:42:14 -0700, ColdCathoids wrote:
> I have a string that contains entries such as the following:
>
> MSIE 6.0 on Windows XP 24.49 18.14 + 6.35
> MSIE 6.0 on Windows 98 10.91 10.43 + 0.48
> MSIE 6.0 (AOL) on Windows 2000 0.16 0.10 - 0.06
> MSIE 5.5 on Other 0.03 0.03 0.00
>
> Ideally what I would like to do is make this a csv looking like this:
> [...]
Quick and dirty, but should work. :)
#!/usr/bin/perl
#
use strict;
use warnings;
while ( <DATA> ) {
s/^(.*)\s+on\s+(.*)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(.*)$/$1,$2,$3,$4,$5/;
print;
}
__DATA__
MSIE 6.0 on Windows XP 24.49 18.14 + 6.35
MSIE 6.0 on Windows 98 10.91 10.43 + 0.48
MSIE 6.0 (AOL) on Windows 2000 0.16 0.10 - 0.06
MSIE 5.5 on Other 0.03 0.03 0.00
Output:
MSIE 6.0,Windows XP,24.49,18.14,+ 6.35
MSIE 6.0,Windows 98,10.91,10.43,+ 0.48
MSIE 6.0 (AOL),Windows 2000,0.16,0.10,- 0.06
MSIE 5.5,Other,0.03,0.03,0.00
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: Mon, 10 Feb 2003 06:54:44 GMT
From: "Dan" <abayny@hotmail.com>
Subject: remove non-numerical characters from a string
Message-Id: <U0I1a.5289$9U3.1397@twister.nyroc.rr.com>
How do you remove all non-numerical characters from a string?
Thanks a lot,
Dan
------------------------------
Date: Mon, 10 Feb 2003 07:12:58 GMT
From: ktb <xyf@nixnotes.org>
Subject: Re: remove non-numerical characters from a string
Message-Id: <slrnb4ek7o.91l.xyf@scab.nixnotes.org>
In article <U0I1a.5289$9U3.1397@twister.nyroc.rr.com>, Dan wrote:
> How do you remove all non-numerical characters from a string?
>
There might be better ways of doing it but this seems to work -
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
s/[A-Za-z]//g;
print;
}
kent
--
To know the truth is to distort the Universe.
Alfred N. Whitehead (adaptation)
------------------------------
Date: Mon, 10 Feb 2003 07:15:04 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: remove non-numerical characters from a string
Message-Id: <YjI1a.10399$LY2.620828@newsc.telia.net>
Dan wrote:
> How do you remove all non-numerical characters from a string?
$string =~ s/\D//g;
Which efforts had you made you find out yourself?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 10 Feb 2003 07:31:36 GMT
From: ktb <xyf@nixnotes.org>
Subject: Re: remove non-numerical characters from a string
Message-Id: <slrnb4elan.98r.xyf@scab.nixnotes.org>
In article <slrnb4ek7o.91l.xyf@scab.nixnotes.org>, ktb wrote:
> In article <U0I1a.5289$9U3.1397@twister.nyroc.rr.com>, Dan wrote:
>> How do you remove all non-numerical characters from a string?
>>
>
> There might be better ways of doing it but this seems to work -
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> while (<>) {
> s/[A-Za-z]//g;
> print;
> }
>
On further reflection
s/\D//g
or
s/[^0-9]//g
would be better as it weeds out &,*,(, etc.
kent
--
To know the truth is to distort the Universe.
Alfred N. Whitehead (adaptation)
------------------------------
Date: Mon, 10 Feb 2003 09:02:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: remove non-numerical characters from a string
Message-Id: <3E476A3E.453819EF@acm.org>
Dan wrote:
>
> How do you remove all non-numerical characters from a string?
$string =~ tr/0-9//cd;
John
--
use Perl;
program
fulfillment
------------------------------
Date: 9 Feb 2003 19:45:35 -0800
From: julia4_me@yahoo.com (Julia Briggs)
Subject: Request help with this script
Message-Id: <c48f65ef.0302091945.3b78962a@posting.google.com>
Hello! I've got this simple script that works just fine, but I'm
looking for any suggestions on how to improve... mainly what I desire
is to make sure that some hacker can't mess with it. Any
suggestions/ideas on how best to reinforce this script??
Thx,
JB
#!/usr/local/bin/perl
$|++;
use CGI;
$query=new CGI;
print "Content-type: text/html\n\n";
$email_recipient = 'julia4_me@yahoo.com';
$subject = "<Subject Line>";
$Subject1 = "<Subject Line>";
$copy = "<Message Copy>";
$copy1 = "<Message Copy>";
&check_url;
&mailAttachment;
&confirmation;
sub check_url {
local($check_referer) = 0;
if ($ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i)
{
$check_referer = 1;
last;
}
}
}
else {
$check_referer = 1;
}
if ($check_referer != 1) { &error('bad_referer') }
}
# _________________________________________________________
sub mailAttachment {
$boundary="Message-Boundary-19990614";
$mailprog ="/usr/lib/sendmail";
foreach ($query->param){
if ($query->param($_)){ ## The user entered some value!!
if (/^file_attached_[A-Z]$/){ ## The uploaded file!!
++$no_of_files;
push(@list,$_);
}else{ ## One of the other items (Sender's Name,
Sender's Email, etc...).
## Store the value in a variable.
## The name of the variable is the same as the HTML
form element name
## Eg if the HTML element is called name_sender,
the PERL
## variable will be called $name_sender.
$$_=$query->param($_);
}
}
}
open(MAIL, "| $mailprog -t ");
print MAIL "To: $name_recipient <$email_recipient>\n";
print MAIL "From: $name_sender <$email_sender>\n";
print MAIL "Subject: $subject\n";
print MAIL "MIME-Version: 1.0\n";
## Add the text part of the message
print "Content-type: text/html\n\n";
print MAIL "Content-type: text/plain; charset=US-ASCII\n";
print MAIL "Content-description: candidate.data\n";
print MAIL "Content-transfer-encoding: 7BIT\n";
print MAIL "\n";
print MAIL "$copy\n";
## Send out the contents!!
close (MAIL);
}
# _________________________________________________________
sub confirmation {
open(MAIL, "| $mailprog -t ");
print MAIL "To: $email_sender\n";
print MAIL "From: $email_recipient\n";
print MAIL "Subject: $Subject1\n";
print MAIL "$copy1\n\n";
close (MAIL);
}
------------------------------
Date: Mon, 10 Feb 2003 04:48:00 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Request help with this script
Message-Id: <slrnb4ebo0.se5.mgjv@verbruggen.comdyn.com.au>
On 9 Feb 2003 19:45:35 -0800,
Julia Briggs <julia4_me@yahoo.com> wrote:
> Hello! I've got this simple script that works just fine, but I'm
> looking for any suggestions on how to improve... mainly what I desire
> is to make sure that some hacker can't mess with it. Any
> suggestions/ideas on how best to reinforce this script??
>
> Thx,
>
> JB
>
>
> #!/usr/local/bin/perl
use warnings; # -w if you have a perl < 5.6.0
use strict;
> $|++;
>
> use CGI;
>
> $query=new CGI;
>
> print "Content-type: text/html\n\n";
Use the methods that CGI.pm gives you, instead of this.
> $email_recipient = 'julia4_me@yahoo.com';
> $subject = "<Subject Line>";
> $Subject1 = "<Subject Line>";
> $copy = "<Message Copy>";
> $copy1 = "<Message Copy>";
>
> &check_url;
Don't use this way to call subroutines. Use check_url(). Read the
perlsub documentation for the reason.
Don't use that many global variables. While globals have a place, it
is generally better to avoid them, and to pass parameters to
subroutines. From a quick skim of the rest of your code, it seems you
don't need any globals.
> &mailAttachment;
> &confirmation;
>
> sub check_url {
>
> local($check_referer) = 0;
>
> if ($ENV{'HTTP_REFERER'}) {
Again, why did you include the CGI module? You don't seem to be using
it.
> sub mailAttachment {
>
> $boundary="Message-Boundary-19990614";
> $mailprog ="/usr/lib/sendmail";
Why package globals here? They should be lexically scoped.
I would also advise you to use one of the modules on CPAN to do
emailing, and another one to do MIME handling. The first will make
your code more portable, the second will make it easier to maintain.
> foreach ($query->param){
> if ($query->param($_)){ ## The user entered some value!!
> if (/^file_attached_[A-Z]$/){ ## The uploaded file!!
> ++$no_of_files;
> push(@list,$_);
>
> }else{ ## One of the other items (Sender's Name,
> $$_=$query->param($_);
Do not do this. These are symbolic references, and you should only be
using those when you understand why. Write your program with use
strict, and use a hash here instead (or rather, don't do this loop at
all, and just use $query-param() when you need the value).
> open(MAIL, "| $mailprog -t ");
Always check the result of an open.
> print MAIL "To: $name_recipient <$email_recipient>\n";
> print MAIL "From: $name_sender <$email_sender>\n";
Instead of using so many print statements, you might consider using a
here-document (see the perldata documentation). Of course, if you
switch to using a module to do your MIME and Mail handling, you won't
need this.
> close (MAIL);
When piping, always check the result of a close. This is where you
will get an error condition from the program you called.
Summarising: many possibilities for improvement. Using strict, and
properly scoped variables will help tremendously.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Can't say that it is, 'cause it ain't.
|
------------------------------
Date: Mon, 10 Feb 2003 22:57:29 +0000
From: "Bob Wilkinson" <bob@fourtheye.REMOVEME.org>
To: julia4_me@yahoo.com (Julia Briggs)
Subject: Re: Request help with this script
Message-Id: <pan.2003.02.10.22.57.28.323477@fourtheye.REMOVEME.org>
On Sun, 09 Feb 2003 19:45:35 -0800, Julia Briggs wrote:
> Hello! I've got this simple script that works just fine, but I'm
> looking for any suggestions on how to improve... mainly what I desire
> is to make sure that some hacker can't mess with it. Any
> suggestions/ideas on how best to reinforce this script??
>
> Thx,
>
> JB
>
>
> #!/usr/local/bin/perl
>
In addition to those suggestions made by Martien Verbruggen, I would
suggest running with a -T flag on, too.
i.e. use #!/usr/bin/perl -Tw
perldoc perlrun tells us:
-T forces "taint" checks to be turned on so you can test them.
Ordinarily these checks are done only when running setuid
or setgid. It's a good idea to turn them on explicitly for
programs that run on behalf of someone else whom you might not
necessarily trust, such as CGI programs or any internet servers
you might write in Perl. See perlsec for details. For security
reasons, this option must be seen by Perl quite early; usually
this means it must appear early on the command line or in the
#! line for systems which support that construct.
As it says there a reading of perlsec gives more detail about enhancing
security.
Bob
------------------------------
Date: Fri, 7 Feb 2003 17:08:23 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: Return the index of an array
Message-Id: <3e43e80c$0$4022$cc9e4d1f@news.dial.pipex.com>
Well, thanks all very much. My problem is now sorted - funnily enough I
wound up using a hash. But I've learnt a little more about how Perl deals
with arrays.
TTFN, Alex
---------------------------
alex@alexbanks.com
http://www.alexbanks.com
------------------------------
Date: 10 Feb 2003 11:49:35 -0800
From: gdsafford@hotmail.com (Greg)
Subject: Scope of a global lexical
Message-Id: <a8f367ed.0302101149.700eb516@posting.google.com>
use strict;
use warnings;
smith();
my $global = 3;
sub smith{
print $global || 'undef', "\n";
}
This prints 'undef' when run in my local Perl 5.6 installation. How
can the body of smith() be interpreted without the assignment of 3 to
$global having taken place? The funny thing is that I tried running
this using a Perl 5.5.3 installation and printed '3'.
Any insight or a reference to where information might be found
appreciated.
TIA
Greg
------------------------------
Date: Mon, 10 Feb 2003 20:28:06 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.nospam>
Subject: Re: Scope of a global lexical
Message-Id: <b2920m$evk$1@knossos.btinternet.com>
"Greg" <gdsafford@hotmail.com> wrote in message
news:a8f367ed.0302101149.700eb516@posting.google.com...
> use strict;
> use warnings;
>
> smith();
>
> my $global = 3;
>
> sub smith{
> print $global || 'undef', "\n";
> }
>
> This prints 'undef' when run in my local Perl 5.6 installation. How
> can the body of smith() be interpreted without the assignment of 3 to
> $global having taken place?
the line
my $global = 3;
causes $global to be recognized at compile time, and set to 3 at run time.
the compile-time recognition means that sub smith can access $global without
generating a compile-time error under strict 'vars'.
the run-time assignment does not happen until after the call to sub smith,
so $global is undefined when sub smith runs.
> The funny thing is that I tried running
> this using a Perl 5.5.3 installation and printed '3'.
i don't have a copy of Perl 5.5.3 to hand, if what you say is true then that
would suggest that the behavior of "my" has changed under 5.6.
> Any insight or a reference to where information might be found
> appreciated.
>
> TIA
>
> Greg
HTH
-eric
------------------------------
Date: 10 Feb 2003 21:03:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Scope of a global lexical
Message-Id: <b2942e$t6f$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Greg:
> use strict;
> use warnings;
>
> smith();
>
> my $global = 3;
>
> sub smith{
> print $global || 'undef', "\n";
> }
>
> This prints 'undef' when run in my local Perl 5.6 installation. How
> can the body of smith() be interpreted without the assignment of 3 to
> $global having taken place? The funny thing is that I tried running
> this using a Perl 5.5.3 installation and printed '3'.
On my machine, 5.8.0, 5.6.1 and 5.00503 all behave identically with
respect to the above code. That is, they print 'undef'. You possibly ran
different code on each.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 10 Feb 2003 23:39:36 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Scope of a global lexical
Message-Id: <pan.2003.02.10.22.35.25.913946@aursand.no>
On Mon, 10 Feb 2003 11:49:35 -0800, Greg wrote:
> smith();
>
> my $global = 3;
$global isn't initialized when you call smith(). Hence, smith() won't
know it's value.
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: 09 Feb 2003 01:40:51 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Script Problem - PLEASE help
Message-Id: <slrnb4bcd2.sb.abigail@alexandra.abigail.nl>
Babyface (stuandju@NOSPAMaberhonddu1.fsnet.co.uk) wrote on MMMCDXLVI
September MCMXCIII in <URL:news:b1u0n4$md0$1@news7.svr.pol.co.uk>:
-: Are there experts who'd be willing to look at a script for me to see what
-: the problem is. It's the YABB discussion board script. (they are not much
-: help) My web host Technical support have looked through it a number of
-: times but can see no reason why it wouldn't work. I have been through all
-: the troubleshooting bits and pieces. I havent changed any of the script
-: other than what I was instructed to do.
That would be EUR 200/hour, 4 hours minimum.
Abigail
--
print 74.117.115.116.32;
print 97.110.111.116.104.101.114.32;
print 80.101.114.108.32;
print 72.97.99.107.101.114.10;
------------------------------
Date: 7 Feb 2003 08:38:07 -0800
From: orljustin@aol.com (OJ)
Subject: Re: Simple regexp gots me stuck...
Message-Id: <77d3a68b.0302070838.712b6c45@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<b1vrbe$87u$1@mamenchi.zrz.TU-Berlin.DE>...
> OJ <orljustin@aol.com> wrote in comp.lang.perl.misc:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > news:<b1ui9j$bbg$3@mamenchi.zrz.TU-Berlin.DE>...
> > > OJ <orljustin@aol.com> wrote in comp.lang.perl.misc:
> > > > Heya,
> > > >
> > > > Can't figure out why this does not return the image path only in $1.
> Any clue?
> > > >
> > > > #!/usr/local/bin/perl
> > > >
> > > > $t = "img SRC=\"/Images/tmp.gif\" ALT=\"avast ye scurvy dogs\"";
> > > > $t=~/src.*?=.*?"(.*)[^ ]?"/i;
> > > ^^^^
> > > The underlined part captures everything after '"' up to the last '"' in
> > > a greedy way, since the following "[^ ]?" is optional.
> >
> > Hey again,
> >
> > Why is it optional?
>
> Because of the final "?".
>
> > I was just going for "the first quote with no
> > white space before it. Actually, I tried your suggestion below
> > initially, but got the same result.
>
> That's because my suggestion is wrong. It should have been
>
> $t=~/src.*?=.*?"(.*?)"/i;
>
>
> Anno
A-cha! Tx.
oj
------------------------------
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.
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 V10 Issue 4541
***************************************