Re: more example code Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Zachary Buckholz
ECTED]] > > Sent: Wednesday, July 10, 2002 12:26 PM > > To: Timothy Johnson; [EMAIL PROTECTED] > > Cc: Shawn; Connie Chan; [EMAIL PROTECTED] > > Subject: more example code Re: help dereferencing arrayref so > > I can put > > the value into a hash > &g

Re: more example code Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Zachary Buckholz
olz [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, July 10, 2002 12:26 PM > > To: Timothy Johnson; [EMAIL PROTECTED] > > Cc: Shawn; Connie Chan; [EMAIL PROTECTED] > > Subject: more example code Re: help dereferencing arrayref so > > I can put > > the valu

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Jeff 'japhy' Pinyan
On Jul 10, bob ackerman said: >you get a warning with @x[2] if 'x' is an array, >but no warning with @$x[2] where 'x' is an array ref. >so perl isn't handling quite the same. Well, let me refer to the source. toke.c is where the "scalar value @x[1] better written as $x[1]" comes from. To raise

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread bob ackerman
On Wednesday, July 10, 2002, at 09:05 AM, Jeff 'japhy' Pinyan wrote: > On Jul 10, bob ackerman said: > >> and, as someone pointed out, this does work: >> $x = ['abc','def','ghi']; >> print @$x[2]."\n"; # prints 'ghi' >> >> but i couldn't tell you how perl reads this, except to say that '@

RE: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Timothy Johnson
>Am I alone in thinking that $x->[2] is much more readable that @$x[2] or $$x[2]? IMHO, you are just asking for trouble whenever you use notation like "$$x[2]". You should always put the curly braces around the scalar being dereferenced to be sure that you or someone reading your code doesn't

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Jeff 'japhy' Pinyan
On Jul 10, bob ackerman said: >> All lists get auto-cast into a scalar, in scalar context. An array slice >> is merely a list of array elements. >> >> $x = @y[2]; >> >> is the same as >> >> $x = ($y[2]); > >except you will get warnings on these lines. Perl warns about @x[$i] because it was

RE: more example code Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Bob Showalter
> -Original Message- > From: Zachary Buckholz [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, July 10, 2002 12:26 PM > To: Timothy Johnson; [EMAIL PROTECTED] > Cc: Shawn; Connie Chan; [EMAIL PROTECTED] > Subject: more example code Re: help dereferencing arrayref so >

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread bob ackerman
On Wednesday, July 10, 2002, at 09:39 AM, Jeff 'japhy' Pinyan wrote: > On Jul 10, George Schlossnagle said: > >> Am I alone in thinking that $x->[2] is much more readable that @$x[2] >> or $$x[2]? > > No; I always use the $ref->... syntax, unless I'm golfing. > >> @b[2] is an array slice with

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Jeff 'japhy' Pinyan
On Jul 10, George Schlossnagle said: >Am I alone in thinking that $x->[2] is much more readable that @$x[2] >or $$x[2]? No; I always use the $ref->... syntax, unless I'm golfing. >@b[2] is an array slice with a single element (which strangely seems to >get auto-cast as a scalar). All lists

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread bob ackerman
On Wednesday, July 10, 2002, at 09:29 AM, George Schlossnagle wrote: >> and, as someone pointed out, this does work: >> $x = ['abc','def','ghi']; >> print @$x[2]."\n"; # prints 'ghi' > > > Am I alone in thinking that $x->[2] is much more readable that @$x[2] > or $$x[2]? i was only sa

more example code Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Zachary Buckholz
s); } sub get_pct_up_time($sum_checks, $sum_errors) { my $sum_checks = $_[0]; my $sum_errors = $_[1]; my @pct_up_time; for(my $i = 0; $i <= 6; $i++) { if(@$sum_checks[$i] == 0) {next;}; my $sum_good = @$sum_checks[$i] - @$sum_errors[$i]; $pct_up_time[$i] = (($sum_good * 100) /

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread George Schlossnagle
> and, as someone pointed out, this does work: > $x = ['abc','def','ghi']; > print @$x[2]."\n"; # prints 'ghi' Am I alone in thinking that $x->[2] is much more readable that @$x[2] or $$x[2]? > > but i couldn't tell you how perl reads this, except to say that '@$x' > dereferences and

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Jeff 'japhy' Pinyan
On Jul 10, bob ackerman said: >and, as someone pointed out, this does work: >$x = ['abc','def','ghi']; >print @$x[2]."\n"; # prints 'ghi' > >but i couldn't tell you how perl reads this, except to say that '@$x' >dereferences and then '[2]' gets the array element. >but i don't know why a '$

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread bob ackerman
On Wednesday, July 10, 2002, at 01:31 AM, Janek Schleicher wrote: > Shawn wrote at Wed, 10 Jul 2002 09:59:54 +0200: > >> I think what you are looking for is: >> $avg_resp_time->[0] >> >> if you want to have the '@' at the front, I think you would need >> something like this: >> @{$avg_resp_t

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Janek Schleicher
Shawn wrote at Wed, 10 Jul 2002 09:59:54 +0200: > I think what you are looking for is: > $avg_resp_time->[0] > > if you want to have the '@' at the front, I think you would need something like this: > @{$avg_resp_time}[0] > What should be better written as ${$avg_resp_time}[0] if you want to

RE: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Timothy Johnson
s: $avg_resp_time is an array reference. Get the first element of the dereferenced array. ## -Original Message- From: Zachary Buckholz [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 09, 2002 11:31 PM To: [EMAIL PROTECTED] Subject: help derefe

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Shawn
"Zachary Buckholz" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I understand how to use a foreach on a reference to an array as follows: > > my $avg_resp_time = get_avg_resp_time($durations, $url_id); > foreach my $avg_resp(@$avg_resp_time) { > print

Re: help dereferencing arrayref so I can put the value into a hash

2002-07-10 Thread Connie Chan
> But how do I directly access one array value from the reference to the > array? > > print "DEBUG TEST @$avg_resp_time[0]\n";Fails > print "DEBUG TEST @$avg_resp_time->[0]\n";Fails > print "DEBUG TEST @{$avg_resp_time[0]}\n";Fails > Why don't just print "DEBUG TEST $avg_resp_time

RE: help dereferencing arrayref so I can put the value into a hash

2002-07-09 Thread Toby Stuart
2002 4:31 PM To: [EMAIL PROTECTED] Subject: help dereferencing arrayref so I can put the value into a hash I understand how to use a foreach on a reference to an array as follows: my $avg_resp_time = get_avg_resp_time($durations, $url_id); foreach my $avg_resp(@$avg_resp_time) { print

help dereferencing arrayref so I can put the value into a hash

2002-07-09 Thread Zachary Buckholz
I understand how to use a foreach on a reference to an array as follows: my $avg_resp_time = get_avg_resp_time($durations, $url_id); foreach my $avg_resp(@$avg_resp_time) { print "AVG = $avg_resp\n"; } But how do I directly access one array value from the reference to the array? print "