You have a lot of duplication in your code so I cleaned it up a bit and removed some redundant code.

#!/usr/bin/perl use warnings; use strict; use List::Util qw/ max sum /; my %file_types = ( ENG => 'ENGLISH', AFR => 'AFRIKAANS', NDB => 'NDEBELE', SEP => 'SEPEDI', SIS => 'SISWATI', SOT => 'SOTHO', TSO => 'TSONGA', TSW => 'TSWANA', VEN => 'VENDA', XHO => 'XHOSA', ZUL => 'ZULU', ); my %words; for my $file ( <korpus*.txt> ) { $file =~ /\Akorpus([A-Z]{3})\.txt\z/ or next; my $type = $1; exists $file_types{ $type } or next; local $/; open my $FH, '<', $file or die "Cannot open '$file' because: $!"; @{ $words{ $type } }{ grep length, split /\n/, <$FH> } = (); } ############################################################# my $input; do { print "To classify a single file, press 1\nTo work within a direct +ory, press 2\n"; chomp( $input = <STDIN> ); } until $input =~ /\A[12]\z/; if ( $input == 1 ) { print "Please type the name of the file you wish to classify\n"; chomp( my $filename = <STDIN> ); folder( $filename ); } else { my $dir = 'C:\Users\ZB\Desktop\Text Files'; opendir my $DIR, $dir or die "cannot opendir $dir"; for my $file ( map "$dir/$_", readdir $DIR ) { next unless -f $file; folder( $file ); } } ###################################################################### +############################ sub folder { my ( $fname ) = @_; open my $FIN, '<', $fname or die "Cannot open '$fname' because: $! +"; my %hash; while ( <$FIN> ) { while ( /(\w+)/g ) { $hash{ lc $1 }++; } } ###################################################### my $total = sum values %hash; my @highest = ( '', 0 ); for my $type ( keys %file_types ) { my $percentile = sum( @hash{ keys %{ $words{ $type } } } ) / $ +total; @highest = ( $type, $percentile ) if $highest[ 1 ] < $percenti +le; } ########################################################## D +etermine lingo through percentiles print "The file '$fname' is $file_types{ $highest[ 0 ] }\n"; }

In reply to Re: No such file or directory error by jwkrahn
in thread No such file or directory error by Dr Manhattan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.