in reply to Counting frequency of strings in files

Welcome to Perl and to programming!.

To solve this problem Hash comes to mind. The code below open a new file to be read into i.e "freq_file.txt", and a file to read from. Print in the new file the values matched and it's frequency. See below:

#!/usr/bin/perl use warnings; use strict; print "Enter the name of your file, ie myfile.txt: ",; chomp( my $file = <STDIN> ); my %found; open my $fh, '>', 'freq_file.txt' or die "can't open this file: $!"; open my $fh2, '<', $file or die "can't open this file: $!"; while ( my $line = <$fh2> ) { $found{$_}++ foreach split /\s+?/, $line; } print $fh "Frequence\tValue Found", $/; print $fh $_, "\t\t", $found{$_}, $/ foreach sort keys %found; close $fh2 or die "can't close file: $!"; close $fh or die "can't close file: $!";

I hope this helps