develooper Front page | perl.fwp | Postings from July 2003

Re: my if?

Thread Previous | Thread Next
From:
Abigail
Date:
July 2, 2003 05:08
Subject:
Re: my if?
Message ID:
20030702120800.GB19937@abigail.nl
On Wed, Jul 02, 2003 at 01:02:12PM +0100, Pense, Joachim wrote:
> 
> 
> > -----Original Message-----
> > From: Abigail [mailto:abigail@abigail.nl]
> > Sent: Wednesday, July 02, 2003 1:51 PM
> > To: Pense, Joachim
> > Cc: fwp@perl.org
> > Subject: Re: my if?
> > 
> > 
> > On Wed, Jul 02, 2003 at 11:09:54AM +0100, Pense, Joachim wrote:
> > > Abigail wrote
> > > 
> > > > > > > 
> > > > > > > |   sub x {
> > > > > > > |       static $vbl ;
> > > > > > > |       ...
> > > > > > > |
> > > > > > > 
> > > > > > > | {
> > > > > > > |     my $vbl;
> > > > > > > |     sub x {
> > > > > > > |     ...
> > > > > > > |     }
> > > > > > > | }
> > > > > > 
> > > > > > 
> > > > > > IMO, not doubt the latter looks far more elegant - as that 
> > > > > > enables your
> > > > > > 'static' variable to be shared with more than one 
> > > > function. Something
> > > > > > you can't do with a 'static' declared variable inside 
> > a function.
> > > > > > 
> > > > > 
> > > > > Mighty != elegant.
> > > > > 
> > > > 
> > > > And neither is not being flexible.
> > > > 
> > > 
> > > Compare it with conditionals.
> > > 
> > > You can write
> > > 
> > > if ($some_condition) {
> > >    do_this;
> > >    do_that;
> > >    do_something_else;
> > > }
> > > 
> > > and you can write
> > > 
> > > do_this if $some_condition;
> > > 
> > > You need not write
> > > 
> > > if ($some_condition) {do_this}
> > > 
> > > The first version is more flexible, the second more elegant in its
> > > restricted scope. I think it is Perlish to have both available.
> > 
> > 
> > But they aren't equivalent.
> > 
> >     do_this if $condition;
> > 
> > is more efficient than
> > 
> >     if ($condition) {
> >         do_this;
> >     }
> > 
> > 
> > The latter requires Perl to enter and leave a block, while the
> > former doesn't.
> > 
> 
> Does anything similar hold for the sub/static example? I assume this would
> be an argument pro static.


Not really, as that will be a file scoped block and entered/left as
most once.


Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About