<INPUT>

G

Gabriel

How can I do a program that receive a file or any string, and count its
\t, \n or anything that I want?

perl miprogram jjjj.txt
\n ---> 12
\t ---> 7

or

perl miprogram bla blablba bal balb balba
\n ---> 1
\t ---> 0


Thanks.
 
A

anno4000

Gabriel said:
How can I do a program that receive a file or any string, and count its
\t, \n or anything that I want?

perl miprogram jjjj.txt
\n ---> 12
\t ---> 7

or

perl miprogram bla blablba bal balb balba
\n ---> 1
\t ---> 0

How would your program know that the first text is a file name and
the second a literal text to run the count on? You'll have to specify
that somehow.

Apart from that, Perl's tool for character counting id tr///. Look it
up in perlop.

Anno
 
B

Brian Wakem

Gabriel said:
How can I do a program that receive a file or any string, and count its
\t, \n or anything that I want?

perl miprogram jjjj.txt
\n ---> 12
\t ---> 7

or

perl miprogram bla blablba bal balb balba
\n ---> 1
\t ---> 0


perldoc -q count
 
M

Mirco Wahab

Gabriel said:
How can I do a program that receive a file or any string, and count its
\t, \n or anything that I want?

perl miprogram jjjj.txt
\n ---> 12
\t ---> 7

or

perl miprogram bla blablba bal balb balba
\n ---> 1
\t ---> 0

In addition to the correct ways - which were
already mentioned, you could always use
someting 'traditional' like (under *n*x) -
- count anything (eg. the string "XYZ") that
is in file "file.dat":

$ perl -0777 -ne 'print 0+@{[/XYZ/g]}' file.dat

or, count something that comes on a
string, eg. the "\n":

$ echo 'some \
text \
with \
newlines \
here ' | perl -0777 -ne 'print 0+@{[/\n/g]}'

(returns: "5" !)

But stick to the perldoc variants
(which were mentioned before) if
possible.

Regards

Mirco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top