[22126] in Perl-Users-Digest
Perl-Users Digest, Issue: 4348 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 6 00:10:36 2003
Date: Sun, 5 Jan 2003 21:10:09 -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 Sun, 5 Jan 2003 Volume: 10 Number: 4348
Today's topics:
very easy string Q. <darkage@freeshellzzzz.org>
Re: very easy string Q. <mgjv@tradingpost.com.au>
Re: very easy string Q. (Daniel S. Lewart)
Re: very easy string Q. <darkage@freeshellzzzz.org>
Re: very easy string Q. <darkage@freeshellzzzz.org>
Re: very easy string Q. <darkage@freeshellzzzz.org>
Re: What are the software editor/creative choices for P (Tad McClellan)
Re: What are the software editor/creative choices for P (Tad McClellan)
Re: What are the software editor/creative choices for P <jbarrington@comcast.non>
Re: What are the software editor/creative choices for P (Tad McClellan)
Re: While loop (Tad McClellan)
Re: While loop <No_Mail_Address@cox.net>
Re: While loop <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 6 Jan 2003 12:58:34 +1100
From: "^darkage" <darkage@freeshellzzzz.org>
Subject: very easy string Q.
Message-Id: <avansa$h49$1@perki.connect.com.au>
easy string problem. when I execute this the wget cmd runs but the ftp
directory is seperated from the ".zip" extension.
ie. it exec's wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239
instead of wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239.zip Im no
sure of the right way to append the .zip onto the string.
#!/usr/bin/perl -w
use strict;
my(@hold_all, $filename, $search, $line, @dattemp, $datversion, $cmd, $cmd1,
@cmd, @newcmd, @updatecmd, $newcmd);
$filename = './update.ini';
open(FILE, "$filename") || die "can't open file $filename $!";
@hold_all = <FILE>;
chomp @hold_all;
close FILE;
foreach $line (@hold_all)
{
if ($line =~ /DATVersion/)
{
@dattemp = split /\=/, $line;
}
}
$datversion = $dattemp[1];
$cmd[0] = ("/usr/local/bin/wget
ftp://ftp.nai.com/pub/datfiles/english/dat-");
$cmd[1] = $datversion;
$newcmd = join("",@cmd);
$updatecmd[0] = $newcmd;
$updatecmd[1] = "zip";
$cmd1=join(".",@updatecmd);
exec $cmd1;
------------------------------
Date: Mon, 06 Jan 2003 02:15:40 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: very easy string Q.
Message-Id: <slrnb1hpmc.307.mgjv@verbruggen.comdyn.com.au>
On Mon, 6 Jan 2003 12:58:34 +1100,
^darkage <darkage@freeshellzzzz.org> wrote:
> easy string problem. when I execute this the wget cmd runs but the ftp
> directory is seperated from the ".zip" extension.
>
> ie. it exec's wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239
> instead of wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239.zip Im no
> sure of the right way to append the .zip onto the string.
>
>
> #!/usr/bin/perl -w
[SNIP]
Why are you doing all this stuff with arrays and such? Don't you know
that Perl can concatenate strings?
Also, declaring all your variables at the top is not really useful.
You should scope them more locally. A replacement for your program
that is a bit more organised:
#!/usr/bin/perl -w
use strict;
my $datversion = get_datversion("./update.ini")
or die "Couldn't get DAT version\n";
exec("/usr/local/bin/wget",
"ftp://ftp.nai.com/pub/datfiles/english/dat-$datversion.zip");
sub get_datversion
{
my $filename = shift;
if (open my $fh, $filename)
{
while (my $line = <$fh>)
{
chomp $line;
return (split /=/, $line)[1] if $line =~ /DATVersion/;
}
}
return;
}
Martien
--
|
Martien Verbruggen | +++ Out of Cheese Error +++ Reinstall
Trading Post Australia | Universe and Reboot +++
|
------------------------------
Date: Mon, 06 Jan 2003 02:36:20 GMT
From: lewart@uiuc.edu (Daniel S. Lewart)
Subject: Re: very easy string Q.
Message-Id: <EY5S9.11499$Vf3.119951@vixen.cso.uiuc.edu>
^darkage <darkage@freeshellzzzz.org> writes:
> easy string problem. when I execute this the wget cmd runs but the ftp
> directory is seperated from the ".zip" extension.
> ie. it exec's wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239
> instead of wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239.zip Im no
> sure of the right way to append the .zip onto the string.
> #!/usr/bin/perl -w
> use strict;
> my(@hold_all, $filename, $search, $line, @dattemp, $datversion, $cmd, $cmd1,
> @cmd, @newcmd, @updatecmd, $newcmd);
> $filename = './update.ini';
> open(FILE, "$filename") || die "can't open file $filename $!";
> @hold_all = <FILE>;
> chomp @hold_all;
> close FILE;
> foreach $line (@hold_all)
> {
> if ($line =~ /DATVersion/)
> {
> @dattemp = split /\=/, $line;
> }
> }
> $datversion = $dattemp[1];
> $cmd[0] = ("/usr/local/bin/wget
> ftp://ftp.nai.com/pub/datfiles/english/dat-");
> $cmd[1] = $datversion;
> $newcmd = join("",@cmd);
> $updatecmd[0] = $newcmd;
> $updatecmd[1] = "zip";
> $cmd1=join(".",@updatecmd);
> exec $cmd1;
If update.ini has a line like "DATVersion = 4240", what will @dattemp be?
You should learn how to debug by reading the perldebtut and perldebug
man pages. Below is a complete rewrite.
Cheers,
Daniel Lewart
lewart@uiuc.edu
-------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
my $filename = 'update.ini';
my $datversion;
open(FILE, $filename) || die "can't open file $filename $!";
while (<FILE>) {
last if ($datversion) = /^DATVersion\s*=\s*(.*)/;
}
close FILE;
my $url = "ftp://ftp.nai.com/pub/datfiles/english/dat-$datversion.zip";
exec "/usr/local/bin/wget", $url;
-------------------------------------------------------------------------------
------------------------------
Date: Mon, 6 Jan 2003 15:33:50 +1100
From: "^darkage" <darkage@freeshellzzzz.org>
Subject: Re: very easy string Q.
Message-Id: <avb0vf$pks$1@perki.connect.com.au>
Thnakyou both methods work good, except for one thing. the url turns out to
be, ftp://ftp.nai.com/pub/datfiles/english/dat-$datversion\dat-4240?.zip I
need to take out the ?.
It might help to know the contents of the update.ini below, here it has the
version of DAT file. the url for update.ini never changes. probably
should grap the .zip as well from here.
[SuperDat-IA32]
EngineVersion=4160
DATVersion=4240
FileName=sdat4240.exe
FileSize=4504091
Checksum=DAA7,E570
[ZIP]
EngineVersion=0
DATVersion=4240
FileName=dat-4240.zip
FilePath=/pub/antivirus/datfiles/4.x/
FileSize=2483658
Checksum=E95F,F895
MD5=394188c59eb36051f1482cfb214e2333
[Incremental]
EngineVersion=0
DATVersion=4240
FileName=delta.ini
FileSize=1309
Checksum=8EA0,0E56
[Engine-LINUX]
EngineVersion=4160
FileName=elnx4160.zip
FileSize=888430
Checksum=5019,9DF8
MD5=66ea8eef6f548c78ee1095748371eb98
FilePath=/pub/antivirus/engine/4.x/
[Engine-NETWARE]
EngineVersion=4160
FileName=nw4160.zip
FileSize=2446891
Checksum=3300,29EB
MD5=6b760a8d6d311962de3ec9aaaf2c9747
FilePath=/pub/antivirus/engine/4.x/
~
"Daniel S. Lewart" <lewart@uiuc.edu> wrote in message
news:EY5S9.11499$Vf3.119951@vixen.cso.uiuc.edu...
> ^darkage <darkage@freeshellzzzz.org> writes:
>
> > easy string problem. when I execute this the wget cmd runs but the
ftp
> > directory is seperated from the ".zip" extension.
> > ie. it exec's wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239
> > instead of wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239.zip
Im no
> > sure of the right way to append the .zip onto the string.
>
> > #!/usr/bin/perl -w
>
> > use strict;
> > my(@hold_all, $filename, $search, $line, @dattemp, $datversion, $cmd,
$cmd1,
> > @cmd, @newcmd, @updatecmd, $newcmd);
>
> > $filename = './update.ini';
>
> > open(FILE, "$filename") || die "can't open file $filename $!";
> > @hold_all = <FILE>;
> > chomp @hold_all;
> > close FILE;
>
> > foreach $line (@hold_all)
> > {
> > if ($line =~ /DATVersion/)
> > {
> > @dattemp = split /\=/, $line;
> > }
> > }
> > $datversion = $dattemp[1];
> > $cmd[0] = ("/usr/local/bin/wget
> > ftp://ftp.nai.com/pub/datfiles/english/dat-");
> > $cmd[1] = $datversion;
> > $newcmd = join("",@cmd);
>
> > $updatecmd[0] = $newcmd;
> > $updatecmd[1] = "zip";
> > $cmd1=join(".",@updatecmd);
> > exec $cmd1;
>
> If update.ini has a line like "DATVersion = 4240", what will @dattemp be?
> You should learn how to debug by reading the perldebtut and perldebug
> man pages. Below is a complete rewrite.
>
> Cheers,
> Daniel Lewart
> lewart@uiuc.edu
> --------------------------------------------------------------------------
-----
> #!/usr/bin/perl -w
>
> use strict;
>
> my $filename = 'update.ini';
>
> my $datversion;
> open(FILE, $filename) || die "can't open file $filename $!";
> while (<FILE>) {
> last if ($datversion) = /^DATVersion\s*=\s*(.*)/;
> }
> close FILE;
>
> my $url = "ftp://ftp.nai.com/pub/datfiles/english/dat-$datversion.zip";
> exec "/usr/local/bin/wget", $url;
> --------------------------------------------------------------------------
-----
------------------------------
Date: Mon, 6 Jan 2003 15:37:32 +1100
From: "^darkage" <darkage@freeshellzzzz.org>
Subject: Re: very easy string Q.
Message-Id: <avb16c$po5$1@perki.connect.com.au>
pls disregard last, it works perfect (: not sure why the ? was getting in
there. but its not in there now. (: many thanks (:
"Daniel S. Lewart" <lewart@uiuc.edu> wrote in message
news:EY5S9.11499$Vf3.119951@vixen.cso.uiuc.edu...
> ^darkage <darkage@freeshellzzzz.org> writes:
>
> > easy string problem. when I execute this the wget cmd runs but the
ftp
> > directory is seperated from the ".zip" extension.
> > ie. it exec's wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239
> > instead of wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239.zip
Im no
> > sure of the right way to append the .zip onto the string.
>
> > #!/usr/bin/perl -w
>
> > use strict;
> > my(@hold_all, $filename, $search, $line, @dattemp, $datversion, $cmd,
$cmd1,
> > @cmd, @newcmd, @updatecmd, $newcmd);
>
> > $filename = './update.ini';
>
> > open(FILE, "$filename") || die "can't open file $filename $!";
> > @hold_all = <FILE>;
> > chomp @hold_all;
> > close FILE;
>
> > foreach $line (@hold_all)
> > {
> > if ($line =~ /DATVersion/)
> > {
> > @dattemp = split /\=/, $line;
> > }
> > }
> > $datversion = $dattemp[1];
> > $cmd[0] = ("/usr/local/bin/wget
> > ftp://ftp.nai.com/pub/datfiles/english/dat-");
> > $cmd[1] = $datversion;
> > $newcmd = join("",@cmd);
>
> > $updatecmd[0] = $newcmd;
> > $updatecmd[1] = "zip";
> > $cmd1=join(".",@updatecmd);
> > exec $cmd1;
>
> If update.ini has a line like "DATVersion = 4240", what will @dattemp be?
> You should learn how to debug by reading the perldebtut and perldebug
> man pages. Below is a complete rewrite.
>
> Cheers,
> Daniel Lewart
> lewart@uiuc.edu
> --------------------------------------------------------------------------
-----
> #!/usr/bin/perl -w
>
> use strict;
>
> my $filename = 'update.ini';
>
> my $datversion;
> open(FILE, $filename) || die "can't open file $filename $!";
> while (<FILE>) {
> last if ($datversion) = /^DATVersion\s*=\s*(.*)/;
> }
> close FILE;
>
> my $url = "ftp://ftp.nai.com/pub/datfiles/english/dat-$datversion.zip";
> exec "/usr/local/bin/wget", $url;
> --------------------------------------------------------------------------
-----
------------------------------
Date: Mon, 6 Jan 2003 15:48:11 +1100
From: "^darkage" <darkage@freeshellzzzz.org>
Subject: Re: very easy string Q.
Message-Id: <avb1qb$qir$1@perki.connect.com.au>
my mistake, problem still there must be with the formatting of the
update.ini, hmm I've tried to chomp the file first.
"Daniel S. Lewart" <lewart@uiuc.edu> wrote in message
news:EY5S9.11499$Vf3.119951@vixen.cso.uiuc.edu...
> ^darkage <darkage@freeshellzzzz.org> writes:
>
> > easy string problem. when I execute this the wget cmd runs but the
ftp
> > directory is seperated from the ".zip" extension.
> > ie. it exec's wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239
> > instead of wget ftp://ftp.nai.com/pub/datfiles/english/dat-4239.zip
Im no
> > sure of the right way to append the .zip onto the string.
>
> > #!/usr/bin/perl -w
>
> > use strict;
> > my(@hold_all, $filename, $search, $line, @dattemp, $datversion, $cmd,
$cmd1,
> > @cmd, @newcmd, @updatecmd, $newcmd);
>
> > $filename = './update.ini';
>
> > open(FILE, "$filename") || die "can't open file $filename $!";
> > @hold_all = <FILE>;
> > chomp @hold_all;
> > close FILE;
>
> > foreach $line (@hold_all)
> > {
> > if ($line =~ /DATVersion/)
> > {
> > @dattemp = split /\=/, $line;
> > }
> > }
> > $datversion = $dattemp[1];
> > $cmd[0] = ("/usr/local/bin/wget
> > ftp://ftp.nai.com/pub/datfiles/english/dat-");
> > $cmd[1] = $datversion;
> > $newcmd = join("",@cmd);
>
> > $updatecmd[0] = $newcmd;
> > $updatecmd[1] = "zip";
> > $cmd1=join(".",@updatecmd);
> > exec $cmd1;
>
> If update.ini has a line like "DATVersion = 4240", what will @dattemp be?
> You should learn how to debug by reading the perldebtut and perldebug
> man pages. Below is a complete rewrite.
>
> Cheers,
> Daniel Lewart
> lewart@uiuc.edu
> --------------------------------------------------------------------------
-----
> #!/usr/bin/perl -w
>
> use strict;
>
> my $filename = 'update.ini';
>
> my $datversion;
> open(FILE, $filename) || die "can't open file $filename $!";
> while (<FILE>) {
> last if ($datversion) = /^DATVersion\s*=\s*(.*)/;
> }
> close FILE;
>
> my $url = "ftp://ftp.nai.com/pub/datfiles/english/dat-$datversion.zip";
> exec "/usr/local/bin/wget", $url;
> --------------------------------------------------------------------------
-----
------------------------------
Date: Sun, 5 Jan 2003 17:43:08 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What are the software editor/creative choices for Perl
Message-Id: <slrnb1hgoc.9ot.tadmc@magna.augustmail.com>
John B. <jbarrington@comcast.non> wrote:
> I was under the
> general impression that CGI was either a product of, a by-product of, or a
> product that could work in conjunction with Perl, and this was due to a few
> references that I had seen within a couple of web sites.
CGI Programming FAQ:
http://www.htmlhelp.org/faq/cgifaq.html
What is CGI?
http://www.htmlhelp.org/faq/cgifaq.1.html#1
[ snip TOFU. Please learn how to quote followups properly ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 5 Jan 2003 17:40:37 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What are the software editor/creative choices for Perl
Message-Id: <slrnb1hgjl.9ot.tadmc@magna.augustmail.com>
John B. <jbarrington@comcast.non> wrote:
> I'm a new webmaster for a smaller site that wants to investigate possible
> uses for Perl (or CGI ?).
Perl is not CGI. CGI is not Perl.
The Common Gateway Interface is an _interface_. You can choose to
write your CGI programs in just about any programming language, as
long as you write it so that it follows that interface.
90% (a WAG) of the world happens to choose Perl for writing their
CGI programs, only because it is a "good fit" for the kind of
tasks you'd want to perform in a CGI program. You can write CGI
programs in Java or Visual Basic if you so choose.
You should have a look at the Perl Frequently Asked Questions
that mention the CGI:
perldoc -q CGI
Where can I learn about CGI or Web programming in Perl?
What is the correct form of response from a CGI script?
How can I get better error messages from a CGI program?
How do I make sure users can't enter values into a form
that cause my CGI script to do bad things?
How do I decode a CGI form?
> I have some background in most computer languages,
> but no experience with Perl and it's code within an internet site.
Perl had a happy and widespread existance before the WWW was
even invented.
Web stuff is only one application area for Perl.
I've programmed in Perl every day for about 8 years, and have
never written a CGI program (other than as a hobbyist).
> I've ordered a couple of books to study, but I'd like to know about some of
> the better software that's available.
All you need is a programmer's editor.
vi(m?) or emacs are what most people use.
> I'm sure that I'll want to try and
> design and test code as I learn, so what are the better/best freeware,
> shareware, or commercial software choices that are reasonable on costs, easy
> to learn and understand, and to work with.
You don't need any software apart from an editor and perl itself
(and a web server if you want to use Perl in a CGI environment).
If you need some software, _write it_ using Perl. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 5 Jan 2003 20:56:12 -0500
From: "John B." <jbarrington@comcast.non>
Subject: Re: What are the software editor/creative choices for Perl
Message-Id: <PvycndaxkdGgf4WjXTWc3A@comcast.com>
Thanks for the two informative messages and the links.
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb1hgjl.9ot.tadmc@magna.augustmail.com...
> John B. <jbarrington@comcast.non> wrote:
>
> > I'm a new webmaster for a smaller site that wants to investigate
possible
> > uses for Perl (or CGI ?).
>
>
> Perl is not CGI. CGI is not Perl.
>
> The Common Gateway Interface is an _interface_. You can choose to
> write your CGI programs in just about any programming language, as
> long as you write it so that it follows that interface.
>
> 90% (a WAG) of the world happens to choose Perl for writing their
> CGI programs, only because it is a "good fit" for the kind of
> tasks you'd want to perform in a CGI program. You can write CGI
> programs in Java or Visual Basic if you so choose.
>
> You should have a look at the Perl Frequently Asked Questions
> that mention the CGI:
>
> perldoc -q CGI
>
> Where can I learn about CGI or Web programming in Perl?
>
> What is the correct form of response from a CGI script?
>
> How can I get better error messages from a CGI program?
>
> How do I make sure users can't enter values into a form
> that cause my CGI script to do bad things?
>
> How do I decode a CGI form?
>
>
> > I have some background in most computer languages,
> > but no experience with Perl and it's code within an internet site.
>
>
> Perl had a happy and widespread existance before the WWW was
> even invented.
>
> Web stuff is only one application area for Perl.
>
> I've programmed in Perl every day for about 8 years, and have
> never written a CGI program (other than as a hobbyist).
>
>
> > I've ordered a couple of books to study, but I'd like to know about some
of
> > the better software that's available.
>
>
> All you need is a programmer's editor.
>
> vi(m?) or emacs are what most people use.
>
>
> > I'm sure that I'll want to try and
> > design and test code as I learn, so what are the better/best freeware,
> > shareware, or commercial software choices that are reasonable on costs,
easy
> > to learn and understand, and to work with.
>
>
> You don't need any software apart from an editor and perl itself
> (and a web server if you want to use Perl in a CGI environment).
>
> If you need some software, _write it_ using Perl. :-)
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Sun, 5 Jan 2003 20:48:30 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What are the software editor/creative choices for Perl
Message-Id: <slrnb1hrju.adn.tadmc@magna.augustmail.com>
John B. <jbarrington@comcast.non> wrote:
> Thanks
You can thank me by not disregarding that
Please learn how to quote followups properly
part. :-)
> for the two informative messages and the links.
Here's another one:
http://www.geocities.com/nnqweb/nquote.html
[snip 80 lines of TOFU (again)]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 5 Jan 2003 17:15:22 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: While loop
Message-Id: <slrnb1hf4a.9ot.tadmc@magna.augustmail.com>
Michael Peuser \(h\) <post@mpeuser.de> wrote:
> "Fred" <No_Mail_Address@cox.net> schrieb im Newsbeitrag
> news:3E186038.4313B1C1@cox.net...
>> local $/ ;
>
> This sets input to "slurp" mode - the whole file will be input,
> thus 'while (<IN>)' is somewhat irritating.
>> s/(<pre>.+?)<br>(.+?<\/pre>)/$1\n$2/sg;
> Try the following code:
> while ($line =~ s!(<pre>.+?)<br>(.+?</pre>)!$1\n$2!gs) {};
Your while is irritating too, just
s!(<pre>.+?)<br>(.+?</pre>)!$1\n$2!gs;
will do the same thing...
How is your pattern an improvement?
It is functionaly equivalent to what he already had.
Try it with:
$line = "<pre>foobar</pre><br><pre>preformated</pre>\n";
It will replace the <br> even though it is NOT inside a <pre>...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 06 Jan 2003 01:38:07 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: While loop
Message-Id: <3E18DE92.43533E4C@cox.net>
Tad McClellan wrote:
>
> Fred <No_Mail_Address@cox.net> wrote:
> > Fred wrote:
>
> [ wants to replace <br> but only inside of <pre> ]
>
> > Any ideas for a faster solution?
>
> I dunno if this is faster or not, use the Benchmark module
> to answer such questions:
>
> s#(<pre>.*?</pre>)# $a=$1; $a =~ s/<br>/\n/gi; $a #gsie;
>
> --
> Tad McClellan SGML consulting
Do not need Benchmark testing to see the difference: your code about
0.25 sec vs. my code 28.3 sec (your code about 100 times faster),
resulting html files identical
Thank you,
Fred
------------------------------
Date: Mon, 06 Jan 2003 01:47:50 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: While loop
Message-Id: <af5S9.6044$Db.4105@nwrddc02.gnilink.net>
Fred wrote:
> "Jürgen Exner" wrote:
>>
>> Moshe Jacobson wrote:
>>> Fred had nothing better to do than to say:
>>>> I use the following code, but the second while loops forever until
>>>> I stop with Ctrl+Brk:
>>>
>>>> local $/ ;
>>>> while (<IN>){
>>>> while (m/<pre>.+<br>.+<\/pre>/is) {
>>>> s/(<pre>.+?)<br>(.+?<\/pre>)/$1\n$2/sg;
>>>> }
>>>> print $_ ;
>>>> }
>>>
>>> you should just have an if instead of a while in the inner loop and
>>> it'll be fine. The while is a loop. Why are you looping over the
>>> same line? You're already looping over each line with the outer
>>> loop.
>>
>> While this is true and your advice should solve the OP's problem, I
>> still wonder why the inner loop doesn't terminate.
>> After executing the substitute there should not be any and <br>
>> left.......
>>
>> .... wait a second. While writing the above it became quite clear to
>> me. There won't be any "<br"> left but what about "<BR>"? The inner
>> loop condition will match a capital "<BR>" but the substitute
>> command will not replace it. Thereby the condition will never become
>> false.
>>
>> jue
>
> 1.) I checked the html file and there are only <br> and no <BR>.
Hmm, then I have no idea why the inner loop doesn't terminate.
> 2.) If I replace the inner while by if then there is only one single
> replacement in every <pre> ...</pre> string. Not what I want.
Oh, yes, I see. The problem is that you are matching the whole chunk inside
of the <pre> tags in one step.
In that case I wonder if maybe splitting your string into the part before
the <pre>, between <pre> and </pre> and after </pre> would be easier. Then
just do a single global substitute on the middle part and re-assemble your
text.
No wait, that doesn't work either, because you can have multiple <pre>
sections in your string.
You know what, I would just dump this whole approach and use HTML::Parser
instead.
jue
------------------------------
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 4348
***************************************