From: Nikola Janceski <[EMAIL PROTECTED]>
> Okay, I was fuming mad. I have been struggling with a program that is
> supposed to send a simple e-mail... or so I thought!
>
> for 2 days I have sent test e-mails all of them with headers in the
> e-mail and attachments all screwy. then I found the culprit.
>
> 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.
> use MIME::Entity;
>
> local $\ = "\n";
>
> my $top = MIME::Entity->build(
> Type => "multipart/mixed",
> From => "nikola_janceski\@summithq.com",
> To =>
> '[EMAIL PROTECTED]',
> Subject => "something"
> );
> ...
> 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
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]