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 connect to SQL server through Perl?

0 Answers  


what is Chop & Chomp function does?

0 Answers  


Explain chomp?

0 Answers  


How interpreter is used in perl?

0 Answers  


What are the different types of perl operators?

0 Answers  






Write a script for 'count the no.of digits using regular expressions in perl..

6 Answers   AppLabs,


Which of these is a difference between Perl and C++ ?

0 Answers  


Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?

0 Answers  


What is a chop() function in perl?

0 Answers  


How to copy a file in perl?

0 Answers  


What is perl unshift array function?

0 Answers  


What is cpan ? What are the modules coming under this?

0 Answers  


Categories