On Wednesday, April 10, 2002, at 04:42 , Elaine -HFB- Ashton wrote:
> I always found the local, my, our mess pretty confusing and the best > explanation is MJD's "Coping with Scoping" > > http://perl.plover.com/FAQs/Namespaces.html > > Make good note of the text in red :) ok, I get the following error message when I use 'local' rather than a my - in a way old piece of code I found along the way: vladimir: 66:] perl old_get_ip Global symbol "$hostname" requires explicit package name at old_get_ip line 8. Global symbol "$hostname" requires explicit package name at old_get_ip line 10. Execution of old_get_ip aborted due to compilation errors. vladimir: 67:] see below.... I just had the News Flash Coffee Wake Up Moment...... It is whining that in the function it is expecting to use a local copy of a globally declared variable - which if I try with the our $hostname = ''; will work - but not if I did that with the my $hostname = ''; which hurls furballs with: vladimir: 75:] perl old_get_ip wetware Can't localize lexical variable $hostname at old_get_ip line 10. vladimir: 76:] So that is how that works.... ciao drieux --- WARNING: do Not Code Like This: The following is BAD CODE! ### #!/usr/local/bin/perl -w ### use strict; ### # ### # a dumb perl implementation to get an ip_addr for a hostname ### # our $hostname = ''; ### sub do_gethost{ ### ### local($hostname) = pop(@_); ### ### my ( $name, $aliases, $addrtype, $length, @addr)=gethostbyname($hostname); ### ### if ( defined($name) ) ### { ### my ($a, $b, $c, $d) = unpack('C4', $addr[0]); ### ### printf("%s.%s.%s.%s\n", $a, $b, $c, $d); ### } ### ### } ### ### while(my $name = shift(@ARGV) ) { ### ### &do_gethost($name); ### ### } ### ### exit(0); ### that it was in the production release of stuff to provide a work around because the IT staff was never sure if they were putting stuff into /etc/hosts or through NIS+ and hence.... or.... and the geeks who whacked in the /bin/sh scripting - 'because we do not want to learn perl' - had way ancien ugly sed wrappers on nslookup calls - still remains no good excuse for BAD perl Code. WARNING: if you code like that after reading stuff from the perl list - do not blame me because you did not read this Warning Message and heed it. did I mention that this is BAD PERL CODE! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]