http://www.perlmonks.org?node_id=1009757

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am quite sure there is a simple reason for this but it is beyond me. The code below prints the uid as expected from within the foreach loop. However, it will not print it in the subroutine. Why not and how can I fix it?
#!/usr/bin/perl use strict; my $uid; my @array = ("one","two","three"); foreach $uid (@array){ print "uid in loop=$uid\n"; # prints each value of $uid as expected &mail($uid); } sub mail { # never prints the value of $uid ? ? print "uid in sub=$uid\n"; }
Thank you!