Use my to declare local variable : my « Subroutine « Perl






Use my to declare local variable

   


#!/usr/bin/perl -w

$record = 4;
print "We're at record ", $record, "\n";

{
    my $record;
    $record = 7;
    print "Inside the block: ", $record, "\n";
}

print "Outside, we're still at record ", $record, "\n";

   
    
    
  








Related examples in the same category

1.Using my
2.Using my if statement
3.Using my to declare the local variable in a subroutine
4.my ($program, $exitCode) = @_; creates two local variables, $program and $exitCode, from @_.
5.my variable
6.my variable is initialized each time
7.my, local and global variable
8.My value scope
9.Define local variable in subroutine by using my
10.The scope of my variables