On Aug 6, Jakob Kofoed said:

>use List::Util qw(first max min);

You don't use first(), so don't both exporting it.

>open IN, "<", "num.txt";
>
>while  ($xx = <IN>) {
>       chomp $xx;
>       my @xx = split (/\s+/, $xx);
>       push @col1, $xx[0];


Those three lines could just be:

  push @col1, (split ' ', $xx)[0];

Or even better, make the while loop:

  while (<IN>) {
    push @col1, (split)[0];
  }

But it's up to you.

>}
>
>$result1 = max @col1;
>$result3 = min @col1;
>$result7 = sum @col1;

But here's the thing... you don't need an array for any of this.  Just
keep a running count:

  my ($min, $max, $sum);
  while (<IN>) {
    my $n = (split)[0];
    $min = $n if not defined $min or $min > $n;
    $max = $n if not defined $max or $max < $n;
    $sum += $n;
  }
  print "min=$min\nmax=$max\nsum=$sum\n";

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to