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 connect to SQL server through Perl?
what is Chop & Chomp function does?
Explain chomp?
How interpreter is used in perl?
What are the different types of perl operators?
Write a script for 'count the no.of digits using regular expressions in perl..
Which of these is a difference between Perl and C++ ?
Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?
What is a chop() function in perl?
How to copy a file in perl?
What is perl unshift array function?
What is cpan ? What are the modules coming under this?