[Novalug] Re: Perlism...

donjr djr1952@hotpop.com
Wed Feb 14 22:43:27 EST 2007


On Wed, 2007-02-14 at 22:12 -0500, Eric Helvey wrote:
> On Wed, 14 Feb 2007, donjr wrote:
> > 
> <snip>
> 
> >  There is one line that threw{throws} me for a loop:
> >     elsif ($no_act or rename $was, $_)
> 
> >   "no_act" is a logical controlled by the -n option,
> >   but "rename" is the name of the program/script.
> 
> 
> Don, if you're asking for an explanation, I'll give you one.  If you
> weren't, ignore this.

Thank you.

> $no_act is set by the -n flag as you recognize.

This I figured out by the overall logic of the program.

> The Or statement compares the truth values of the $no_act and the result
> of the rename operation.
> 
> Another way to write this (slightly clearer) might be:
> 
> my $shouldbe = $_;
> my $xx = $no_act;
> $xx = rename($was, $shouldbe) unless $no_act;

What I didn't know off hand was:
  Does Perl have a built-in "rename" function/subroutinue?
  I assume for your overall statement/answer here that it does.

> # Not sure what the elsif is attached to...
> elsif ($xx) 

"elif" is one part of a multi-part if,elif,else statement that handles
the overall file name handling logic of the Perl script called "rename".

{ ie I know how to write programs in a number of languages from
"assembler on S360 Main Frames" to C, bash and awk in the *NIX
environment. I even know enough Perl to get me into a problem, but
getting myself back out is another question. }

> The upshot being, if $no_act is true, then the rename never happens -
> you short circuit the logical operation.

I seem to remember reading somewhere that Perl uses short circuit logic
by default.



More information about the Novalug mailing list