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

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

1 Answers  


What are arrays in perl?

0 Answers  


Where do we require ‘chomp’ and what does it mean?

0 Answers  


What does perl do in linux?

0 Answers  


How do you give functions private variables that retain their values between calls?

0 Answers  






Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

0 Answers  


Who created perl?

0 Answers  


How are parameters passed to subroutines in perl?

0 Answers  


Demonstrate subroutines in perl with a simple example.

0 Answers  


Which functions in perl allows you to include a module file. State their differences.

0 Answers  


What package you use to create a windows services?

0 Answers  


Elaborate on perl bite-wise operators.

0 Answers  


Categories