in reply to number array with space

Hi MynameisAchint,
To really get the help you want it will be wonderful if you follow the advice giving in How do I post a question effectively?.

...I wish to run a for loop for that array...
Instead of using a for loop as used in C, why not use for/foreach as Perl like thus:

my @array_data = qw( 21 45 perl 28 monks); foreach my $data (@array_data){ print $data,"\n"; }
Update:
However, if you want to iterate over the array, using the index of the array, Perl also does that for you very cleanly.
my @array_data = (21,45,'perl',28,'monks',' ','togo'); for my $num (0..$#array_data){ print $num,': ',$array_data[$num],"\n"; }
0: 21 1: 45 2: perl 3: 28 4: monks 5: 6: togo
Please, note that I used foreach and for inter-changeably.
And please don't forget that array index start from 0 and not 1, as used in your OP for loop.
Hope this helps

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: number array with space
by CountZero (Bishop) on Jun 20, 2013 at 06:15 UTC
    Or a more Perlish way of using indexes (works only in a fairly recent version of Perl):
    use Modern::Perl; my @array = qw/een twee drie vier vijf zes zeven/; for my $index (keys @array) { say "$index: $array[$index]"; }

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

      (works only in a fairly recent version of Perl):
      of course yes! in Perl 5.12 or better !!!. Nice one...

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me
        Hey

        one more question that how to check whether the element in an array is a number or not . is there any function in perl