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 create a package?
How can you use Perl warnings and what is the importance to use them?
How does a “grep” function perform?
How do you give functions private variables that retain their values between calls?
Which feature of perl provides code reusability?
How will you open a file in a write-only mode in perl?
Difference between Perl and Mod_perl?
How to dereference a reference?
How do I send e-mail from a Perl/CGI program on a Unix system?
What does the qq{ } operator do?
How the interpreter is used in Perl?
What is the closure in PERL?