1) Explain the difference between the following in Perl:
$array[3] vs $array->[3]
Answer:
$array[3] is the 4th element of the array "array"
$array->[3] is the hard reference to a (possible anonymous) array. It's the 4th element of the referenced array.
2) How to remove duplicates from an array?
Answer:
@array=(2,4,3,3,6,2);
my %seen=();
my @unique = grep { !seen{$_}++} @array;
print "@unique";
3) What is Perl on-liner?
Answer:
There are two ways a perl scripts can be run:
1. From a command line, called one-liner. It may contains many statements in one line.
e.g. perl -e "print \"Hello\";"
2. Script file, Perl program
e.g. perl program.pl
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment