dReKurCe has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -w our @frequency; our @words; print "Which file requires frequency analysis please?\n"; $phile=<STDIN>; open(PHILE, "+< $phile") ||die "File specified can not be accessed:$!\n"; while (@interval=<PHILE>){ foreach $line(@interval){ chop $line; @werdz=split(/ / ,$line); $space=@werdz; analyize($space,@werdz); } } $initialize="abcdefghijklmnopqrsstuvwxyz"; unshift @words,$initialize; @alpha=alphatrans(); for $word(@words){ $lengh=@word; @letters=split (//, $word); foreach $key(@letters){ $key=uc $key; frequency($key); } } for $row(@frequency){ $lengh= @$row; $unit=$lengh-1; $token=shift @alpha; print " $token= $unit //// "; } sub analyize{ push @words, @werdz; } sub frequency{ $key=pop @_; for$i(0...25){ if( $alpha[$i] eq $key ){ push @{$frequency[$i]},$key; } } } sub alphatrans{ our @nums; our @pass1; foreach $k(0...25){ $i=$k; push (@nums, $k); $k=~ tr/0-9 /A-J/ ; push (@pass1, $k); } foreach $bdiad(@pass1){ if ($bdiad=~/B(.+)/){ push (@b,$bdiad); } } foreach $cdiad(@pass1){ if ($cdiad=~/C(.+)/){ push (@c,$cdiad); } } foreach $y (0..9){ $f=shift @b; $f=$y ; $y=~ tr/0-9/KLMNOPQRST/ ; push (@blist, $y ); } foreach $x (0..5){ $g=shift @c; $g=$x ; $x=~ tr/0-5/UVWXYZ/ ; push (@clist,$x ); } splice (@pass1, 10, 10,@blist); splice (@pass1, 20, 6, @clist); return @pass1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Frequency Analysis with Lists
by dragonchild (Archbishop) on Feb 02, 2005 at 18:49 UTC | |
|
Re: Frequency Analysis with Lists
by trammell (Priest) on Feb 02, 2005 at 18:38 UTC |