dReKurCe has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks

This was inspired by a recent technique for frequency analysis
using hash references.I was curious if the same could be
accomplished by using only lists. The following code is the
result of creative kludge and insight into three dimensional
data structures.
#! /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
    while (@interval=<PHILE>){ foreach $line(@interval){ chop $line; @werdz=split(/ / ,$line); $space=@werdz; analyize($space,@werdz); } }
    is much better written as
    while (<PHILE>) { chomp; my @werdz = split; analyze( scalar @werdz, @werdz ); }

    You also really need to look at adding strict and warnings to your code. *winces*

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Frequency Analysis with Lists
by trammell (Priest) on Feb 02, 2005 at 18:38 UTC
    ... while (@interval=<PHILE>){ ...
    Yowch! Hope you're not working with any huge files!