Changes

From SME Server
Jump to navigationJump to search
37 bytes added ,  16:09, 28 December 2013
Line 211: Line 211:  
     my $var = "value";
 
     my $var = "value";
   −
The my is actually not required; you could just use:
+
The '''my''' is actually not required; you could just use:
    
     $var = "value";
 
     $var = "value";
   −
However, the above usage will create global variables throughout your program, which is bad programming practice. my creates lexically scoped variables instead. The variables are scoped to the block (i.e. a bunch of statements surrounded by curly-braces) in which they are defined.
+
However, the above usage will create global variables throughout your program, which is bad programming practice. '''my''' creates lexically scoped variables instead. The variables are scoped to the block (i.e. a bunch of statements surrounded by curly-braces) in which they are defined.
    
     my $x = "foo";
 
     my $x = "foo";
Line 227: Line 227:  
     print $y; # prints nothing; $y has fallen out of scope
 
     print $y; # prints nothing; $y has fallen out of scope
   −
Using my in combination with a use strict; at the top of your Perl scripts means that the interpreter will pick up certain common programming errors. For instance, in the example above, the final print $y would cause a compile-time error and prevent you from running the program. Using strict is highly recommended.
+
Using '''my''' in combination with a '''use strict;''' at the top of your Perl scripts means that the interpreter will pick up certain common programming errors. For instance, in the example above, the final '''print $y''' would cause a compile-time error and prevent you from running the program. Using '''strict''' is highly recommended.
 +
 
 
=== Conditional and looping constructs ===
 
=== Conditional and looping constructs ===
  

Navigation menu