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 |
Explain chomp?
Differences between die and exit.
How many ways can we express string in Perl?
while(my($key, $value) = each(%hash) ) { print "$key => $value\n"; } my($key, $value); while(($key, $value) = each(%hash) ) { print "$key => $value\n"; } What is the different between these two code in case of "my" usage ?
What rules must be followed by modules in perl.
How to concatenate strings in perl?
For a situation in programming, how can you determine that Perl is a suitable?
Explain regular expression in perl?
What is the easiest way to download the contents of a URL with Perl?
What is the main function of cookie server?
What is stdin in perl?
How can you create an object of a class in a package?