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



How would you replace a char in string and how do you store the number of replacements? ..

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

How would you replace a char in string and how do you store the number of replacements? ..

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

Post New Answer

More CGI Perl Interview Questions

Explain chomp?

1 Answers  


Differences between die and exit.

1 Answers  


How many ways can we express string in Perl?

1 Answers  


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 ?

1 Answers  


What rules must be followed by modules in perl.

1 Answers  


How to concatenate strings in perl?

1 Answers  


For a situation in programming, how can you determine that Perl is a suitable?

1 Answers  


Explain regular expression in perl?

1 Answers  


What is the easiest way to download the contents of a URL with Perl?

1 Answers  


What is the main function of cookie server?

1 Answers  


What is stdin in perl?

1 Answers  


How can you create an object of a class in a package?

4 Answers   IBM,


Categories