Here's is the another way.Treating the scalar as a file handle.
use strict; use warnings; use IO::Scalar; my $string = "one\ntwo\nthree\nfour\nfive\nsix"; my $scalar_fh = IO::Scalar->new( \$string ); # creating a scalar fi +le handle. my $count = 0; $count++ while (<$scalar_fh> ); print $count;
This is not efficient than using tr. But, you can process a string as file by this way.
In reply to Re: Count number of lines in a STRING
by nagalenoj
in thread Count number of lines in a STRING
by danj35
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |