#!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"); }
In reply to calculating lines by Yoda_Oz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |