Perl Basics
////Write a simple program in perl
# ! usr/bin/perl
print "HELLO WORLD \n";
///////PRINT SOME VALUE///////
#!usr/bin/perl
print "\bHELLO WORLD !\x","sharjeel\n","27\n-87\n";
#Print Stringprint "\nMY NAME IS SHARJELL\n";
print '\nMY NAME IS SHAGHIL\n';#Print & Use Operatorprint "Find Module is::-->",14%3,"\n";
print "21 from 52 is::-->",52-21,"\n";
print "51 and with 85 is::-->",51&85,"\n";
print "6 or with 26 is::-->",6|26,"\n";
print "not of 5 is::-->",~5,"\n";
print "6 exclusive or with 26 is::-->",6^26,"\n";
#Truth&FalseHood
#Comparing Number For Equality
print "\nIs two Equaal to four-->",2==4,"\n";
print "\nIs six Equaal to six:-->",6==6,"\n";
print "\n2 is not Equaal to 4:-->",2!=4,"\n";
print "\nCompare 6 and 9:-->",6<=>9,"\n";
print "\nTest ONE::->",6>3 && 3<9,"\n";
#Concat Stringprint "\nString Concat Is::-->","print"."My"."Name"."Here"."4*7"."+","\n";
#FindCharactersValueprint "\nA # Has Ascii value:-->",ord("#"),"\n";
#StringComparison
print "\nIs Compare:-->","chicken"cmp"chicken","\n";print "\nIs Greater Then:-->","cats"gt"egg","\n";
print "\bHELLO WORLD !\x","sharjeel\n","27\n-87\n";
#Print Stringprint "\nMY NAME IS SHARJELL\n";
print '\nMY NAME IS SHAGHIL\n';#Print & Use Operatorprint "Find Module is::-->",14%3,"\n";
print "21 from 52 is::-->",52-21,"\n";
print "51 and with 85 is::-->",51&85,"\n";
print "6 or with 26 is::-->",6|26,"\n";
print "not of 5 is::-->",~5,"\n";
print "6 exclusive or with 26 is::-->",6^26,"\n";
#Truth&FalseHood
#Comparing Number For Equality
print "\nIs two Equaal to four-->",2==4,"\n";
print "\nIs six Equaal to six:-->",6==6,"\n";
print "\n2 is not Equaal to 4:-->",2!=4,"\n";
print "\nCompare 6 and 9:-->",6<=>9,"\n";
print "\nTest ONE::->",6>3 && 3<9,"\n";
#Concat Stringprint "\nString Concat Is::-->","print"."My"."Name"."Here"."4*7"."+","\n";
#FindCharactersValueprint "\nA # Has Ascii value:-->",ord("#"),"\n";
#StringComparison
print "\nIs Compare:-->","chicken"cmp"chicken","\n";print "\nIs Greater Then:-->","cats"gt"egg","\n";
///////////////////IF ELSE STATEMENT/////////////////////
#!usr/bin/perl
print "Eneter some value \n";
$a=<STDIN>;
$a=<STDIN>;
#USE IF Statement
if($a==2){
print "You Enter::-->TWO\n";
}
#Use If Else Statementif($a == 4)
{
print "Value is 4 \n";
}
else($a==5)
{
print "Value is 5 \n";
}#USE If Els Statement
if($a == 4)
{
print "Value is 4 \n";
}
elsif($a==5)
{
print "Value is 5 \n";
}
elsif($a==6)
{
print "Value is 6 \n";
}
elsif($a==7)
{
print "Value is 7 \n";
}
elsif($a==8)
{
print "Value is 8 \n";
}
elsif($a==9)
{
print "Value is 9 \n";
}
////////////////ARRAY/////////////////////
#Use If Else Statementif($a == 4)
{
print "Value is 4 \n";
}
else($a==5)
{
print "Value is 5 \n";
}#USE If Els Statement
if($a == 4)
{
print "Value is 4 \n";
}
elsif($a==5)
{
print "Value is 5 \n";
}
elsif($a==6)
{
print "Value is 6 \n";
}
elsif($a==7)
{
print "Value is 7 \n";
}
elsif($a==8)
{
print "Value is 8 \n";
}
elsif($a==9)
{
print "Value is 9 \n";
}
////////////////ARRAY/////////////////////
#!usr/bin/perl
@record=qw(sun day,mon,tue,wed,thur,sat,fri);
print "@record \n";
#Print A Specific Element@rec=(jan,feb,mar,april);
print $rec[2],"\n";#Accessing Multiple Element
print @rec[0 .. 2],"\n";
my $value=@record;
#Sort An Arraymy @new=sort @rec;
print "AFter Sorting-->@new\n";
print "VALUE IS:-->$value \n";#Adding An Array
my @record1;
@record1=(1,2,3,@record,4);
print "@record1 \n";
#Accessing An Aray$a=$record1[3];
$b=(@record1)[4];print "A IS::-->$a && B Is :->$b\n";
@record=qw(sun day,mon,tue,wed,thur,sat,fri);
print "@record \n";
#Print A Specific Element@rec=(jan,feb,mar,april);
print $rec[2],"\n";#Accessing Multiple Element
print @rec[0 .. 2],"\n";
my $value=@record;
#Sort An Arraymy @new=sort @rec;
print "AFter Sorting-->@new\n";
print "VALUE IS:-->$value \n";#Adding An Array
my @record1;
@record1=(1,2,3,@record,4);
print "@record1 \n";
#Accessing An Aray$a=$record1[3];
$b=(@record1)[4];print "A IS::-->$a && B Is :->$b\n";
///////////////FOR LOOP///////////////////////////
#!usr/bin/perl
@record=(2,4,5,567,7,89,3);
my $a,$b;
$b=@record;
print "B IS $b \n";
for $a(@record){
print "This Element $a \n";
}
foreach(@record){
$_++;
}
print "Now Array IS:-->@record \n";
for($a=0;$a<=10;$a++){
print "VLUE IS \n",$a,"\n";
}
#USING Command Line Argument
foreach (@ARGV){
print "ARGV IS ::->$_ \n";}
@record=(2,4,5,567,7,89,3);
my $a,$b;
$b=@record;
print "B IS $b \n";
for $a(@record){
print "This Element $a \n";
}
foreach(@record){
$_++;
}
print "Now Array IS:-->@record \n";
for($a=0;$a<=10;$a++){
print "VLUE IS \n",$a,"\n";
}
#USING Command Line Argument
foreach (@ARGV){
print "ARGV IS ::->$_ \n";}
/////////////////WHILE LOOP//////////////////////
#!usr/bin/perl
my $a=0;
while($a<=6){
print "Sharjeel Bilali \n";$a++;
$a++;
}
my $a=0;
while($a<=6){
print "Sharjeel Bilali \n";$a++;
$a++;
}
#Infinite While Loop
#!usr/bin/perl
while(1){
print "Sharjeel Bilali \n";$a++;
$a++;
}
while(1){
print "Sharjeel Bilali \n";$a++;
$a++;
}
////////////////HASH////////////////
#!usr/bin/perl
my %where=(
Sharjeel =>"Seohara",
Gopesh =>"Haldwani",
Rupak =>"Sambhal",
Uzair =>"RamNagar"
);
for(keys %where)
{
print "$_ Lives In$where{$_}\n";}
my %where=(
Sharjeel =>"Seohara",
Gopesh =>"Haldwani",
Rupak =>"Sambhal",
Uzair =>"RamNagar"
);
for(keys %where)
{
print "$_ Lives In$where{$_}\n";}
/////////LABEL///////////
#!usr/bin/perl
print "HELLO \n";
sos:
print "IN SOS LABLE \n";
goto sos;
print "HELLO \n";
sos:
print "IN SOS LABLE \n";
goto sos;
/////////////////FILE HANDLING//////////////
#!usr/bin/perl
#Creating A File & Write Dataopen FP,">/testing.txt" or die "CanNot Open File";
#Creating A File & Write Dataopen FP,">/testing.txt" or die "CanNot Open File";
#Creating A File & Write Data At AppEnd mode
open FP,">>/testing.txt" or die "CanNot Open File";
#Put Data In File(String)my $data="WRITING PERL SCRIPT_1";open FP,">>/testing.txt" or die "CanNot Open File";
my $now="WRITING PERL SCRIPT_2";
print FP "$data";
print FP "\n";
print FP "$now";
print FP "\n";
close (FP);#Read Data In File(Character)open FP,"</testing.txt" or die "CanNot Open File";
my @record=<FP>;
print "@record \n";close (FP);
/////////////Find System Date & Time//////////
#!usr/bin/perl
my @timeData=localtime(time);
print "Current System TIME & Date IS --->@timeData \n";
my @timeData=localtime(time);
print "Current System TIME & Date IS --->@timeData \n";
#Find Date As Per Your Recquirement
@SDate=@timeData[5].@timeData[4].@timeData[3];
print @SDate;
@SDate=@timeData[5].@timeData[4].@timeData[3];
print @SDate;
Comments
Post a Comment