[23384] in Perl-Users-Digest
Perl-Users Digest, Issue: 5603 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 2 09:10:46 2003
Date: Thu, 2 Oct 2003 06:10:11 -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 Thu, 2 Oct 2003 Volume: 10 Number: 5603
Today's topics:
syntax question <vervoom@hotmail.com>
Re: syntax question <ak+usenet@freeshell.org>
Re: syntax question (Sam Holden)
Re: syntax question <vervoom@hotmail.com>
Re: syntax question (Anno Siegel)
Re: syntax question <vervoom@hotmail.com>
Re: syntax question <tore@aursand.no>
Unexpected alteration of array's content <phill@modulus.com.au>
Re: Unexpected alteration of array's content (Sam Holden)
Re: Unexpected alteration of array's content <jurgenex@hotmail.com>
WWW::Mechanize .. anyone? <cent@optushome.com.au>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 02 Oct 2003 09:48:37 +0100
From: JS <vervoom@hotmail.com>
Subject: syntax question
Message-Id: <blgoq5$r3a$1@cspc1n11.baplc.com>
When using the syntax:
true ? do command1 : do command2 ;
Is it possible to execute more than one command? e.g
true? {do command1 && command3} : { do command 2 && command 4} ;
Thanks for your help,
JS.
------------------------------
Date: Thu, 2 Oct 2003 09:00:24 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: syntax question
Message-Id: <slrnbnnq98.cp9.ak+usenet@otaku.freeshell.org>
In article <blgoq5$r3a$1@cspc1n11.baplc.com>, JS wrote:
> When using the syntax:
>
> true ? do command1 : do command2 ;
>
> Is it possible to execute more than one command? e.g
>
> true? {do command1 && command3} : { do command 2 && command 4} ;
The ( test ? value1 : value2 ) construct is best suited as
the right hand side of an assignment. If you need "value1"
and/or "value2" to do more elaborate things than just provide
a straight value, then consider using "if (test) {value1} else
{value2}" instead (where the values now are chunks of code).
--
Andreas Kähäri
------------------------------
Date: 2 Oct 2003 09:04:31 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: syntax question
Message-Id: <slrnbnnqgv.nst.sholden@flexal.cs.usyd.edu.au>
On Thu, 02 Oct 2003 09:48:37 +0100, JS <vervoom@hotmail.com> wrote:
> When using the syntax:
>
> true ? do command1 : do command2 ;
>
> Is it possible to execute more than one command? e.g
>
> true? {do command1 && command3} : { do command 2 && command 4} ;
You can use any expression, "command" is a meaningless term in
that context.
You can use operators like , to turn multiple expressions into
one expressions, and functions or do to turn arbitrary
statments into an expression.
Though using if..else will usually make for more readable
code, if the expressions are large.
--
Sam Holden
------------------------------
Date: Thu, 02 Oct 2003 10:16:16 +0100
From: JS <vervoom@hotmail.com>
Subject: Re: syntax question
Message-Id: <blgqdr$r3g$1@cspc1n11.baplc.com>
Sam Holden wrote:
> On Thu, 02 Oct 2003 09:48:37 +0100, JS <vervoom@hotmail.com> wrote:
>
>>When using the syntax:
>>
>>true ? do command1 : do command2 ;
>>
>>Is it possible to execute more than one command? e.g
>>
>>true? {do command1 && command3} : { do command 2 && command 4} ;
>
>
> You can use any expression, "command" is a meaningless term in
> that context.
>
> You can use operators like , to turn multiple expressions into
> one expressions, and functions or do to turn arbitrary
> statments into an expression.
>
> Though using if..else will usually make for more readable
> code, if the expressions are large.
>
Here is the code I'm trying to get to work:
my $firstdept=1;
foreach my $app (keys %appdept_percentage){
my $applen=length($app)+4;
$firstdept?$firstdept=0,printf "\n%35s",$app:printf
"%".$applen."s",$app
}
Admittedly I could write it:
my $firstdept=1;
foreach my $app (keys %appdept_percentage){
my $applen=length($app)+4;
$firstdept?printf "\n%35s",$app:printf "%".$applen."s",$app
$firstdept=0;
}
OR
my $firstdept=1;
foreach my $app (keys %appdept_percentage){
my $applen=length($app)+4;
if (){
printf "\n%35s",$app
$firstdept=0;
}
else{ printf "%".$applen."s",$app
}
}
OR probably a dozen other ways, but my simple question is assuming I
could do this, what is the correct syntax to group this
$firstdept=0,printf "\n%35s",$app
between the ? and :
This is syntactically wrong at the moment:
$firstdept?$firstdept=0,printf "\n%35s",$app:printf "%".$applen."s",$app
This won't work:
$firstdept?$firstdept=0 && printf "\n%35s",$app:printf "%".$applen."s",$app
Nor will this:
$firstdept?($firstdept=0,printf "\n%35s",$app):printf "%".$applen."s",$app
or this:
$firstdept?{$firstdept=0,printf "\n%35s",$app}:printf "%".$applen."s",$app
I don't care about legibility, I just want to know if Perl can do it or
not?!!!!!!
Thanks,
JS.
------------------------------
Date: 2 Oct 2003 10:57:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: syntax question
Message-Id: <blh0as$gp2$1@mamenchi.zrz.TU-Berlin.DE>
JS <vervoom@hotmail.com> wrote in comp.lang.perl.misc:
> Sam Holden wrote:
> > On Thu, 02 Oct 2003 09:48:37 +0100, JS <vervoom@hotmail.com> wrote:
> >
> >>When using the syntax:
> >>
> >>true ? do command1 : do command2 ;
> >>
> >>Is it possible to execute more than one command? e.g
> >>
> >>true? {do command1 && command3} : { do command 2 && command 4} ;
> >
> >
> > You can use any expression, "command" is a meaningless term in
> > that context.
> >
> > You can use operators like , to turn multiple expressions into
> > one expressions, and functions or do to turn arbitrary
> > statments into an expression.
> >
> > Though using if..else will usually make for more readable
> > code, if the expressions are large.
> >
>
> Here is the code I'm trying to get to work:
>
> my $firstdept=1;
> foreach my $app (keys %appdept_percentage){
> my $applen=length($app)+4;
> $firstdept?$firstdept=0,printf "\n%35s",$app:printf
> "%".$applen."s",$app
> }
>
> Admittedly I could write it:
>
> my $firstdept=1;
> foreach my $app (keys %appdept_percentage){
> my $applen=length($app)+4;
> $firstdept?printf "\n%35s",$app:printf "%".$applen."s",$app
> $firstdept=0;
> }
Then why don't you? Well, it would make a difference if $firstdept could
meaningfully be boolean false, but not 0 ("" or undef).
> OR
>
> my $firstdept=1;
> foreach my $app (keys %appdept_percentage){
> my $applen=length($app)+4;
> if (){
> printf "\n%35s",$app
> $firstdept=0;
> }
> else{ printf "%".$applen."s",$app
> }
> }
Did you try it? An empty "if"-condition is a syntax error.
> OR probably a dozen other ways, but my simple question is assuming I
> could do this, what is the correct syntax to group this
>
> $firstdept=0,printf "\n%35s",$app
>
> between the ? and :
>
> This is syntactically wrong at the moment:
>
> $firstdept?$firstdept=0,printf "\n%35s",$app:printf "%".$applen."s",$app
Sure. There can be only one expression between "?" and ":".
> This won't work:
> $firstdept?$firstdept=0 && printf "\n%35s",$app:printf "%".$applen."s",$app
Wrong precedence. "&&" binds tighter than "=", so that's
"$firstdept= ( 0 && printf "\n%35s",$app)". Not what you want.
> Nor will this:
>
> $firstdept?($firstdept=0,printf "\n%35s",$app):printf "%".$applen."s",$app
Sure it will. How did you test it? The parens make a single expression
out of the comma-separated two.
> or this:
>
> $firstdept?{$firstdept=0,printf "\n%35s",$app}:printf "%".$applen."s",$app
A block isn't a statement, so a block can't go between "?" and ":". To
make a statement out of a block, prefix it with "do". IoW:
$firstdept? do {$firstdept=0,printf "\n%35s",$app}:printf "%".$applen."s",$app
> I don't care about legibility, I just want to know if Perl can do it or
> not?!!!!!!
If you had run your tests a little more careful, you'd already have your
answer. Don't blame the group.
Anno
------------------------------
Date: Thu, 02 Oct 2003 12:31:14 +0100
From: JS <vervoom@hotmail.com>
Subject: Re: syntax question
Message-Id: <blh2au$q1o$1@cspc1n11.baplc.com>
Anno Siegel wrote:
> JS <vervoom@hotmail.com> wrote in comp.lang.perl.misc:
>
>>Sam Holden wrote:
>>
>>>On Thu, 02 Oct 2003 09:48:37 +0100, JS <vervoom@hotmail.com> wrote:
>>>
>>>
>>>>When using the syntax:
>>>>
>>>>true ? do command1 : do command2 ;
>>>>
>>>>Is it possible to execute more than one command? e.g
>>>>
>>>>true? {do command1 && command3} : { do command 2 && command 4} ;
>>>
>>>
>>>You can use any expression, "command" is a meaningless term in
>>>that context.
>>>
>>>You can use operators like , to turn multiple expressions into
>>>one expressions, and functions or do to turn arbitrary
>>>statments into an expression.
>>>
>>>Though using if..else will usually make for more readable
>>>code, if the expressions are large.
>>>
>>
>>Here is the code I'm trying to get to work:
>>
>>my $firstdept=1;
>>foreach my $app (keys %appdept_percentage){
>> my $applen=length($app)+4;
>> $firstdept?$firstdept=0,printf "\n%35s",$app:printf
>>"%".$applen."s",$app
>>}
>>
>>Admittedly I could write it:
>>
>>my $firstdept=1;
>>foreach my $app (keys %appdept_percentage){
>> my $applen=length($app)+4;
>> $firstdept?printf "\n%35s",$app:printf "%".$applen."s",$app
>> $firstdept=0;
>>}
>
>
> Then why don't you? Well, it would make a difference if $firstdept could
> meaningfully be boolean false, but not 0 ("" or undef).
>
>
>>OR
>>
>>my $firstdept=1;
>>foreach my $app (keys %appdept_percentage){
>> my $applen=length($app)+4;
>> if (){
>> printf "\n%35s",$app
>> $firstdept=0;
>> }
>> else{ printf "%".$applen."s",$app
>> }
>>}
>
>
> Did you try it? An empty "if"-condition is a syntax error.
>
>
>>OR probably a dozen other ways, but my simple question is assuming I
>>could do this, what is the correct syntax to group this
>>
>>$firstdept=0,printf "\n%35s",$app
>>
>>between the ? and :
>>
>>This is syntactically wrong at the moment:
>>
>>$firstdept?$firstdept=0,printf "\n%35s",$app:printf "%".$applen."s",$app
>
>
> Sure. There can be only one expression between "?" and ":".
>
>
>>This won't work:
>>$firstdept?$firstdept=0 && printf "\n%35s",$app:printf "%".$applen."s",$app
>
>
> Wrong precedence. "&&" binds tighter than "=", so that's
> "$firstdept= ( 0 && printf "\n%35s",$app)". Not what you want.
>
>
>>Nor will this:
>>
>>$firstdept?($firstdept=0,printf "\n%35s",$app):printf "%".$applen."s",$app
>
>
> Sure it will. How did you test it? The parens make a single expression
> out of the comma-separated two.
>
>
>>or this:
>>
>>$firstdept?{$firstdept=0,printf "\n%35s",$app}:printf "%".$applen."s",$app
>
>
> A block isn't a statement, so a block can't go between "?" and ":". To
> make a statement out of a block, prefix it with "do". IoW:
>
> $firstdept? do {$firstdept=0,printf "\n%35s",$app}:printf "%".$applen."s",$app
>
>
>>I don't care about legibility, I just want to know if Perl can do it or
>>not?!!!!!!
>
>
> If you had run your tests a little more careful, you'd already have your
> answer. Don't blame the group.
>
> Anno
Thanks for that Anno. So you can do it with a do {block}. I don't mean
to blame the "group" but if someone had just said that in the first
place it would have been a lot easier :)
JS.
------------------------------
Date: Thu, 02 Oct 2003 14:23:05 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: syntax question
Message-Id: <pan.2003.10.02.09.09.14.262335@aursand.no>
On Thu, 02 Oct 2003 09:48:37 +0100, JS wrote:
> When using the syntax:
>
> true ? do command1 : do command2 ;
>
> Is it possible to execute more than one command? e.g
>
> true? {do command1 && command3} : { do command 2 && command 4} ;
Have you tried? What happened when you did?
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Thu, 2 Oct 2003 17:02:57 +1000
From: "Peter Hill" <phill@modulus.com.au>
Subject: Unexpected alteration of array's content
Message-Id: <blgj8v$1rdo$1@arachne.labyrinth.net.au>
The following program gives an output which I didn't expect with Perl 5.8
#! /usr/bin/perl -w
use strict;
my @lines = ('one','two','three');
for my $line (@lines){
$line =~ s/w/x/g;
}
print "@lines\n";
#output is "one txo three"
Am I wrong in expecting the array not to be modified when I'm only modifying
a local variable derived from it? Apologies if this is a commonly known
effect, I've just returned to Perl programming.
tia
------------------------------
Date: 2 Oct 2003 07:19:56 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Unexpected alteration of array's content
Message-Id: <slrnbnnkcs.mqr.sholden@flexal.cs.usyd.edu.au>
On Thu, 2 Oct 2003 17:02:57 +1000, Peter Hill <phill@modulus.com.au> wrote:
> The following program gives an output which I didn't expect with Perl 5.8
> #! /usr/bin/perl -w
> use strict;
> my @lines = ('one','two','three');
> for my $line (@lines){
> $line =~ s/w/x/g;
> }
> print "@lines\n";
>
> #output is "one txo three"
>
>
> Am I wrong in expecting the array not to be modified when I'm only modifying
> a local variable derived from it? Apologies if this is a commonly known
> effect, I've just returned to Perl programming.
Your expectation is incorrect. The behaviour is documented in:
perldoc perlsyn
Reading the documentation is usually a better way of determining what
a statement will do then guessing.
--
Sam Holden
------------------------------
Date: Thu, 02 Oct 2003 07:21:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Unexpected alteration of array's content
Message-Id: <2mQeb.1409$3b7.199@nwrddc02.gnilink.net>
Peter Hill wrote:
> The following program gives an output which I didn't expect with Perl
> 5.8 #! /usr/bin/perl -w
> use strict;
> my @lines = ('one','two','three');
> for my $line (@lines){
> $line =~ s/w/x/g;
> }
> print "@lines\n";
>
> #output is "one txo three"
>
>
> Am I wrong in expecting the array not to be modified when I'm only
> modifying a local variable derived from it? Apologies if this is a
> commonly known effect, I've just returned to Perl programming.
From "perldoc perlsyn":
Foreach Loops
[...] If any element of LIST is an lvalue, you can modify it by
modifying VAR
inside the loop.
jue
------------------------------
Date: Thu, 2 Oct 2003 17:56:32 +1000
From: "Ryan" <cent@optushome.com.au>
Subject: WWW::Mechanize .. anyone?
Message-Id: <3f7bda2e$0$30274$afc38c87@news.optusnet.com.au>
anyone here used this module before? I really need to stop it from
downloading images .... it's eating up all my bw and I cant find a way to
stop it from doing so ....... not that i know if it is or not, but it's
downloading something
Thanks
Ry
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5603
***************************************