To: [EMAIL PROTECTED] From: "Lance" <[EMAIL PROTECTED]> Subject: inner variable access Date sent: Tue, 11 Feb 2003 17:49:25 -0000
> Is there a way to access the 'foreach' variable from a subprocedure > called from inside the loop whose variable you want to access? > Hooboy, even I don't understand that question! ;-) Depends on whether you use a lexical variable. If you do (and you SHOULD) then only if you pass it to the function. > An example is > neccessary, I believe: > > foreach my $store( values %$server ){ > if( $$store{errorPageCount} >=1 ){ $store->{errorPageCount} looks much better. > ## loop through each page to check in each store > foreach my $page( values %$store ){ > $$server{emailMessage} .= "$$page{error}"; Do not enclose variables in quotes unless you really have to. $server->{emailMessage} .= $page->{error}; > } > } > if( $$store{badMailSent} ne 'sent' ){ > mailIt( $$store{emailMessage}, "$$store{name} is > non-responsive", 'bad', $$store{email}); mailIt( $store->{emailMessage}, "$store->{name} is non-responsive", 'bad', $store->{email}, $store, $server); > } > } > > Now, from within my mailIt sub, can I access $$store or $$server? I > get the error message: "Global symbol "$store" requires explicit > package name at D:\My Stuff\lance\perl\store_monitor\store_monitor.pl > line 603." > > inside of mailIt, I am trying to access a variable in %server using: > $$server{errorPageCount}++; There is no variable %server in your code. You have a SCALAR variable $server that contains a reference to a HASH. So the hash is %$server. And the elements of the hash are either $$server{key} or $server- >{key}. Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]