[25468] in Perl-Users-Digest
Perl-Users Digest, Issue: 7713 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 30 18:05:32 2005
Date: Sun, 30 Jan 2005 15:05:11 -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, 30 Jan 2005 Volume: 10 Number: 7713
Today's topics:
Re: Error in command line <wksmith@optonline.net>
Re: Error in command line <1usa@llenroc.ude.invalid>
Re: Error in command line (Anno Siegel)
Re: Error in command line <news@chaos-net.de>
Re: FAQ 4.16 How can I find the Julian Day? (Anno Siegel)
Re: Just wondering - variables in html templates <flavell@ph.gla.ac.uk>
Re: Just wondering - variables in html templates <1usa@llenroc.ude.invalid>
Re: Perl loops should use break, not last <gargoyle@no.spam>
Re: Perl loops should use break, not last <nodj.athensspam@surfeu.fi.useless>
Re: Perl loops should use break, not last (Anno Siegel)
Re: Perl loops should use break, not last <ask@me.com>
Re: Perl loops should use break, not last <ask@me.com>
Re: Perl loops should use break, not last <gargoyle@no.spam>
Re: Perl loops should use break, not last <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Perl loops should use break, not last <gargoyle@no.spam>
Re: Perl loops should use break, not last (Anno Siegel)
Re: Perl loops should use break, not last <1usa@llenroc.ude.invalid>
Re: Perl loops should use break, not last <abigail@abigail.nl>
Re: Perl loops should use break, not last <abigail@abigail.nl>
Re: Perl loops should use break, not last <abigail@abigail.nl>
Re: Perl loops should use break, not last <No_4@dsl.pipex.com>
Re: Perl loops should use break, not last <gargoyle@no.spam>
Re: Print question <edgrsprj@ix.netcom.com>
Re: Regular Expression Question on /i (Anno Siegel)
Re: Regular Expression Question on /i <nospam-abuse@ilyaz.org>
Re: Regular Expression Question on /i (Anno Siegel)
Replace text inside html tags? squash@peoriadesignweb.com
Re: Replace text inside html tags? <1usa@llenroc.ude.invalid>
Re: Replace text inside html tags? <noreply@gunnar.cc>
Re: Replace text inside html tags? <spamtrap@dot-app.org>
Re: what's OOP's jargons and complexities? <crabak@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 30 Jan 2005 11:35:13 -0500
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Error in command line
Message-Id: <918Ld.2790$qo6.865@fe12.lga>
"Rajendra Pai" <rs.pai@sbi.co.in> wrote in message
news:33b0685e.0501300304.3ad5ec53@posting.google.com...
> Hi,
>
> I have ActivePerl installed in a Windows XP Machine.
>
> When I type the following line at the command prompt (this is just an
> example):
> perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19
perl -le "print qq(PRIME) if (1 x shift) !~ /^(11+)\1+$/" 19
> the response I get is:
> Can't find string terminator "'" anywhere before EOF at -e line 1.
>
> (I am getting similar error messages for 'perl -lane' type of commands
> also. The example shown above is taken from a tutorial)
>
> I am not able to figure out what is wrong. I have tried doing both web
> and group searches in google. Please help me. I am a newbie and maybe
> missing something very obvious.
Windows still requires DOS syntax in command lines.
You must use double quotes around parameters with
special characters. This prevents the use of
double quotes in perl command line commands.
In this case, single quotes around 'PRIME' would
work, but it is a good idea to use the q family
of operators within commands on the command line
because they will never be interpreted
by windows.
Bill
------------------------------
Date: Sun, 30 Jan 2005 16:54:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Error in command line
Message-Id: <Xns95EE792B68BDDasu1cornelledu@127.0.0.1>
rs.pai@sbi.co.in (Rajendra Pai) wrote in news:33b0685e.0501300304.3ad5ec53
@posting.google.com:
> Hi,
>
> I have ActivePerl installed in a Windows XP Machine.
>
> When I type the following line at the command prompt (this is just an
> example):
> perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19
> the response I get is:
> Can't find string terminator "'" anywhere before EOF at -e line 1.
While I find that the cmd.exe shell is fairly workable, its handling of
various quotation marks leaves a lot to be desired.
My brain has become accustomed to converting the above to:
perl -le "print q{PRIME} if (1 x shift) !~ /^(11+)\1+$/" 19
In this particular case, you cold have also done:
perl -le "print -PRIME if (1 x shift) !~ /^(11+)\1+$/" 19
if you don't mind the leading dash.
On the other hand, you are just using a one liner on the command line
Sinan
------------------------------
Date: 30 Jan 2005 17:05:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Error in command line
Message-Id: <ctj45a$cp2$1@mamenchi.zrz.TU-Berlin.DE>
Martin Kissner <news@chaos-net.de> wrote in comp.lang.perl.misc:
> Rajendra Pai wrote :
> > Hi,
> >
> > I have ActivePerl installed in a Windows XP Machine.
> >
> > When I type the following line at the command prompt (this is just an
> > example):
> > perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19
> > the response I get is:
> > Can't find string terminator "'" anywhere before EOF at -e line 1.
>
> On my computer the above line prints 'PRIME' and exits with no error.
> However, I can not imagine what the trailing '19' is for.
It's an argument for shift() to pick up.
Anno
------------------------------
Date: Sun, 30 Jan 2005 19:05:03 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Error in command line
Message-Id: <slrncvq8ef.d77.news@maki.homeunix.net>
Anno Siegel wrote :
> Martin Kissner <news@chaos-net.de> wrote in comp.lang.perl.misc:
>> Rajendra Pai wrote :
>> > perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19
>>
>> On my computer the above line prints 'PRIME' and exits with no error.
>> However, I can not imagine what the trailing '19' is for.
>
> It's an argument for shift() to pick up.
Oh - now I see a little clearer.
Thanks.
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: 30 Jan 2005 19:30:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 4.16 How can I find the Julian Day?
Message-Id: <ctjcjt$h4n$3@mamenchi.zrz.TU-Berlin.DE>
Jim Keenan <jkeen_via_google@yahoo.com> wrote in comp.lang.perl.misc:
> PerlFAQ Server wrote:
> >
> > 4.16: How can I find the Julian Day?
> >
> > [snip]
> >
> > There is too many details and much confusion on this issue to cover in
>
> s/is/are/ for number agreement between verb and predicate nominative.
Doesn't work:
There are too many details and much confusion ...
Better:
There is too much detail and confusion ...
Anno
------------------------------
Date: Sun, 30 Jan 2005 16:14:05 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Just wondering - variables in html templates
Message-Id: <Pine.LNX.4.61.0501301612470.2104@ppepc56.ph.gla.ac.uk>
On Sun, 30 Jan 2005, Seansan blurted out atop a fullquote:
> Sherm start a hobby
I knew you'd be finding your way into the killfile before long, when
I spotted some of your earlier wibble.
bye.
------------------------------
Date: Sun, 30 Jan 2005 16:47:48 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Just wondering - variables in html templates
Message-Id: <Xns95EE780B2CE2asu1cornelledu@127.0.0.1>
"Seansan" <sheukels=cuthere=@yahooo.co.uk> wrote in
news:41fcf599$0$28979$e4fe514c@news.xs4all.nl:
> Sherm start a hobby
Seansan, meet Xah Lee ... Xah Lee, meet Seansan.
*PLONK*
;)
------------------------------
Date: Sun, 30 Jan 2005 17:38:25 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: Perl loops should use break, not last
Message-Id: <lY8Ld.3401$qJ3.1211@bignews1.bellsouth.net>
On 2005-01-30, Jussi Mononen <nodj.athensspam@surfeu.fi.useless> wrote:
> That is just prone to errors. What if you had to add some functionality into
> one of the blocks? You would have to add the braces and forgetting to add
> them is easy.
Then throw compiler error, if it sees more than one statement w/o
braces.
Some people don't like the way C does it, but some do. And Perl is
about choices.
Otherwise a similar argument could be used against this:
if ( substr($foo, 0, 4) == BAR & BAZ and $xyz ^ x0ffff > $abc ) {
launch_missiles();
}
What happens if you make a change here that affect operator precedence?
It means you can screw up. But Perl allows it. Perl respect my free
will to code how I want. And that's why I respect Perl. :-)
Let people read perlstyle man page and make their decision. If you want
anal-rententive language, try python maybe.
------------------------------
Date: Sun, 30 Jan 2005 20:25:08 +0200
From: "Jussi Mononen" <nodj.athensspam@surfeu.fi.useless>
Subject: Re: Perl loops should use break, not last
Message-Id: <ctj8mh$qlq$1@nyytiset.pp.htv.fi>
"gargoyle" <gargoyle@no.spam> kirjoitti
viestissä:lY8Ld.3401$qJ3.1211@bignews1.bellsouth.net...
>> That is just prone to errors. What if you had to add some functionality
>> into
>> one of the blocks? You would have to add the braces and forgetting to add
>> them is easy.
>
> Then throw compiler error, if it sees more than one statement w/o
> braces.
That's just what Perl does if you don't use braces with if-statement :-D
You want to change Perl syntax to suit your personal preferences, although
by definition the if-statement executes a {block} of code and needs braces
because of that.
How would the compiler know what you meant if you are not using
else-statements?
if( $hungry )
eat();
drink();
if( $hungry ){
eat();
drink();
}
> Otherwise a similar argument could be used against this:
>
> if ( substr($foo, 0, 4) == BAR & BAZ and $xyz ^ x0ffff > $abc ) {
> launch_missiles();
> }
>
> What happens if you make a change here that affect operator precedence?
> It means you can screw up. But Perl allows it. Perl respect my free
> will to code how I want. And that's why I respect Perl. :-)
That is not related to syntax, it is just a logical error. You can code as
many logical errors as you wish into the if-clause, within the syntax of
course. If you force certain rules on syntax, you can prevent some logical
errors caused by vague syntax.
> Let people read perlstyle man page and make their decision. If you want
> anal-rententive language, try python maybe.
Preventing logical errors with syntax is not a style-issue, me thinks :-)
All this is IMO of course
/jUSSi
ps. I love C and earn my living with it and Perl.
------------------------------
Date: 30 Jan 2005 19:14:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl loops should use break, not last
Message-Id: <ctjbm6$h4n$2@mamenchi.zrz.TU-Berlin.DE>
gargoyle <gargoyle@no.spam> wrote in comp.lang.perl.misc:
> On 2005-01-30, Jussi Mononen <nodj.athensspam@surfeu.fi.useless> wrote:
> > That is just prone to errors. What if you had to add some functionality into
> > one of the blocks? You would have to add the braces and forgetting to add
> > them is easy.
>
> Then throw compiler error, if it sees more than one statement w/o
> braces.
You can't throw an error -- it is perfectly legit to have an unconditional
statement after a conditional one.
> Some people don't like the way C does it, but some do. And Perl is
> about choices.
Not about bad choices. The real problem with brace-less statements under
"if" is an different one. It happens with nested "if"s and a following
"else":
if ( $alive ) if ( $well ) get_up() else stay_put();
is essentially ambiguous. You can't indicate whether "else" is an alternative
to the first condition:
if ( $alive ) {
if ( $well ) {
get_up();
}
} else {
stay_put();
}
or to the second one:
if ( $alive ) {
if ( $well ) {
get_up();
} else {
stay_put();
}
}
It makes a difference, and the ambiguity can only be resolved "by force",
there is no "natural" resolution. With braces, there can't be any doubt.
Early compiler designs (Pascal, C, Algol) tended to ignore this ambiguity.
Later ones (Modula2, Perl, not sure about Algol68) decided to enforce
delimiters for this very reason. That was progress, there's no reason
to go back behind it.
Anno
------------------------------
Date: Sun, 30 Jan 2005 19:43:12 -0000
From: "Jeremy Morton" <ask@me.com>
Subject: Re: Perl loops should use break, not last
Message-Id: <41fd39a4$0$26027$fa0fcedb@news.zen.co.uk>
"Abigail" <abigail@abigail.nl> wrote in message
news:slrncvo947.a9.abigail@alexandra.abigail.nl...
> Matija Papec (perl@my-header.org) wrote on MMMMCLXIX September MCMXCIII
> in <URL:news:dmcnv0tclggthkelp49b0uf0fj50uiv6o8@4ax.com>:
> ;; X-Ftn-To: Jeremy Morton
> ;;
> ;; "Jeremy Morton" <ask@me.com> wrote:
> ;; >Probably been mentioned before but I fail to see why Perl changed the
> ;; >'break' keyword to 'last', in loops. Bear with me on this - it seems
> ;; >semantically more accurate to say 'break' - you're immediately
> breaking out
> ;; >of the loop. 'last' makes it sound like the current loop will be the
> last,
> ;; >but not that the execution should be stopped immediately, whereas
> break
> ;; >makes it sound like the latter.
> ;;
> ;; I'm guessing, "last" was picked because it's short and it sounds good
> along
> ;; with "next". Further, "break" could blur things for C people as his
> ;; "continue" friend is already used for something else.
>
>
> One of the reasons why the three loop control constructs are named
> 'last', 'redo' and 'next' is that they are all the same length.
>
> One of the reasons 'last' isn't called 'break' is that 'last' isn't
> the same as 'break'. 'break' breaks the current loop - while 'last'
> takes an optional argument, indicating the top level loop that will
> be exited.
Hang on, are you saying 'break' has a meaning in Perl? I didn't think it
was reserved.
In addition, i'm not sure what you're getting at re: 'last' taking an
argument. 'break' could just as easily take an optional argument and mean
the same thing.
--
Best regards,
Jeremy Morton (Jez)
------------------------------
Date: Sun, 30 Jan 2005 19:50:01 -0000
From: "Jeremy Morton" <ask@me.com>
Subject: Re: Perl loops should use break, not last
Message-Id: <41fd3bfd$0$26026$fa0fcedb@news.zen.co.uk>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:ctgif2$seo$1@mamenchi.zrz.TU-Berlin.DE...
> [defunct newsgroup comp.lang.perl trimmed]
>
> Jeremy Morton <ask@me.com> wrote in comp.lang.perl.misc:
>> Probably been mentioned before but I fail to see why Perl changed the
>> 'break' keyword to 'last', in loops. Bear with me on this - it seems
>> semantically more accurate to say 'break' - you're immediately breaking
>> out
>> of the loop. 'last' makes it sound like the current loop will be the
>> last,
>> but not that the execution should be stopped immediately, whereas break
>> makes it sound like the latter.
>
> It makes perfect sense when you name the loops appropriately:
>
> line: while ( <DATA> ) {
> next line if /^\s*#/;
> chomp;
> last line if $_ eq '__END__';
> # ...
> }
>
> What could be clearer? That's the idea behind "next" and "last", even
> if the label is not present.
Heh, well assume that the loop is:
line: while ( <DATA> ) {
next line if /^\s*#/;
chomp;
last line if $_ eq '__END__';
print $_ . "\n";
# ...
}
Personally, i'd find 'break' a lot more semantically sensible there. "If
the line says end, break out NOW." Using 'last' makes it look like "If the
line says end, make this the last loop iteration, eg. Finish this current
iteration and print $_." Oh well.
--
Best regards,
Jeremy Morton (Jez)
------------------------------
Date: Sun, 30 Jan 2005 20:07:49 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: Perl loops should use break, not last
Message-Id: <p8bLd.3625$qJ3.1035@bignews1.bellsouth.net>
On 2005-01-30, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Not about bad choices. The real problem with brace-less statements under
> "if" is an different one. It happens with nested "if"s and a following
> "else":
>
> if ( $alive ) if ( $well ) get_up() else stay_put();
>
> is essentially ambiguous. You can't indicate if "else" is an alternative
> to the first condition:
In C, the else would get parsed as belonging to the innermost if.
I think that's fairly logical, especially if one indents their code
appropriately, eg:
if ( $alive )
if ( $well )
get_up();
else
stay_put();
Whereas this looks more sketchy, at least to my eye:
/* OMG! it smell like python! ;-) */
if ( $alive )
if ( $well )
get_up();
else
stay_put();
Though it's understandable that this can generate confusion. And
personally I wouldn't use ambiguous syntax like that. Even in the
first case, my code would be like this:
if ( $alive ) {
if ( $well )
get_up();
else
stay_put();
}
Just because you can do something doesn't mean you have to or should.
I'd really have liked to just be able to write simple code like this w/o
braces:
if ( $alive )
get_up();
else
stay_put();
And although the ?: operator can sometimes fill in the gap, it doesn't
work so well when there is one of more 'elsif' conditions.
But my name's not Larry Wall, and I don't make decisions around here.
So I'll shutup now. ;-)
------------------------------
Date: Sun, 30 Jan 2005 12:15:47 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Perl loops should use break, not last
Message-Id: <1trvc2x3gk.ln2@goaway.wombat.san-francisco.ca.us>
On 2005-01-30, Jeremy Morton <ask@me.com> wrote:
> Heh, well assume that the loop is:
> line: while ( <DATA> ) {
> next line if /^\s*#/;
> chomp;
> last line if $_ eq '__END__';
> print $_ . "\n";
> # ...
> }
>
> Personally, i'd find 'break' a lot more semantically sensible there. "If
> the line says end, break out NOW." Using 'last' makes it look like "If the
> line says end, make this the last loop iteration, eg. Finish this current
> iteration and print $_." Oh well.
If that's what I wanted, I'd do
line: while ( <DATA> ) {
next line if /^\s*#/;
chomp;
print $_ . "\n";
# ...
last line if $_ eq '__END__';
}
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information
------------------------------
Date: Sun, 30 Jan 2005 20:15:55 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: Perl loops should use break, not last
Message-Id: <%fbLd.3636$qJ3.3221@bignews1.bellsouth.net>
On 2005-01-30, Jussi Mononen <nodj.athensspam@surfeu.fi.useless> wrote:
> You want to change Perl syntax to suit your personal preferences, although
> by definition the if-statement executes a {block} of code and needs braces
> because of that.
If there's no braces, then the block could be comprised of only the very next
statement.
> How would the compiler know what you meant if you are not using
> else-statements?
>
> if( $hungry )
> eat();
> drink();
It would then really mean this:
if( $hungry )
eat();
drink();
Instead of this:
> if( $hungry ){
> eat();
> drink();
> }
------------------------------
Date: 30 Jan 2005 20:26:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl loops should use break, not last
Message-Id: <ctjfsu$jll$1@mamenchi.zrz.TU-Berlin.DE>
Jeremy Morton <ask@me.com> wrote in comp.lang.perl.misc:
>
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:ctgif2$seo$1@mamenchi.zrz.TU-Berlin.DE...
> > [defunct newsgroup comp.lang.perl trimmed]
> >
> > Jeremy Morton <ask@me.com> wrote in comp.lang.perl.misc:
> >> Probably been mentioned before but I fail to see why Perl changed the
> >> 'break' keyword to 'last', in loops. Bear with me on this - it seems
> >> semantically more accurate to say 'break' - you're immediately breaking
> >> out
> >> of the loop. 'last' makes it sound like the current loop will be the
> >> last,
> >> but not that the execution should be stopped immediately, whereas break
> >> makes it sound like the latter.
> >
> > It makes perfect sense when you name the loops appropriately:
> >
> > line: while ( <DATA> ) {
> > next line if /^\s*#/;
> > chomp;
> > last line if $_ eq '__END__';
> > # ...
> > }
> >
> > What could be clearer? That's the idea behind "next" and "last", even
> > if the label is not present.
>
> Heh, well assume that the loop is:
> line: while ( <DATA> ) {
> next line if /^\s*#/;
> chomp;
> last line if $_ eq '__END__';
> print $_ . "\n";
> # ...
> }
>
> Personally, i'd find 'break' a lot more semantically sensible there. "If
> the line says end, break out NOW." Using 'last' makes it look like "If the
> line says end, make this the last loop iteration, eg. Finish this current
^^^^^^^^^
Ah... last time you said "loop" instead of "iteration". That made it
hard to understand. (The *loop* it the whole thing, it can be iterated
any number of times.)
> iteration and print $_." Oh well.
I have already answered to this elsewhere in the thread. To recapitulate,
- I don't see why anyone would assume such an awkward behavior to be
the norm. If you really need it, put the "last" statement last in
the loop.
- I don't see how "break" indicates the actual behavior any better than
"last" does.
Anno
------------------------------
Date: Sun, 30 Jan 2005 20:35:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl loops should use break, not last
Message-Id: <Xns95EE9E9DABCA6asu1cornelledu@127.0.0.1>
gargoyle <gargoyle@no.spam> wrote in
news:p8bLd.3625$qJ3.1035@bignews1.bellsouth.net:
> On 2005-01-30, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> Not about bad choices. The real problem with brace-less statements
>> under "if" is an different one. It happens with nested "if"s and a
>> following "else":
>>
>> if ( $alive ) if ( $well ) get_up() else stay_put();
>>
>> is essentially ambiguous. You can't indicate if "else" is an
>> alternative to the first condition:
>
> In C, the else would get parsed as belonging to the innermost if.
That is what Anno was trying to explain to you. C resolves the ambiguity
by force. There is no a priori reason one interpretation is more logical
than the other.
> I think that's fairly logical,
That is because you have grown used to it.
> especially if one indents their code appropriately, eg:
But there is a language that depends on indentation to figure out what's
going on. It is Python.
> personally I wouldn't use ambiguous syntax like that. Even in the
> first case, my code would be like this:
But your coding preferences are not at issue here.
Sinan.
------------------------------
Date: 30 Jan 2005 22:24:18 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl loops should use break, not last
Message-Id: <slrncvqnki.a9.abigail@alexandra.abigail.nl>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMCLXX
September MCMXCIII in <URL:news:ctjbm6$h4n$2@mamenchi.zrz.TU-Berlin.DE>:
??
?? Early compiler designs (Pascal, C, Algol) tended to ignore this ambiguity.
?? Later ones (Modula2, Perl, not sure about Algol68) decided to enforce
?? delimiters for this very reason. That was progress, there's no reason
?? to go back behind it.
Algol 68 didn't use delimiters around then/else blocks. Algol 68 uses
if ... then ... else ... fi which solves the problem in a different way.
Abigail
--
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
for (??;(??)x??;??)
{??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'
------------------------------
Date: 30 Jan 2005 22:26:27 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl loops should use break, not last
Message-Id: <slrncvqnoj.a9.abigail@alexandra.abigail.nl>
gargoyle (gargoyle@no.spam) wrote on MMMMCLXX September MCMXCIII in
<URL:news:p8bLd.3625$qJ3.1035@bignews1.bellsouth.net>:
;;
;; Just because you can do something doesn't mean you have to or should.
;; I'd really have liked to just be able to write simple code like this w/o
;; braces:
;;
;; if ( $alive )
;; get_up();
;; else
;; stay_put();
;;
;; And although the ?: operator can sometimes fill in the gap, it doesn't
;; work so well when there is one of more 'elsif' conditions.
elsif? elsif? In C? I don't think so.
Abigail
--
@_=map{[$!++,$_^$/]}split$²,"\@\x7Fy~*kde~box*Zoxf*Bkiaox";$\="\r";
$|=++$*;do{($#,$=)=(rand@_,rand@_);@_[$#,$=]=@_[$=,$#]}for($*..@_);
for$:($|..@_-$|){for($|..@_-$:){@_[$_-$|,$_]=@_[$_=>$_-$*]if$_[$_][
$¼]<$_[$_-$*][$®];print+map{$_->[$|]}@_;select$·,$°,$½,0.1}}print$/
------------------------------
Date: 30 Jan 2005 22:32:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl loops should use break, not last
Message-Id: <slrncvqo37.a9.abigail@alexandra.abigail.nl>
Jeremy Morton (ask@me.com) wrote on MMMMCLXX September MCMXCIII in
<URL:news:41fd39a4$0$26027$fa0fcedb@news.zen.co.uk>:
%%
%% > One of the reasons 'last' isn't called 'break' is that 'last' isn't
%% > the same as 'break'. 'break' breaks the current loop - while 'last'
%% > takes an optional argument, indicating the top level loop that will
%% > be exited.
%%
%% Hang on, are you saying 'break' has a meaning in Perl?
No, I did not.
Abigail
--
perl -wlne '}{print$.' file # Count the number of lines.
------------------------------
Date: Sun, 30 Jan 2005 22:50:13 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Perl loops should use break, not last
Message-Id: <GqmdnUulht0--WDcRVnyjg@pipex.net>
Jeremy Morton wrote:
> Bear with me on this - it seems
> semantically more accurate to say 'break' - you're immediately breaking out
> of the loop. 'last' makes it sound like the current loop will be the last,
The semantics of 'break' or 'last' are defined by the language (in this
case Perl), not by you.
Why not think of 'last' as "this is the last statement to run for the
loop".
It's always struck me as odd that the 'continue' statement in 'C'
starts the next pass of a loop. This is definitely a strange use of the
concept of "continue". But it is the semantics of 'C', so I accept it.
By trying to map particular programming concepts into single English words
with exisiting meaning there is always going to be some sort of mismatching
oddity.
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Sun, 30 Jan 2005 22:57:24 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: Perl loops should use break, not last
Message-Id: <oDdLd.4059$qJ3.3242@bignews1.bellsouth.net>
On 2005-01-30, Abigail <abigail@abigail.nl> wrote:
> elsif? elsif? In C? I don't think so.
Well it's got 'else if' which is the same thing, no?
But anyway that's all academic. I was talking Perl code (that's why
the vars have a $ in front of them :-}), and how sometimes a ?: can
be used to omit braces. Because the if/elsif/else don't work w/o them.
------------------------------
Date: Sun, 30 Jan 2005 17:44:09 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Print question
Message-Id: <J19Ld.2690$S3.1148@newsread2.news.atl.earthlink.net>
"Joe Smith" <joe@inwap.com> wrote in message
news:7NmdnVIutIJDK2bcRVn-rA@comcast.com...
> edgrsprj wrote:
>
Thanks again for the info.
------------------------------
Date: 30 Jan 2005 19:46:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regular Expression Question on /i
Message-Id: <ctjdj1$h4n$4@mamenchi.zrz.TU-Berlin.DE>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
> Tad McClellan
> <tadmc@augustmail.com>], who wrote in article
> <slrncvn54e.6vb.tadmc@magna.augustmail.com>:
> > > \b(?:college|university)\s+diplomas/i
> >
> >
> > The "i" is not in a regular expression there, the "i" is part
> > of an *operator* that makes use of regular expressions.
>
> Actually, it is in a regular expression; so are 'x', 's' and 'm'.
Hmmm? I'm not following.
You must mean (?imsx), which *can* indeed be embedded in a regular
expression. If they are given in the form m/.../imsx however, they
aren't (even if the regex compiler doesn't make a difference).
Or do you mean something else?
Anno
------------------------------
Date: Sun, 30 Jan 2005 20:47:42 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Regular Expression Question on /i
Message-Id: <ctjh5e$1pfc$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <ctjdj1$h4n$4@mamenchi.zrz.TU-Berlin.DE>:
> > > The "i" is not in a regular expression there, the "i" is part
> > > of an *operator* that makes use of regular expressions.
> >
> > Actually, it is in a regular expression; so are 'x', 's' and 'm'.
> You must mean (?imsx), which *can* indeed be embedded in a regular
> expression.
I did not.
> If they are given in the form m/.../imsx however, they
> aren't.
Yes, they are. ;-)
It is unfortunate, that some of modifiers are actually parts of a REx,
while the others are part of the OP which uses the REx, but this is a
legacy design...
Hope this helps,
Ilya
------------------------------
Date: 30 Jan 2005 21:22:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regular Expression Question on /i
Message-Id: <ctjj64$l7p$2@mamenchi.zrz.TU-Berlin.DE>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
> Anno Siegel
> <anno4000@lublin.zrz.tu-berlin.de>], who wrote in article
> <ctjdj1$h4n$4@mamenchi.zrz.TU-Berlin.DE>:
> > > > The "i" is not in a regular expression there, the "i" is part
> > > > of an *operator* that makes use of regular expressions.
> > >
> > > Actually, it is in a regular expression; so are 'x', 's' and 'm'.
>
> > You must mean (?imsx), which *can* indeed be embedded in a regular
> > expression.
>
> I did not.
>
> > If they are given in the form m/.../imsx however, they
> > aren't.
>
> Yes, they are. ;-)
>
> It is unfortunate, that some of modifiers are actually parts of a REx,
> while the others are part of the OP which uses the REx, but this is a
> legacy design...
I know better than to accuse you of making no sense, but please, in what
*sense* are they part of the regex? Textually they aren't. That is what
the user sees.
Anno
------------------------------
Date: 30 Jan 2005 13:01:41 -0800
From: squash@peoriadesignweb.com
Subject: Replace text inside html tags?
Message-Id: <1107118901.149776.208370@z14g2000cwz.googlegroups.com>
I want to able replace text inside html tags. I am using a regex to
extract the text , but after I modify the text how can I re-assemble
the html tag? Here is an example:
<font size=1> HI </font>
I need to replace HI with BYE and re-assemble html tag like below:
<font size=1> BYE </font>
I checked perldoc -q html but could not find the answer there.
Thx!
------------------------------
Date: Sun, 30 Jan 2005 21:20:07 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Replace text inside html tags?
Message-Id: <Xns95EEA6361429Fasu1cornelledu@127.0.0.1>
squash@peoriadesignweb.com wrote in news:1107118901.149776.208370
@z14g2000cwz.googlegroups.com:
> I want to able replace text inside html tags. I am using a regex to
> extract the text , but after I modify the text how can I re-assemble
> the html tag? Here is an example:
>
> <font size=1> HI </font>
>
> I need to replace HI with BYE and re-assemble html tag like below:
>
> <font size=1> BYE </font>
> I checked perldoc -q html but could not find the answer there.
The answer to your question can be found in the answer to the FAQ.
The most correct way (albeit not the fastest) is to use HTML::Parser
from CPAN.
...
Many folks attempt a simple-minded regular expression approach, like
"s/<.*?>//g", but that fails in many cases because the tags may
continue over line breaks, they may contain quoted angle-brackets,
or HTML comment may be present. Plus, folks forget to convert
entities--like "<" for example.
That is, you need to use an HTML parser to parse HTML.
See CPAN for HTML parser modules.
I had never used HTML::TokeParser::Simple, so I gave that a shot:
#! /usr/bin/perl
use strict;
use warnings;
use HTML::TokeParser::Simple;
my $html = <<HTML;
<font><!--
<font> HI
</font>
-->
HI
</font>
HTML
my $p = HTML::TokeParser::Simple->new(string => $html);
my $in_font_tag;
while(my $token = $p->get_token) {
if($token->is_start_tag('font')) {
print $token->as_is;
$in_font_tag = 1;
next;
}
if($token->is_end_tag('font')) {
print $token->as_is;
$in_font_tag = 0;
next;
}
if($in_font_tag and $token->is_text) {
my $text = $token->as_is;
$text =~ s/HI/BYE/g;
print $text;
next;
}
print $token->as_is;
}
__END__
C:\Dload> h
<font><!--
<font> HI
</font>
-->
BYE
</font>
Seems to work.
Sinan.
------------------------------
Date: Sun, 30 Jan 2005 22:24:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Replace text inside html tags?
Message-Id: <365257F4svar0U1@individual.net>
squash@peoriadesignweb.com wrote:
> I want to able replace text inside html tags. I am using a regex to
> extract the text , but after I modify the text how can I re-assemble
> the html tag? Here is an example:
>
> <font size=1> HI </font>
>
> I need to replace HI with BYE and re-assemble html tag like below:
>
> <font size=1> BYE </font>
Depending on the complexity of the document, the s/// operator may be
sufficient.
> I checked perldoc -q html but could not find the answer there.
Then you should have seen for instance
perldoc -q "remove HTML"
and other entries in perlfaq9 which warn for trying to parse HTML
documents with regular expressions, and recommend the use of a suitable
module for HTML parsing.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 30 Jan 2005 17:43:49 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Replace text inside html tags?
Message-Id: <cNCdndmussGx_mDcRVn-qw@adelphia.com>
squash@peoriadesignweb.com wrote:
> I want to able replace text inside html tags. I am using a regex to
> extract the text , but after I modify the text how can I re-assemble
> the html tag? Here is an example:
>
> <font size=1> HI </font>
>
> I need to replace HI with BYE and re-assemble html tag like below:
>
> <font size=1> BYE </font>
Others have suggested using a parser module - and they're right. That should
always be your first instinct when working with HTML. However, there are
some scenarios where a regex is good enough, and faster to write than a
parser-based solution. For example, if the task at hand is a very simple
search-and-replace across a number of pages where you know a given pattern
will match. Or you're fixing pages that are broken beyond a parser's
ability to cope with them.
With that in mind, have a look at "perldoc perlretut", paying special
attention to the section titled "Extracting matches". You can use
"backreferences" in your regex to use parts of the matched string in the
replacement, like this:
#!/usr/bin/perl
use strict;
use warnings;
my $html = '<font size=1> HI </font><font size=1> HELLO </font>';
$html =~ s%(<font size=1>)(.*?)(</font>)%$1 BYE $3%g;
print $html, "\n";
Aside from subexpressions and backreferences, another point of note is the
"non-greedy" quantifier "*?". Without it - i.e. written as "*" - the second
expression would be "greedy", meaning it would return the longest possible
string that matches the expression it modifies. In the example above, that
would mean replacing everything between the first '<font size=1>' and the
*second* '</font>'. (Try it!)
That's not what you want - you want the *shortest* string that matches the
expression, not the longest. That's what the "non-greedy" quantifier gives
you.
Just to restate it - regexes are generally *not* the best way to parse HTML,
particularly arbitrary HTML that's fetched from a web site that's beyond
your control. But using them *can* useful if the task at hand is extremely
limited, or if the HTML is broken beyond a parser's ability to handle it.
References:
perldoc perlretut
perldoc perlre
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sun, 30 Jan 2005 15:24:50 -0200
From: Cesar Rabak <crabak@acm.org>
Subject: Re: what's OOP's jargons and complexities?
Message-Id: <41FD1862.9050804@acm.org>
Pascal Bourguignon escreveu:
> "Larry" <larry_wallet@yahoo.com> writes:
>
>
>>Xah Lee wrote:
>>
>>>in computer languages, often a function definition looks like this:
>>
>>> xah@xahlee.org
>>> http://xahlee.org/PageTwo_dir/more.html
>>
>>Your ideas are original, insightful and simply reflect incredibly deep
>>creative genius. I have read your work and I want to hire you for
>>highly classified work in software design and philosophical writing.
>>Would you possibly be available to meet with me in my secret mountain
>>compound to discuss terms?
>>
>>Larry
>
>
> You forgot to mention the coordinates of your secret mountain compound:
>
> 28 deg 5 min N, 86 deg 58 min E
>
Pascal!!
You spoiled a carefully kept Larry's secret. . . now it will have to
change his compound. . .
------------------------------
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 V10 Issue 7713
***************************************