please try this one:

#tested in linux
#!/usr/bin/perl -w
use strict;

my @names = qw( fred barney betty wilma dino );
print "Enter some numbers 1 to 5, one per line, then press ctrl D:\n";
chomp (my @numbers = <STDIN>);
foreach (@numbers){
  if ($_ < 6){
       print "$names[$_ - 1]\n";
           }else{
                print "Error: choose numbers less then 6!\n";
                }
         }




On 6/4/05, Hakim Singhji <[EMAIL PROTECTED]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi All,
> 
> This is my first post at beginners. I am working with Learning Perl
> (Llama!) and I like to tweak some of the problems and create more
> creative solutions to some things. I cannot figure out why this is not
> working. Can anyone point out an error in my code.
> 
> #! Perl
> 
> @names = qw( fred barney betty wilma dino );
> print "Enter some numbers 1 to 5, one per line, then press ctrl Z:\n";
       
 ctrl + D should be used
> chomp (@numbers = <STDIN>);
> ~  if (@numbers > 5) {
           @number > 5 means the number of element in array @number 
is large than 5.
         it does not mean the element is large than 5.

>           print "Error: choose numbers less then 6!\n";
> ~  } else {
>           foreach (@numbers); {
                                          ~~~ no ; here 
>                   print "$names[ $_ - 1 ]\n";
>           }
           need another } here to comparable with "if (@numbers > 5) {"
> Best,
> - --
> Hakim Singhji
> New York University
> [EMAIL PROTECTED]
> http://i5.nyu.edu/~hzs202
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFCoTsjs2AZ6g3dZu8RAtAdAJ44jsNG/TUOiP4kDyuZWN3tWIrrFQCdFB+V
> WKsRYfcrHasOTOB4lhrlMOg=
> =K40v
> -----END PGP SIGNATURE-----
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


-- 
Do not guess who  I am.  I am not Bush in BlackHouse

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to