OK. While at this point, it will seem quite obvious. I'm going to list it, for completeness. As I would have thought it the first thing to show up. :)

Here cant i declare a variabe without using my keyword.
Error: Global symbol "$i" requires explicit package name at for.pl line 6.
Technically, you can
use strict; use warnings; my $number=8; no strict; # could have also used "no strict vars" $i=0; #if i remove my keyword it gives error (not now) for($i=0;$i<20;$i++) use strict; # back to strict { print "present value of the number is:"; print $number++; print "\n"; }
OR, clobber them all up front:
use strict; no strict vars; use warnings; $number=8; # look MA, no MY! $i=0; #if i remove my keyword it gives error -- not NOW! for($i=0;$i<20;$i++) # here either { print "present value of the number is:"; print $number++; print "\n"; }
OK those were pretty much directly from the strictures documentation (which is why I felt they should have been included here). But why not illustrate another possibility -- global Variable Scoping in Perl: the basics?
#!/usr/bin/perl -w our ( $number, $i ); use strict; $number=8; # NOTE the absence of my $i=0; # AGAIN no my used here for($i=0;$i<20;$i++) # OR here { print "present value of the number is:"; print $number++; print "\n"; }
Cool, huh? Well, not really. While the PHP language practically encourages global variables. In most cases, it should be avoided. If for no other reason; security reasons. Ovid has written a nice overview, that outlines global variables scoping, titled: 'our' is not 'my', that better describes this.

There. Now this feels complete :)

--Chris

¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH


In reply to Re: usage of "my" keyword by taint
in thread usage of "my" keyword by ravi45722

Title:
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, details, 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, summary, 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.