Created
October 9, 2012 04:32
-
-
Save sakadonohito/3856617 to your computer and use it in GitHub Desktop.
Reference and DeReference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# -*- coding:utf-8 -*- | |
use strict; | |
use warnings; | |
use feature 'say'; | |
use encoding 'utf-8'; | |
my @array = (1,2,3); | |
my %hash = ( | |
'A'=>'Alpha', | |
'B'=>'Bravo', | |
'C'=>'Charlie' | |
); | |
say 'foreach:File Scope'; | |
foreach my $a (@array){ | |
say $a; | |
} | |
say 'foreach:File Scope'; | |
foreach my $k (keys(%hash)){ | |
say $hash{$k}; | |
} | |
sub _push1 { | |
my $temp_arr = shift; | |
my @arr = @$temp_arr; | |
push(@arr,4); | |
say 'foreach:Sub Scope'; | |
foreach my $a (@arr){ | |
say $a; | |
} | |
} | |
sub _push2 { | |
my $arr = shift; | |
push(@$arr,4); | |
say 'foreach:Sub Scope'; | |
foreach my $a (@$arr){ | |
say $a; | |
} | |
} | |
&_push1(\@array); | |
say 'foreach:File Scope'; | |
foreach my $a (@array){ | |
say $a; | |
} | |
&_push2(\@array); | |
say 'foreach:File Scope'; | |
foreach my $a (@array){ | |
say $a; | |
} | |
sub _add1 { | |
my $temp = shift; | |
my %hs = %$temp; | |
$hs{'D'} = 'Delta'; | |
say 'foreach:Sub Scope'; | |
foreach my $key (keys(%hs)){ | |
say $hs{$key} | |
} | |
} | |
&_add1(\%hash); | |
say 'foreach:File Scope'; | |
foreach my $k (keys(%hash)){ | |
say $hash{$k}; | |
} | |
sub _add2 { | |
my $hs = shift; | |
$$hs{'D'} = 'Delta'; | |
say 'foreach:Sub Scope'; | |
foreach my $key (keys(%$hs)){ | |
say $$hs{$key} | |
} | |
} | |
&_add2(\%hash); | |
say 'foreach:File Scope'; | |
foreach my $k (keys(%hash)){ | |
say $hash{$k}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment