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

How to remove a directory in perl?

0 Answers  


What are scalars in perl?

0 Answers  


What is stdin in perl?

0 Answers  


what is the difference b/w coldfusion MX 6 and Coldfusion MX 7?

1 Answers  


Explain goto expr?

0 Answers  


What are prefix dereferencer?

0 Answers  


What are the two ways to get private values inside a subroutine?

0 Answers  


Which feature of Perl provides code reusability ? Give any example of that feature.

1 Answers  


What arguments do you frequently use for the Perl interpreter and what do they mean?

4 Answers  


How to close a directory in perl?

0 Answers  


What is posix in perl?

0 Answers  


What are some of the key features of objects in perl?

0 Answers  


Categories