Re: Returning arrays from subroutines... how?

2003-06-02 Thread Ken Tozier
Thanks for answering David, Jeff and Beau. My script works like a charm now. Ken -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread Ken Tozier
Here's the flip side of yesterday's array question. Now that I know how to pass associative arrays out of a routine, I'm having trouble trying to use them in other routines. The best I can figure from reading is that I need to pass them by reference, but in practice, the terminal always fills

Re: Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread James Edward Gray II
On Sunday, June 1, 2003, at 03:27 PM, Ken Tozier wrote: my $description = DescribeCritter(\% wombatStats); This is passing a hash to a hash. No reference required for that. Just drop the \. I also believe you have a space after the % that shouldn't be there. Hope that helps. James -- To

Re: Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread Ken Tozier
On Sunday, June 1, 2003, at 04:35 PM, James Edward Gray II wrote: On Sunday, June 1, 2003, at 03:27 PM, Ken Tozier wrote: my $description = DescribeCritter(\%wombatStats); This is passing a hash to a hash. No reference required for that. Just drop the \. I also believe you have a space after

Re: Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread James Edward Gray II
On Sunday, June 1, 2003, at 04:12 PM, Ken Tozier wrote: No luck. Dropping the \ in 'my $description = DescribeCritter(\%wombatStats);' didn't fix the problem. You're right. I was dumb. Let me try again... my $description = DescribeCritter(\% wombatStats); Drop the backslash and space here,

RE: Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread Charles K. Clarkson
Ken Tozier [EMAIL PROTECTED] wrote: : : my %wombatStats = GetWombat(); : my $description = DescribeCritter(\% wombatStats); my $description = DescribeCritter(\%wombatStats); I didn't try it but I don't think the space after '%' is a good idea. It is a good idea to get in the habit of passing

Re: Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread Tassilo von Parseval
On Sun, Jun 01, 2003 at 04:20:28PM -0500 James Edward Gray II wrote: On Sunday, June 1, 2003, at 04:12 PM, Ken Tozier wrote: No luck. Dropping the \ in 'my $description = DescribeCritter(\%wombatStats);' didn't fix the problem. You're right. I was dumb. Let me try again... my

Returning arrays from subroutines... how?

2003-06-01 Thread Ken Tozier
I'm sure this is an easy one but after Googling for hours, I still don't get it. Given the following subroutine, how do I return the result array? Nothing I try works. sub GetMarmots { @result = (); $result{'steppe marmot '} = 4; $result{'himalayan marmot'} = 3;

Re: Returning arrays from subroutines... how?

2003-06-01 Thread jeff loetel
Ken, your mixing your @ with your % Try this: #!/usr/bin/perl GetMarmots; sub GetMarmots { %result = (); $result{'steppe marmot'} = 4; $result{'himalayan marmot'} = 3; $result{'mongolian marmot'} = 1; $result{'woodchuck'} = 6; return %result; } foreach (keys %result)

Re: Returning arrays from subroutines... how?

2003-06-01 Thread Beau E. Cox
- Original Message - From: Ken Tozier [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, May 31, 2003 5:24 PM Subject: Returning arrays from subroutines... how? I'm sure this is an easy one but after Googling for hours, I still don't get it. Given the following subroutine, how

RE: Returning arrays from subroutines... how?

2003-06-01 Thread Charles K. Clarkson
jeff loetel [EMAIL PROTECTED] wrote: : Try this: : : #!/usr/bin/perl : : GetMarmots; : : sub GetMarmots { : %result = (); : $result{'steppe marmot'} = 4; : $result{'himalayan marmot'} = 3; : $result{'mongolian marmot'} = 1; : $result{'woodchuck'} = 6; : return %result;

Re: arrays and subroutines

2003-03-17 Thread R. Joseph Newton
David Newman wrote: Greetings. I have a newbie question about passing arrays into a subroutine (and getting return values as well). Hi David, I can't help much as far as passing or returning whole arrays, but there is a much better way to access arrays from inside a function. I'll show you

arrays and subroutines

2003-03-16 Thread David Newman
Greetings. I have a newbie question about passing arrays into a subroutine (and getting return values as well). My script uses arrays for various values -- one array each for TCP port numbers, UDP port numbers, and the different bytes of IP addresses. Since I have to populate each of these

Re: arrays and subroutines

2003-03-16 Thread Victor Tsang
You need to pass the array to the function by reference, here's the fix. spin([EMAIL PROTECTED]); sub spin { $arr = shift; for (; $count 0; $count--) { push(@$arr, $start++); } } but if all you want to do is to populate your array with value between 1025 to 1035, here's a

Multi-dimensional arrays and subroutines

2002-07-17 Thread Ho, Tony
Hi Guys I was wondering if you could help me. I have a multi-dimensional array and I would like to pass it to a subroutine as follows : my multi_array = ([1,2,3,4], [5,6,7,8]); my result = process_array(multi_array); print The result is : result\n; sub process_array { my

RE: Multi-dimensional arrays and subroutines - PLEASE IGNORE PREVIOUS EMAIL

2002-07-17 Thread Ho, Tony
, July 17, 2002 11:43 AM To: '[EMAIL PROTECTED]' Subject: Multi-dimensional arrays and subroutines Hi Guys I was wondering if you could help me. I have a multi-dimensional array and I would like to pass it to a subroutine as follows : my @multi_array = ([1,2,3,4], [5,6,7,8]); my

Re: Multi-dimensional arrays and subroutines

2002-07-17 Thread Jeff 'japhy' Pinyan
On Jul 17, Ho, Tony said: $sth-bind_param(1, @$_-[0]); You've already fixed your problem, so that's good, but I would use $sth-bind_param(1, $_-[0]); instead of $sth-bind_param(1, @$_-[0]); Yours works by some bizarre coincidence of Perl's parsing. It should be considered a

Arrays as subroutines arguments

2001-07-26 Thread Diego Riaño
Hi How can I pass two arrays as subroutine arguments? thanks in advances -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Arrays as subroutines arguments

2001-07-26 Thread Maxim Berlin
Hello Diego, Thursday, July 26, 2001, Diego Riaño [EMAIL PROTECTED] wrote: DR How can I pass two arrays as subroutine arguments? passing arrays as arguments is bad idea; you should use references. my_sub(\@array1, \@array2); sub my_sub { my ($ref1,$ref2) = @_; print $$ref1[0], $$ref2[0]; }