My value scope : my « Subroutine « Perl






My value scope

   

#!/usr/bin/perl
use warnings;
use strict;

my $file_scope = "my value";
print $file_scope, "\n";

sub topsub {
    my $top_scope = "visible in 'topsub'";
    if (1 > 0.5) {
        my $if_scope = "visible inside 'if'";
        print "$file_scope, $top_scope, $if_scope \n";
    }
    bottomsub();
    print "$file_scope, $top_scope\n";
}

sub bottomsub {
    my $bottom_scope = "visible in 'bottomsub'";
    print "$file_scope, $bottom_scope \n";
}

topsub();
print $file_scope, "\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.Define local variable in subroutine by using my
9.The scope of my variables
10.Use my to declare local variable