Philip Potter <philip.g.pot...@gmail.com> writes: > On 5 May 2010 14:36, Harry Putnam <rea...@newsguy.com> wrote: >> "Uri Guttman" <u...@stemsystems.com> writes: >> >>> HP> The output from the script below: >>> HP> Shows 6 elements arrive in dispt($g, @ar) as @_. But when sub N(@_) >>> HP> is called, no variables arrive there. @_ is empty. When it seems like >>> HP> 5 elements should have arrived there >>> >>> well, it helps if you actually pass in arguments. @_ is NOT a global.FF >>> >>> HP> my $code = $dispt{$selection} || $dispt{'error'} ; >>> HP> $code->(); >>> >>> you aren't passing anything in to $code. you need to put something in >>> the () which then is set in the @_ of the called sub. >> >> As usual, I'm a little confused here. First, what is a `global.FF'? > > I don't see "FF" in uri's original post, your reader may have mangled > it. He said "@_ is NOT a global."
First. I see `FF' in your response above too. At the line beginning: >>> well, But you're right... its NOT in the original... odd. Anyway, I understood he was saying NOT global. What I asked is why that would matter. That is, the values or elements in @_ arrive inside the `sub dispt {...}', so should be available to anything inside `sub dispt {...}' right? And `%hash = (...)' is inside `sub dispt {. %hash = (...)..}' I do get confused often about how scope works. Trying to subtract as much as I can and still see what is confusing to me. In this little piece of code... I'm still missing why @_ has lost its meaning in the spots indicated by comments below: Not seeing why it matters that @_ is NOT global since we are only looking for a value inside dispt {...} and the content is shipped in with the call `dispt($val1,$val2)' #!/usr/bin/perl my $val1 = 'I am a value'; my $val2 = 'I am a second value'; dispt($val1,$val2) sub dispt { # HERE @_ is known %hash = ( N => sub { print N(@_ # HERE it is not known) . "\n"; }, [...] ); [...] chomp(my $selection = <STDIN>); my $code = $hash{$selection} || $hash{'error'} ; $code->(); ## I realize this is what calls sub N() and passes ## any info, but what about the call to N(@_) above? } sub N { # HERE no values for @_ are present. [...] } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/