Wijaya Edward wrote:
Hi Mark,
Edward, for a beginner, would you mind explaining what the
>(1 .. $#arr)
$#arr is the index of the last element in the array
ok, so 1 .. $#arr is the same as 1 .. 2 where 2 is the index of b, yes..?
and qw actually do in this code.? Cheers
Mark Sargent <[EMAIL PROTECTED]> asked:
> >>$ perl -e '
> >>@arr = qw (a b c);
> >> foreach(1 .. $#arr)
> >>{
> >> print "$arr[$_]\n";
> >>}'
> Edward, for a beginner, would you mind explaining what the (1
> .. $#arr) and qw actually do in this code.? Cheers
I'm not Edward, but I'll give it a
Hi Mark,
> >
>
> Edward, for a beginner, would you mind explaining what the
>(1 .. $#arr)
$#arr is the index of the last element in the array
> and qw actually do in this code.? Cheers
with "qw" you are treating values inside as individual words
automatically. Thus you don't need to put quo
$ perl -e '
@arr = qw (a b c);
foreach(1 .. $#arr)
{
print "$arr[$_]\n";
}'
prints:
b
c
Is that what you want?
--
Regards,
Edward WIJAYA
SINGAPORE
Hi All,
Edward, for a beginner, would you mind explaining what the (1 .. $#arr)
and qw actually do in this code.? Cheers
Mark Sarg
Hi,
[EMAIL PROTECTED] <[EMAIL PROTECTED]> asked:
> How do I get a for each-statement to start at element 1
> (second element)
# probably bad for long lists
foreach my $item ( @list[1..$#list] ){
...
}
# quick but destroys @list
foreach my $item ( splice @list,1 ){
...
}
Of course, you coul
Hi there!
Yes, exactly. Thanx a lot! :-)
/G
>
>
> - Original Message -
> From: [EMAIL PROTECTED]
> Date: Friday, October 7, 2005 3:29 pm
> Subject: for each
>
>> Hi there!
>>
> Hi!
>
>> How do I get a for each-statement to start at element 1 (second
>> element)
>
> $ perl -e '
> @arr = q
- Original Message -
From: [EMAIL PROTECTED]
Date: Friday, October 7, 2005 3:29 pm
Subject: for each
> Hi there!
>
Hi!
> How do I get a for each-statement to start at element 1 (second
> element)
$ perl -e '
@arr = qw (a b c);
foreach(1 .. $#arr)
{
print "$arr[$_]\n";
}'
prints: