I want to calculate the frequency of occurrence of chars in a message using Perl. For instance, if the char "a" appears 10 times in a message, then the frequency would be 10. To do this, I am reading the message from a FILE one char at a time using the getc function. Here's the snippet I have written. It's very basic, I know. But when I compile, I get an error:
Details:
#!/usr/bin/perl
use strict;
use warnings;
my $input=$ARGV[0];
open(INPUT,"<$input");
while(<INPUT>
{
my $c=getc(INPUT);
print $c."\n";
}
close(INPUT);
I get the below error when I try to compile it:
Use of uninitialized value in print at AccessChar.pl line 13, <INPUT> line 1.
I am not able to figure out, what's wrong with this script. Could someone help me out with this?
I have even tried using getc
INPUT instead of getc(INPUT)
. I don't think I need to include any other packages while running this script.