in reply to Perl File Handling

Ok, since you look like you are starting with Perl and maybe missed a couple of classes ;) I'll give you a couple of pointers :)

Opening and closing files:

Open a file with  open(); function. I recommend something like this :

#!/usr/bin/perl use strict; use warnings my $file = "Name.txt"; open(IN, "<", $file) or die "I cannot open a file: $file "; # close file: close IN;
I would be nice if you checked out what "IN", "<" stand for :)
Once you have opened the file you are ready for reading it. Please thank all mighty Perl for being able to read files line by line by default. To do that all you need to do is to loop through a file with a while loop. Now, how will you know where your file is?. Well, by opening a file you placed your file handle into "IN" variable. (I am trying to make this as simple as possible to understand for someone not familiar with programming, therefore you can read my previous sentence as : put my file in "IN"). once you have done that go through it:
#!/usr/bin/perl use strict; use warnings my $file = "Name.txt" open(IN, "<", $file) or die "I cannot open a file: $file "; while(my $line =<IN>){ ## reading a file line by line # here you need to put some regular expression to identify your web +addresses }
Ok, how do we compute percentage. well we count the total amount of www's and the number of each one separately and divide each by the total. Here it would be nice to have some kind of table like this one:
www.1 5 www.2 7 www.3 2 ...
Now again, Thank you Perl for hash tables!!! Hash tables are very simple, you have a key (the first column) and a value (second column) and every time you ask for a www address all you need to do is something like this:
#hey, what is my current count for www.2 ? my $value = $hash{"www.2"}; print "$value\n"; # What does "\n" stand for?
Ok we mastered hashes, now let put all this together:
#!/usr/bin/perl use strict; use warnings my $file = "Name.txt"; open(IN, "<", $file) or die "I cannot open a file: $file "; my %hash = (); while(my $line =<IN>){ ## reading a file line by line # here you need to put some regular expression to identify your web +addresses # from regular expression extract the WWW address and put it into so +me variable like my $www = $1; #hey, what is my current count for some www ? my $value = $hash{$www}; #OK, cool add one to it :) $value = $value + 1; #Good, now put it back. $hash{$www} = $value; } #close file close IN; # Print my averages foreach my $key (keys %hash){ print "$key\t" . (($hash{$key}/$total)*100) . "\%\n"; # hey where di +d my $total come from (I'll leave that to you :))? }
I believe this is enough to get you started :)

Cheers

baxy