0% found this document useful (0 votes)
66 views

Sys Verilog

The document contains examples of using various Perl functions including numeric, string, and array functions. It shows how to convert between data types, manipulate strings and arrays, perform math operations, and more.

Uploaded by

Rishabh
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Sys Verilog

The document contains examples of using various Perl functions including numeric, string, and array functions. It shows how to convert between data types, manipulate strings and arrays, perform math operations, and more.

Uploaded by

Rishabh
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#!

/usr/bin/perl

=pod
print "enter a number through standard input\n";
my $a=<STDIN>;
chop($a);

print $a . "\n";
=cut

#hex function

my $a=0x2e;
my $r=hex($a);
print $r;

#oct function
=pod
my $c1=0x2e; #hexadecimal
my $a=oct($c1);
print $a ."\n";
my $c2=057; #Octal format
my $a2=oct($c2);
print $a2 . "\n";

my $c3=0b101110; #binary format


my $a3=oct($c3);
print $c3;

=cut

#convert the number in to stringi

=pod
my $p=10;
my $str=sprintf("%lx",$p);
my $str1=sprintf("%lo",$p);
my $str2=sprintf("%lb",$p);
my $str3=sprintf("%lf",$p);
my $str4=sprintf("%e",$p);
print $str . "\n";
print $str1 ."\n";
print $str2 . "\n";
print $str3 . "\n";
print $str4 . "\n";
=cut

#example of sqrt
=pod
my $a=sqrt(16);
print $a;
=cut

#int function..

=pod
my $price=9.95;
my $dollar=int($price);
print $dollar;

=cut

#abs function calling

=pod
my $a=-3.4;
my $b=abs($a);
print $b;
=cut

=pod

my @a=qw(raju vishnu pankaj);

#to remove
#my @a1=splice(@a,1,1);
#to add
splice(@a,2,0,'king','manohar');
print "@a" . "\n";
=cut

=pod

my @scores = ( 1000, 13, 27, 200, 76, 150 );


#my @scores=(2,4,1,6,8);
my @sorted=sort(@scores);
print "@sorted\n";
my @reverse =reverse(@sorted);

#print "@reverse";
=cut

=pod

my @a=qw(one two three four);


print "length of a array is $#a\n";
#or
my $a1=@a;
print "lenth of a array is $a1\n";
my $a2=scalar(@a);
print "length of a array is $a2\n";
=cut

=pod

my $i=15;
my $j=12;

my $c= $i cmp $j;


print $c;
=cut

=pod

my $decimal=12;
my $hex=sprintf("%08lx",$decimal);
my $oct=sprintf("%08lo",$decimal);
my $bin=sprintf("%08lb",$decimal);

print "hex value is $hex\n";


print "oct value is $oct\n";
print "bin value is $bin\n";

=cut

multiple line string ...here docoment

=pod
my $str=<<'endofstring';
brajesh
rajesh
rakesh
anitha
ana
endofstring

print $str;
=cut

#join function

=pod
my $str=join(" and ",qw(raju rajesh ana prankaj));
#print $str;

#or
my $str=join(" and ", 'raju','rajesh','ana','pankaj');
print $str;

=cut

#split function
#
=pod
my $data='raju\brajesh\ana\bhushan';
my ($fname,$sname,$tname,$foname)= split(/\\/,$data);
print "firstname is $fname\n";
print "secondname is $sname\n";
print "thirdname is $tname\n";
print "fourth name is $foname\n";

=cut

#find out substring

=pod
my $i="welcome to incise";

my $j=substr($i,8,4);
print $j."\n";
=cut

#to find out lenth of a string


=pod
my $str="welcome";
my $len=length($str);
print $len."\n";
=cut

#string concatenation
=pod
my $str="raju"." rajesh";
print $str;
=cut

#string repetition operator

=pod
my $str="raju " x 5;
print " $str";
=cut

###########################chop and chomp


=pod
my $i="welcome";

#chomp($i);
print " i is $i\n";
chop($i);
print " i is $i\n";
=cut

##########################variable interpolation
=pod
my $i=5;

print "i value is $i\n";


print 'i value is $i\n';
=cut

You might also like