Sei sulla pagina 1di 5

8. Develop two Perl functions.

The first function must take a list of elements as an argument and check if there are
any duplicate elements in the list. And the second must delete duplicate elements from the list.

CODE:

print "How many elements you want to add: ";


chomp ($no=(<STDIN>));

for ($i=0;$i<$no;$i++)
{
print "Enter an element: ";
chomp ($text=(<STDIN>));
@content[$i]=$text;
}
@data=list(@content);
@new_data=del(@content);

print "List without any dulplicate items: @new_data\n";

sub list()
{
@data=@_;
$size=@data;
$i=0;
for($j=0;$j<$size;$j++)
{
for($k=$j+1;$k<$size;$k++)
{
if(@data[$j]==@data[$k])
{
@duplicate[$i]= @data[$j];
$i++;
}
}
}
print "Dupliacte items are: @duplicate\n";
}

sub del ()
{
@data=@_;
$size=@data;
for($j=0;$j<$size;$j++)
{
for($k=$j+1;$k<$size;$k++)
{
if(@data[$j]==@data[$k])
{
delete (@data[$j]);
}
}
}
return @data;

OUTPUT:
9. Write a Perl script that prints the count of all the cells used in the given module of a netlist in
a report file. The script must get two arguments. First is the name of the netlist and the second
is the name of module for which to determine the cell counts. Script must generate a log file
named "netlist_report.log"

CODE:

($module, $netlist_name) = @ARGV;

open IN, "<$netlist_name" or die "Error opening the file $!";


while (<IN>)
{
push (@text,$_);
}
close (IN);

$lines=0;
$size=@text;
#print "$size\n";
for($i=0;$i<=$size;$i++)
{
if($text[$i]=~/^module\s*$module\s*\(/)
{
$end=0;
$cell_count=0;
for($j=$i+1;$j<=$size;$j++)
{

if($text[$j]=~/^\s*(\w+)\s\w+\s\(\s*\./)
{
$cell_count++;
}

if($text[$j]=~/^endmodule/)
{
last;
}

}
}
}
print "Total Cell count in the Module \"$module\": $cell_count\n";

open OUT, ">d:/netlist_report.log" or die "Error creating file $!";


print OUT "Total Cell count in the Module \"$module\": $cell_count";
close (OUT);

OUTPUT:
10. Write a Perl programme that creates the skeleton of a test suite such that the directory
structure should be as in fig. 1. Also assume you need to copy two different #.v files residing in
the current working directory to test each test directory. Prompt the user to enter the number
of test directories to be created through the standard input. Pass the names of the #.v files that
need to be copied to each test directory as the command line argument.

CODE:

@v_files=@ARGV;

use Cwd;
$cur_dir = getcwd;

$temp="/";
$in_file_1=$cur_dir.$temp.$v_files[0];
$in_file_2=$cur_dir.$temp.$v_files[1];

open IN,"<$in_file_1" or die "Error opening the file. $!";


while (<IN>)
{
push (@data_1,$_);
}
close (IN);

open IN1,"<$in_file_2" or die "Error opening the file. $!";


while (<IN1>)
{
push (@data_2,$_);
}
close (IN1);

$temp2="/Testcases/";
$dir=$cur_dir.$temp2;
mkdir $dir;
chdir($dir) or die "Can't chdir to c:\\mnt : $!";

print "How many test directories you want to create: ";


chomp ($dir_no=<STDIN>);
for ($i=1;$i<=$dir_no;$i++)
{
$temp1="Test";
$dir_name=$temp1.$i;
mkdir $dir_name;
$path=$dir.$dir_name;
$name1="/$v_files[0]";
$name2="/$v_files[1]";
$path1=$path.$name1;
$path2=$path.$name2;

open OUT1,">$path1" or die "Error creating the file. $!";


print OUT1 @data_1;
close (OUT1);
open OUT2,">$path2" or die "Error creating the file. $!";
print OUT2 @data_2;
close (OUT2);
}
print "Check $dir\n";

OUTPUT:

Potrebbero piacerti anche