Re: passing Hash to subroutine help please

2009-12-09 Thread Philip Potter
2009/12/9 John W. Krahn : > Jeff Pang wrote: >> >> Noah: >>> >>> sub exiting { >>>    my ($hostname, %login) = @_; >> >> Passing arguments like this has no such problem. >> But you'd better pass the hash as a reference to the subroutine. >> >> exitint($hostname, \%login); >> >> sub exiting { >>    

Re: passing Hash to subroutine help please

2009-12-08 Thread Jeff Pang
John W. Krahn: Jeff Pang wrote: Noah: sub exiting { my ($hostname, %login) = @_; Passing arguments like this has no such problem. But you'd better pass the hash as a reference to the subroutine. exitint($hostname, \%login); sub exiting { my $hostname = shift; my %login = %{+shi

Re: passing Hash to subroutine help please

2009-12-08 Thread John W. Krahn
Jeff Pang wrote: Noah: sub exiting { my ($hostname, %login) = @_; Passing arguments like this has no such problem. But you'd better pass the hash as a reference to the subroutine. exitint($hostname, \%login); sub exiting { my $hostname = shift; my %login = %{+shift}; What is t

Re: passing Hash to subroutine help please

2009-12-08 Thread Steve Bertrand
Jeff Pang wrote: > Noah: > >> >> sub exiting { >> my ($hostname, %login) = @_; > > Passing arguments like this has no such problem. > But you'd better pass the hash as a reference to the subroutine. ...or bundle _all_ parameters into a hashref, which I've found to be oh so extensible, wi

Re: passing Hash to subroutine help please

2009-12-08 Thread Jeff Pang
Noah: sub exiting { my ($hostname, %login) = @_; Passing arguments like this has no such problem. But you'd better pass the hash as a reference to the subroutine. exitint($hostname, \%login); sub exiting { my $hostname = shift; my %login = %{+shift}; ... } print "logi

Re: passing Hash to subroutine help please

2009-12-08 Thread Jim Gibson
On 12/8/09 Tue Dec 8, 2009 5:41 PM, "Noah" scribbled: > > Hi there List people, > > I am hoping to send a hash and a scalar to a subroutine but the variable > is not completely being sent. Below is the error message below is > showing something is not getting passed that well to the subrouti

passing Hash to subroutine help please

2009-12-08 Thread Noah
Hi there List people, I am hoping to send a hash and a scalar to a subroutine but the variable is not completely being sent. Below is the error message below is showing something is not getting passed that well to the subroutine. Looks like %login is empty. --- snip --- $ret{$hostnames[0]

Re: SubRoutine Help

2002-01-07 Thread Michael R. Wolf
[EMAIL PROTECTED] (John W. Krahn) writes: > "Michael R. Wolf" wrote: [buggy code deleted ...] > $ perl -le' > @fred = qw(1 3 5 7 9); > sub total { > my $sum; > $sum += $_ foreach (@_); > } # undef from final foreach always returned > print total( @fred ); > ' > My ba

Re: SubRoutine Help

2002-01-07 Thread John W. Krahn
"Michael R. Wolf" wrote: > > # Readable. > sub total { > my $sum; > foreach my $num (@_) { > $sum += $num; > } > return $sum; > } > > # Streamlined > sub total { > my $sum; > $sum += $_ foreach (@_);# $_ implicitly set > } # sum implicitly returned ^

Re: SubRoutine Help

2002-01-06 Thread Michael R. Wolf
[EMAIL PROTECTED] (Dragon Nebula Web Design) writes: [...] > In this case, RTFMing is not helping (and I'd rather not > resort to the answer in the back of the book). You chose to not look? Don't let your pride get in the way of working code. AND also, don't let a simple answer get in the

SubRoutine Help

2002-01-06 Thread Dragon Nebula Web Design
Okay, first, this is NOT a homework question for the good reason that I am not currently in college. I am teaching Perl to myself, and I've managed to make it to the exercises in Chapter Four of the Llama, Third Edition and I'm stuck. In this case, RTFMing is not helping (and I'd rather not resort