dimanche 28 décembre 2014

file name as argument and sort in descending way in perl?


I have this perl script



#!/usr/bin/perl
use strict;
open my $df, '<', 'file.txt' or die "open: $!\n";
my %h;
while (<$df>) {
$h{$_}++ for split /\s+/;
END{
for (keys %h){
print $_, "=", $h{$_};
print "\n";
}
}
}


it prints the occurrence of each word in the file, I have several questions


1) How can I make this script dynamic by let the user put one argument as a file name


Now:



perl script.pl


wanted:



perl script.pl fileName


2) How can I sort the output in descending way?



Aucun commentaire:

Enregistrer un commentaire