Logo F2FInterview

Perl Interview Questions

Q   |   QA

#!usr/bin/perl
use strict;
use warnings;
my $mainstring="APerlAReplAFunction";
my $count = ($mainstring =~ tr/A//);
print "There are $count As in the given string\n";
print $mainstring;

By using the dot operator which concatenates strings in Perl.
Eg. $string = “My name is”.$name

If duplicates need to be removed, the best way is to use a hash.
Eg:

sub uniqueentr {
return keys %{{ map { $_ => 1 } @_ }};
}
@array1 = ("tea","coffee","tea","cola”,"coffee");
print join(" ", @array1), "\n";
print join(" ", uniqueentr(@array1)), "\n";

Use strict command calls the strict pragma and is used to force checks on definition and usage of variables, references and other barewords used in the script. If unsafe or ambiguous statements are used, this command stops the execution of the script instead of just providing warnings.

-a - automatically splits a group of input files
-c - checks the syntax of the script without executing it
-d - invokes the PERL debugger after the script is compiled
-d:module - script is compiled and control is transferred to the module specified.
-d - The command line is interpreted as single line script
-S - uses the $PATH env variable to locate the script
-T - switches on Taint mode
-v - prints the version and path level of the interpreter
-w - prints warnings

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: