Tag: perl

Problem: perl: warning: Setting locale failed

This is one of the very most common issue most of the people face.

perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "UTF-8", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C").

Read the complete article »

Count number of lines in text file using perl

The best way to do that is to count the number of new line characters in the file. An example for the same is given below:

$lines = 0;
open(FILE, $filename) or die “Can’t open `$filename’: $!”;
while (sysread FILE, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
close FILE;

If your text file doesn’t end with a new …

Read the complete article »