Hi again,
Thanks all, for your good advices!
I wrote some scripts which all worked from bits of peaces from the list -
but I have a question on performance:
1.
First I tried the to use a "while" loop by:
__________________________________________________________
#! /usr/bin/perl -w
use List::Util qw(first max min);
open IN, "<", "num.txt";
while ($xx = <IN>) {
chomp $xx;
my @xx = split (/\s+/, $xx);
push @col1, $xx[0];
}
$result1 = max @col1;
$result3 = min @col1;
$result7 = sum @col1;
print "Max: $result1\n";
print "Min: $result3\n";
print "Sum: $result7\n";
close IN;
______________________________________________________________
2.
I tried to use Janek's (and thanks for the advice - see below) advice on
Tie:File which also worked!
But there was a great diffrence in performance.
With a two collumn file of 300000 lines - it took example no. 1 appr. 20 sek
and example 2 appr. 5 min. and used all of the computers RAM (128MB).
Why is the diffrence that big? Is it bacause Tie::File sucks it all into
memmory and do something with it?
A note to the last part: I tried to use:
my @in = <IN>;
foreach $xx (@in) { ---and so on
instead of the "while" loop and that took appr. 30 sek - alas not as slow as
"Tie"
Cheers,
Jakob
> -----Oprindelig meddelelse-----
> Fra: Janek Schleicher [mailto:[EMAIL PROTECTED]
> Sendt: 6. august 2003 12:10
> Til: [EMAIL PROTECTED]
> Emne: Re: List::Util / arrays
>
>
> Jakob Kofoed wrote at Tue, 05 Aug 2003 23:33:29 +0200:
>
> > I am trying to get the maximum number in a file looking like:
> >
> > 1 5001
> > [...]
> > 19 5019
> >
> >
> > I had the idea to push the individual line in a row into a
> array and se
> > the List::Util module - but I cant get it to work.
>
> Yet another solution might be
>
> use Tie::File;
> use List::Util qw/max/;
>
> tie my @line, 'Tie::File', $filename;
> print max map {(split)[1]} @line;
>
>
> Greetings,
> Janek
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]