Beruflich Dokumente
Kultur Dokumente
Perl
$pvt=Calculation(5,5)
print("Result=$pvt\n")
1 $pvt = Calculation(5,5);
2
3 print("Result = $pvt\n");
4
5 sub Calculation{
6
7 my ($fstVar, $secndVar) = @_;
8
9 my $square = sub{
10
11 return($_[0] ** 2);
12
13 };
14
15 return(&$square($fstVar) + &$square($secndVar));
16
17 };
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 1/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Output: Result = 50
Perl
PackageParent
Subfoo
1 Package Parent;
2
3 Sub foo
4
5 {
6
7 print("Inside A::foo\n");
8
9 }
10
11 package Child;
12
13 @ISA = (Parent);
14
15 package main;
16
17 Child->foo();
18
19 Child->bar();
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 2/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Perl
$sum=0
$count=0
1 $sum = 0;
2
3 $count = 0;
4
5 print "Enter number: ";
6
7 $num = <>;
8
9 chomp($num);
10
11 while ($num >= 0)
12
13 {
14
15 $count++;
16
17 $sum += $num;
18
19 print "Enter another number: ";
20
21 $num = <>;
22
23 chomp($num);
24
25 }
26
27 print "$count numbers were entered\n";
28
29 if ($count > 0)
30
31 {
32
33 print "The average is ",$sum/$count,"\n";
34
35 }
36
37 exit(0);
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 3/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
[http://career.guru99.com/wp-
content/uploads/2012/06/Perl.gif]
Syntax:
Program:
Perl
#!/usr/bin/perl
$firststring="abcd"
1 #!/usr/bin/perl
2
3 $rststring = "abcd";
4
5 $secondstring = "efgh";
6
7 $combine = "$rststring $secondstring";
8
9 print "$Combine\n";
Output:
abcd efgh
perlpi.bake's/\t/,/g'myfile.txt
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 4/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
-e (which executes)
-wd
Perl
my@arrayvar=(stringa,stringbstringc)
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 5/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
use
require
4. Loads at run-time.
use Module;
or
require Module.pm;
$test=2.3456
1 $test = 2.3456;
2
3 {
4
5 my $test = 3;
6
7 print "In block, $test = $test ";
8
9 print "In block, $:: test = $:: test ";
10
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 6/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
10
11 }
12
13 print "Outside the block, $test = $test ";
14
15 print "Outside the block, $:: test = $::test ";
Output:
In block, $test = 3
Perl
#!/usr/bin/perl
1 #!/usr/bin/perl
Perl
[perl]
packageX
subfoo
1 [perl]
2 package X;
3
4 sub foo
5
6 {
7
8 print("Inside X::foo\n");
9
10 }
11
12 package Z;
13
14 @ISA = (X);
15
16 sub foo
17
18 {
19
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 8/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
19
20 print("Inside Z::foo\n");
21
22 }
23
24 package main;
25
26 Z->foo();
27 [/perl]
Inside Z::foo
If you need faster execution the Perl will provide you that
requirement. There a lot of exibility in programming if
you want to develop a web based application. We do not
need to buy the license for Perl because it is free. We can
use CPAN (Comprehensive Perl Archive Network), which
is one of the largest repositories of free code in the
world.
Perl
@arrayvar=(@array1,@array2)
1 @arrayvar = (@array1,@array2);
Arithmetic operators
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 9/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
+, ,*
Assignment operators:
+= , -+, *=
++,
String concatenation:
. operator
comparison operators:
Logical operators:
&&, ||, !
Perl
usestrict
usewarnings
1 use strict;
2
3 use warnings;
4
5 my @checkarray;
6
7 if (@checkarray)
8
9 {
10
11 print "Array is not empty";
12
13 }
14
15 else
16
17 {
18
19 print "Array is empty";
20
21 }
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 10/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Perl
@arraycontent=(ab,cd,ef,gh)
foreach(@arraycontent)
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 11/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Perl
#!/usr/bin/perl
usestrict
1 #!/usr/bin/perl
2
3 use strict;
4
5 use warnings;
6
7 use LWP::Simple;
8
9 my $siteurl = 'www.perlinterview.com/answers.php';
10
11 my $savele = 'content.kml';
12
13 getstore($siteurl, $savele);
Perl
grepBLOCKLIST
grep(EXPR,LIST)
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 12/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Perl
subSymbols
1 sub Symbols
2
3 {
4
5 my($hashRef) = shift;
6
7 my(%sym);
8
9 my(@sym);
10
11 %sym = %{$hashRef};
12
13
14 @sym = sort(keys(%sym));
15
16 foreach (@sym)
17
18 {
19
20 printf("%-10.10s| %s\n", $_, $sym{$_});
21
22 }
23
24 }
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 13/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
24 }
25
26 Symbols(\%Foo::);
27
28 package Foo;
29
30 $bar = 2;
31
32 sub baz {
33
34 $bar++;
35
36 }
33. How can you use Perl warnings and what is the
importance to use them?
Perl
usewarnings#itissameasimporting"all"
nowarnings#itissameasunimporting"all"
Perl
for($count=10$count>=1$count)
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 14/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
{
Perl
#!usr/bin/perl
usestrict
1 #!usr/bin/perl
2
3 use strict;
4
5 use warnings;
6
7 my $string="APerlAReplAFunction";
8
9 my $counter = ($string =~ tr/A//);
10
11 print "There are $counter As in the given string\n";
12
13 print $string;
Perl
subuniqueentr
1 sub uniqueentr
2
3 {
4
5 return keys %{{ map { $_ => 1 } @_ }};
6
7 }
8
9 @array = ("perl","php","perl","asp);
10
11 print join(" ", @array), "\n";
12
13 print join(" ", uniqueentr(@array)), "\n";
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 15/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Perl
%birthdate=(Ram=>"01011985",
Vinod=>"22121983",
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 16/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Perl
usestrict
open(IN,"in")
1 use strict;
2
3 open(IN,"in");
4
5 my @lines = <IN>
6
7 close(IN);
8
9 open(OUT,">out");
10
11 foreach (@lines)
12
13 {
14
15 print OUT m/([^\s]+)/,"\n";
16
17 }
18
19 close(OUT);
Perl
subBLOCK
subPROTOBLOCK
1 sub BLOCK
2
3 sub PROTO BLOCK
4
5 sub ATTRS BLOCK
6
7 sub PROTO ATTRS BLOCK
$-Scalar variables
%-Hash variables
@-arrays
&-subroutines
Perl
@array=qw/abcde/#array
print"n",$array>[0]#itiswrong
4
5 print "n",$array[0]; #it is correct , @array is an array
Perl
excuteScript.plFstArgu.
$argu=$ARGV[0]
1 excuteScript.pl FstArgu.
2
3 $argu = $ARGV[0];
4
5 chomp $argu; --> to get rid of the carrige return.
Perl
useDBI
my$dbh=DBI>connect(dbi:Oracle:orcl,username,password,)
1 use DBI;
2
3 my $dbh = DBI->connect(dbi:Oracle:orcl, username,
password,)
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 19/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
String Concatenation .
Comparison Operators ==, !=, >,< , >=
Logical Operators &&, ll , !
Assignment Operators + = ,- + , *=
Increment and decrement Operators ++ ,-
Arithmetic Operators +, ,*
Die will print a message to the std err before ending the
program while Exit will simply end up the program.
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 20/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 21/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
q(this is guru99)
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 22/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
For example,
perl-d my_le
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 24/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
$- Scalar variables
%-Hash variables
@-Arrays
&-Subroutines
Type globs-*myvar stands for @myvar, %myvar
Perl Quiz
Start
%%FORM%%Congratulations - you have completed Perl
Quiz.You scored %%SCORE%% out of %%TOTAL%%.Your
performance has been rated as %%RATING%%
[]
First
Last
Quiz Name
Score
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 26/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Time used (Requires timer add on). This has the same
value as the %%TIME_USED%% Variable on the Final
Screen.
Submit
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
End
Return
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 27/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
[/#facebook]
[/#twitter]
You Might Like:
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 28/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
Commentsforthisthreadarenowclosed.
Comments Community
1 Login
DaveCrossayearago
"AniValueisascalarvaluewhichcanbeusedtostorethe
resultofanyexpression.Usually,itappearsatthelefthand
sideoftheexpressionandrepresentadataspacein
memory."
No.That'sanlvalue,notanivalue.
Mostofthequestionshereareterribleandtheanswersare
worse.
Share
correctedtolvalue.Thanks!
Share
nikhil2yearsago
foundsyntaxerrorsinthe3rdand4thexampleitself,
dissappointing.
Share
TheerrorswereduetotheuseoftheSyntax
Highlightingpluginwewereusing.Theissueisnow
fixed
1 Share
nikhil>Guru992yearsago
thanksforthequickresponse!
Share
ALSOONCAREERGURU99
Top50VB.NetInterview Top30HiveInterview
Questions&Answers Questions
2comments3monthsago 1comment6monthsago
SamuelNiipleaseineed BalaNiceandUsefull
answerstoit
Whatmotivatesyou? Whatareyourstrengthand
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 29/30
3/15/2017 Top72PerlInterviewQuestionsandAnswers|
http://career.guru99.com/top50perlinterviewquestionsandanswers/ 30/30