Then I am really confused, how can I cause the scope of $\ to extend only to
the end of the file and not into the other modules??

perldoc -f local
     local EXPR
             You really probably want to be using "my" instead,
             because "local" isn't what most people think of as
             "local".  See the Private Variables via my() entry
             in the perlsub manpage for details.

             A local modifies the listed variables to be local to
             the enclosing block, file, or eval.  If more than
             one value is listed, the list must be placed in
             parentheses.  See the Temporary Values via local()
             entry in the perlsub manpage for details, including
             issues with tied arrays and hashes.

and in my quick script:

#!yourperl
        my $\ = "\n";
__END__

I get this error:

Can't use global $\ in "my" at /usr/nj/pl.pl line 4, near "my $\ "
Execution of /usr/nj/pl.pl aborted due to compilation errors.

> -----Original Message-----
> From: Jenda Krynicky [mailto:Jenda@;Krynicky.cz]
> Sent: Thursday, October 24, 2002 3:16 PM
> To: Beginners (E-mail)
> Subject: Re: local()! Explain, please?
> 
> 
> > at the top of my script is:
> > 
> > local $\ = "\n";
> > 
> > now ... isn't local supposed to "modify the listed variables to be
> > local to the enclosing block, file, or eval." ?
> 
> No. That's "my".
> 
> > then why when I set this variable just before some code 
> (Mail::Sender
> > or MIME::Entity) that builds the e-mail and sends it, that 
> the e-mail
> > ALWAYS comes out wrong (wrong == improper formatting, wrong headers,
> > bad multipart, etc.).
> 
> Yes that's what I would expect.
> 
> 
> > Am I just misunderstanding the use of local?????????????????
> 
> Yes.
> 
> See this:
> 
>       sub foo {
>               print "\$x = $x\n";
>       }
> 
>       $x = "global value";
>       foo();
>       {
>               local $x = "local value";
>               foo();
>       }
>       foo();
>       {
>               my $x = "my value";
>               foo();
>       }
>       foo();
> 
> Do you see? 
> The "my $x = ..." "changes the value of $x" only for the block, while 
> "local $x = ..." changes the value of $x UNTIL you finish the block.
> That's a big difference.
> 
> What local does is this:
>       1) it stores the value of the variable somewhere
>       2) sets the variable to undef or whatever you told it to
>       3) installs a "handler" that'll replace the value of 
> the variable
>        with whatever local stored when the execution leaves the block.
> 
> On the other hand "my" creates a NEW variable that's not accessible 
> from anywhere outside the block.
> 
> You want to read MJD's "Coping with Scoping"
> http://perl.plover.com/FAQs/Namespaces.html
> 

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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

Reply via email to