Yoda_Oz has asked for the wisdom of the Perl Monks concerning the following question:
#!usr/local/bin/perl use strict; use warnings; my %lineHash; my @lineArray; print ("Enter filename to count lines: "); my $path=<STDIN>; print ("\n"); open(DATA, "<$path") || die "Couldn't open $path for reading: $!\n"; while (<DATA>) { while (s/(\n)(.*)/$2/) { my $count = $1; $lineHash{$count}++; } } close (DATA); my %charname = ( "\n" => "Lines" ); while ( my ($lines, $count) = each(%lineHash) ) { push @lineArray, "$count\t$lines"; print ("$count\t$charname{$lines}\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: calculating lines
by Zaxo (Archbishop) on Jan 12, 2007 at 00:25 UTC | |
by Yoda_Oz (Sexton) on Jan 12, 2007 at 00:42 UTC | |
by Zaxo (Archbishop) on Jan 12, 2007 at 00:54 UTC | |
by Yoda_Oz (Sexton) on Jan 12, 2007 at 01:35 UTC | |
by Zaxo (Archbishop) on Jan 12, 2007 at 01:44 UTC | |
by Yoda_Oz (Sexton) on Jan 12, 2007 at 01:02 UTC | |
by Zaxo (Archbishop) on Jan 12, 2007 at 01:15 UTC | |
by Yoda_Oz (Sexton) on Jan 12, 2007 at 01:17 UTC |