Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Count number of lines in a STRING

by nagalenoj (Friar)
on May 12, 2010 at 10:17 UTC ( #839592=note: print w/ replies, xml ) Need Help??


in reply to Count number of lines in a STRING

TIMTOWTDI

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.


Comment on Re: Count number of lines in a STRING
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839592]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2015-07-28 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls