How would you replace a char in string and how do you store
the number of replacements?
Answers were Sorted based on User's Feedback
Answer / tanu
$str='Hello';
$cnt= ($str=~s/l/i/g);
print $cnt;
$cnt stores the number of replacements.
Is This Answer Correct ? | 20 Yes | 4 No |
Answer / ananth_s
#!usr/bin/perl
use strict;
use warnings;
my $string="XmanXseriesx";
my $count = ($string =~ tr/X//);
print "There are $count Xs in the string\n";
print $string;
Is This Answer Correct ? | 7 Yes | 1 No |
How to remove a directory in perl?
What are scalars in perl?
What is stdin in perl?
what is the difference b/w coldfusion MX 6 and Coldfusion MX 7?
Explain goto expr?
What are prefix dereferencer?
What are the two ways to get private values inside a subroutine?
Which feature of Perl provides code reusability ? Give any example of that feature.
What arguments do you frequently use for the Perl interpreter and what do they mean?
How to close a directory in perl?
What is posix in perl?
What are some of the key features of objects in perl?