Ktb wrote:
> 
> Thanks for laying out the following code John.  I've learned a few new
> tricks for my bag:)  There are a couple things I'm confused about.
> 
> 1) I've read about "return" but am still trying to wrap my mind around it.
>    I understand the two return statements skip if it comes across a file
>    or prog name but where is "returning" returning to?

return returns from a subroutine.  Since the code is in a subroutine it
will either return at the end of the sub (the closing brace) or by
explicitly using return.

perldoc -f return
perldoc perlsub


> 2) The following line confuses me.
>    local( $^I, @ARGV, $_ ) = ( '', $_ );
> 
> I will take a shot at it.
> 
> local
> # keep variable within subroutine

You need to use local() with perl's global variables which just affects
the values of the variables.


> ( $^I, @ARGV, $_ ) = ( '', $_ );
> # there seems to be an assignment going on here and "$^I" means to
>   change in place.  Is "$_" assigned to "@ARGV, $_" and the "''"
>   assigned to "$^I"?   Is "''" for empty lines in the files?

The $^I does the same thing as the -i command line switch (which you
were using.)  Setting it to '' means that you want in-place editing but
you don't want a backup file.

perldoc perlvar
perldoc perlrun

If any variable on the left-hand side of a list assignment is an array
or hash it will remove all the subsequent values from the right-hand
side so everything after '' on the right-hand side is assigned to @ARGV
(the current value of $_) and $_ is assigned the undef value.

This would do the same thing:

   local( $^I, $_, @ARGV ) = ( '', undef, $_ );

perldoc perldata
[snip]
       The final element may be an array or a hash:

           ($a, $b, @rest) = split;
           my($a, $b, %rest) = @_;

       You can actually put an array or hash anywhere in the
       list, but the first one in the list will soak up all the
       values, and anything after it will become undefined.  This
       may be useful in a my() or local().



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to