On Thu, 2009-01-29 at 14:39 +0800, itshardtogetone wrote:
> Hi,
> How do I copy the first 10 elements of @a into @b?
>
> The method that I use is long :-
> my @a = 1..20;
> my @b = ();
>
> my $ctr = 0;
> foreach (@a){
> if ($ctr < 10){
> push @b,$_;
> }
> $ctr ++;
> }
See
itshardtogetone wrote:
Hi,
Hello,
How do I copy the first 10 elements of @a into @b?
my @b = @a[ 0 .. 9 ];
John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For
try this,
@b[0..9] = @a[0..9];
- 原邮件 -
从: itshardtogetone
日期: 星期四, 一月 29日, 2009 下午2:39
主题: how to copy elements into the next array
> Hi,
> How do I copy the first 10 elements of @a into @b?
>
> The method that I use is long :-
> my @a = 1..20;
> my @b = ()
Hi,
How do I copy the first 10 elements of @a into @b?
The method that I use is long :-
my @a = 1..20;
my @b = ();
my $ctr = 0;
foreach (@a){
if ($ctr < 10){
push @b,$_;
}
$ctr ++;
}
Thanks.