Richard Monson-Haefel wrote:
> Here is the Perl program
> 
> http://www.rafb.net/paste/results/4px8PI74.html

Here it is:

  #!/usr/bin/perl -w
 
  @l = @ARGV;
  print "@l\n";
  @r = ();
  foreach $x(@l){
      if(length($x) <= 3){
          push(@r, $x);
      }
  }
  $y = @r;
  print $y;
  foreach $y(@r){
      print $y."\n";
  }

Here's an equivalent, but shorter version:

   #!/usr/bin/perl
   print "@ARGV\n";
   print "$_\n" for grep length($_) <= 3, @ARGV;

> If there is a more efficient, but readable way to write the script
> (especially, it would see the first for loop which filters out names
> longer than 4 characters) I would really appreciate it.

This is an equivalent program:

   #!/usr/bin/perl
   print "@ARGV\n";
   print "$_\n" for grep length($_) <= 3, @ARGV;

HTH

-- 
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