Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The basic difference is that, when you declare $foo = 3; and then
you go into a block or sub and say local $foo = 5; the value in $foo
inside the blocks or sub is 5, but outside is 3 here is some code:
#!/usr/bin/perl -w #didn't use strict, to make the example clearer. $foo = 3; #default value of $foo { local $foo = 5; #now the value of $foo is 5 while inside the braces print "$foo\n"; # prints 5. } print "$foo\n"; # prints 3.

With my is a bit different code examples:
#!/usr/bin/perl -w use strict; #<- very important. my $foo = 3; # $foo has a value of 3, and is seen by the compiler. { my $bar = 5; # $ bar life is limited to the block. print "$bar\n"; # you get 5. print "$foo\n"; # you get 3. } print "$bar\n"; # <- compiler gives error.$bar does not exsist (kind o +f). print "$foo\n"; # you get 3.
I hope this clear, things up a bit, and i hope i'm not completely wrong
if i am i'm sure the other monks, will point it out.



In reply to Re: my and local?? by monk
in thread my and local?? by mrt

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (8)
    As of 2021-04-12 21:46 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found