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
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
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
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 '@
>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
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
> -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
>
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
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
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
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) /
> 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
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 '$
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
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
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
"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
> 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
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
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 "
20 matches
Mail list logo