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 |
What is the difference between module and package?
What is cpan ? What are the modules coming under this?
What is the usage of -i and 0s options?
How will you create a file in perl?
what are the strategies followed for multiple form interaction in cgi programs?
Why aren't Perl's patterns regular expressions?
Why does Perl not have overloaded functions?
Explain USE and REQUIREMENT statements?
How would you ensure the re-use and maximum readability of your perl code?
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
How do I pass a command line argument in perl?
What is the use of '>>' in perl?