Write a script for 'count the no.of digits using regular
expressions in perl..
Answers were Sorted based on User's Feedback
Answer / rajendran
($test,$number) = ("","");
$test = "12344tyyyyy456";
@test=split('',$test);
foreach(@test)
{
if ($_ =~ /\d/)
{$number++;
}
}
print $number;
Is This Answer Correct ? | 10 Yes | 3 No |
Answer / arun janardhanan
Simple guys here we go :-).........
#!/usr/bin/perl -w
use strict;
my($test,$number) = ("","");
$test = "12344tyyyyy456";
$number = ($test =~ tr/[0-9]/[0-9]/);
print "Number of digits in variable is :- $number ";
exit;
Is This Answer Correct ? | 11 Yes | 5 No |
Answer / santha
$testnumber='34535sssss24';
$numbercount=0;
while($testnumber=~m{\d}igs)
{
$numbercount++;
}
print "\n $numbercount";
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / tclgeek
to find the count of no of digits using regular expression in TCL
set val "abbj68689kbj8798797"
set a [regexp {[a-z]+(\d+)[a-z]+(\d+)} $val val1 val2 val3]
if { $a == 1 } {
puts "matched pattern found are : $val2$val3"
puts "the number of digits are [expr [string length $val2] + [string length $val3]]"
} else {
puts "error"
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / anandan
#!/usr/bin/perl -w
use strict;
my($test,$number) = ("","");
@test = "12344tyyyyy456";
foreach(@test)
{
if ($_ =~ /\d/)
{$number++;
}
}
print $number;
Is This Answer Correct ? | 5 Yes | 15 No |
How do I debug a perl program?
How to sort dates in Perl ?
how to search a unique pattern in a file by using perl hash map function ??? plz answer me
Explain regular expression in perl?
Show the use of sockets for the server and client side of a conversation?
What is subroutine in perl?
How will you declare a variable in perl?
What does the qx{ } operator do?
Which guidelines by Perl modules must be followed?
I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur
What are the arguements we normally use for perl interpreter?
How to read a single line from a file in perl?