Urgent help: getoptions::long to execute a command.

P

perl_newbie

I have created a data structure that checks the hierarchy list to a
list found in cadence. I'd like to use the getopt::long package to do
the following but do not know if this could be done.

1) when the flag 'unused' is chosen then it should get the $cadecells
and have them be executed by a command to remove them
"dssc remove $cadcell"

2)I am unable to reference the $hier->{$cell} in my last subroutine.
the $hierec->{$cell} contains the $lib but when I use the
data::Dumper;the $hierec->{$cell} ;which should have all $lib shows up
empty, why?.

use strict
use Getopt::Long;
use Data::Dumper;
my $show_file={};
my $hierec={};
my $cell={};
my $lib={};
my $cadcell={};
my $cadlib={};
my @cell=();

if (! & GetOptions('help', 'unused'))
{ print"Invalid Flag. please try -help.\n";}

if (@ARGV == 2 )
{
my $list1=$ARGV[0];
my $list2=$ARGV[1];

open(L1,"<$list1") || die "cannot open first file";
open(L2,"<$list2") || die "cannot open second file";
}
if (! my $opt_nosyntax)
{
print ("\nARGS were: ",join(" ",@ARGV),"\n");
print ("\nSYNTAX is:\n",
"hierarchy_list cadence_list <Flag_options>\n");
print("\tFlag_options include:\n");
print("\t\t-help\n");
print("\t\t-unused\n");
}
while(<L1>)
{
$show_file=$_;

if ($show_file=~/^\s?(\S+)\s+(\S+)/)
{
my ( $cell, $lib)= ($2, $1);
$hierec->{$cell}->{$lib}=1;
}
}
&comp_2_cell_list;
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{

my ($cadlib,$cadcell)=($1,$2);
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
}
unless ( exists $hierec->{$cell}->{$cadlib})
cannot obtain the keys from my hash to be reference here for comparing
if the same cell is found in the same lib. help???
{
print "mismatch in:{$hierec} ($hierec->{$cell},$cadlib)\n";
}

}
}
}


-----------------input files----------------------------
lib0 cell1
lib1 cell2
lib2 cell3
lib3 cell4
lib4 cell5

cadence:
lib0 cell1
lib0 cell1A --to be marked for deletion
lib1 cell2
lib3 cell4
lib3 cell4a --to be marked for deletion;
lib4 cell4 --to be marked for deletion; found in wrong lib
lib4 cell5
 
M

Mark Clements

perl_newbie said:
I have created a data structure that checks the hierarchy list to a
list found in cadence. I'd like to use the getopt::long package to do
the following but do not know if this could be done.

1) when the flag 'unused' is chosen then it should get the $cadecells
and have them be executed by a command to remove them
"dssc remove $cadcell"

2)I am unable to reference the $hier->{$cell} in my last subroutine.
the $hierec->{$cell} contains the $lib but when I use the
data::Dumper;the $hierec->{$cell} ;which should have all $lib shows up
empty, why?.

use strict
really? Then why does this look as though it has been typed in as an afterthought
ie no semi-colon. You need to copy and paste code, not retype it. You also need

use warnings;

Read the posting guidelines.
use Getopt::Long;
use Data::Dumper;
my $show_file={};
my $hierec={};
my $cell={};
my $lib={};
my $cadcell={};
my $cadlib={};
my @cell=();

if (! & GetOptions('help', 'unused'))

You need to read the documentation for Getopt::Long, not just guess how it is used.
{ print"Invalid Flag. please try -help.\n";}

if (@ARGV == 2 )
{
my $list1=$ARGV[0];
my $list2=$ARGV[1];

open(L1,"<$list1") || die "cannot open first file";
open(L2,"<$list2") || die "cannot open second file";
}
if (! my $opt_nosyntax)
This if statement is *never* going to be false. You declare $opt_nosyntanx, assign
no value to it, and then check if it contains a false value. It cannot be anything
else.

<snip>
I'm not going to proceed any further. You need to fix these fundamental issues
before any further diagnosis can be attempted. You also need to read the posting
guidelines: post the smallest complete script (that compiles out of the box - the
one already posted doesn't) that exhibits the behaviour that you are trying to
demonstrate, and let us know what the expected and actual output are.

Mark
 
T

Tad McClellan

perl_newbie said:
Subject: Urgent help: getoptions::long to execute a command.


Newsgroups are not an appropriate resource for things that
are truly urgent.

use strict ^^
use Getopt::Long;


Show real code if you want real help.
 
P

perl_newbie

thank you Tad and Mark for your comments. I still have some problems
implementing the the getoption::long to retire unused cells. I believe
the 'help' option is okay now but i need more help. I have posted the
smallest program possible that can I show to demostrate output. Will
you please help me figure out how to use the -unused option to push it
to another file to later run it to remove the unused cell from the cad
tree? can you also tell me how to reference my $hierc->{$cell} into my
subroutine? I have tried several ways to reference the hash which
contains my library to compare it to the cad tree libraries the cell is
found in but had no luck doing so.


desire output with no option chosen:
list to dump: cell1A
list to dump: cell4a
library mismatch in cell4 (gold:lib3,cad:lib4)

desired output with "-unused" option chosen to be run later in time:
dssc retire cell1A
dssc retire cell4a

current ouput with code below and no options chosen:
% perl dup.cell gold cad
list to dump: cell1A
list to dump: cell4a

---my code---
#!usr/bin/perl -w
use strict;
use Data::Dumper;

my $show_file={};
my $hierec={};
my $cell={};
my $lib={};
my $cadcell={};
my $cadlib={};
my @cell=();
my ($opt_help,$opt_unused);
#------------------------------------------------------------------------
use Getopt::Long; #for getting right arguments on the command line

if (! & GetOptions('help'=>\$opt_help, 'unused'=>\$opt_unused))
{ print"Invalid Flag. please try -help.\n";exit;}

if (@ARGV == 2 )
{
my $list1=$ARGV[0];
my $list2=$ARGV[1];

open(L1,"<$list1") || die "cannot open Gold STND file";
open(L2,"<$list2") || die "cannot open Cadence file";
}
if ($opt_help) {
print ("\nARGS were: ",join(" ",@ARGV),"\n");
print ("\nSYNTAX is:\n",
"hierarchy_list cadence_list <Flag_options>\n");
print("\tFlag_options include:\n");
print("\t\t-help\n");
print("\t\t-unused\n");
exit if defined $opt_help;
}
if ($opt_unused){
print("dssc -retire {$cadcell}\n");
}

while(<L1>)
{
$show_file=$_;

if ($show_file=~/^\s?(\S+)\s+(\S+)/)
{
my ( $cell, $lib)= ($2, $1);
$hierec->{$cell}->{$lib}=1;
}
}

#-------------------------------------------------------------------------------
&comp_2_cell_list;
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{

my ($cadlib,$cadcell)=($1,$2);
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
}
# unless ( exists $hierec->{$cell}->{$cadlib})
# {
# print "mismatch libs in:$hierec ($hierec->{$cell},$cadlib)\n";

# print Dumper($hierec->{$lib});
# }
}
}
}
#----------------------------input list--
lib0 cell1
lib1 cell2
lib2 cell3
lib3 cell4
lib4 cell5
gold (END)

lib0 cell1
lib0 cell1A --to be marked for deletion
lib1 cell2
lib3 cell4
lib3 cell4a --to be marked for deletion;
lib4 cell4 --to be marked for deletion; found in wrong lib
lib4 cell5
cad (END)
 
P

perl_newbie

thank you Tad and Mark for your comments. I still have some problems
implementing the the getoption::long to retire unused cells. I believe
the 'help' option is okay now but I need more help. I have posted the
smallest program possible that can to demostrate output. Will
you please help me figure out how to use the -unused option to push it
to another file to later run it to remove the unused cell from the cad
tree? can you also tell me how to reference my $hierc->{$cell} into my
subroutine? I have tried several ways to reference the hash which
contains my library to compare it to the cad tree libraries the cell is
found in but had no luck doing so.

thank you all for your past and future help in helping me complete the
program to get the correct output.:^)


desire output with no option chosen:
list to dump: cell1A
list to dump: cell4a
library mismatch in cell4 (gold:lib3,cad:lib4)


desired output with "-unused" option chosen to be run later in time:
dssc retire cell1A
dssc retire cell4a


current ouput with code below and no options chosen:
% perl dup.cell gold cad
list to dump: cell1A
list to dump: cell4a

--input files--
lib0 cell1
lib1 cell2
lib2 cell3
lib3 cell4
lib4 cell5
gold (END)


lib0 cell1
lib0 cell1A --to be marked for deletion
lib1 cell2
lib3 cell4
lib3 cell4a --to be marked for deletion;
lib4 cell4 --to be marked for deletion; found in wrong lib
lib4 cell5


--my code--
#!usr/bin/perl -w
use strict;
use Data::Dumper;
my $show_file={};
my $hierec={};
my $cell={};
my $lib={};
my $cadcell={};
my $cadlib={};
my @cell=();
my ($opt_help,$opt_unused);
#------------------------------------------------------------------------
use Getopt::Long; #for getting right arguments on the command line

if (! & GetOptions('help'=>\$opt_help, 'unused'=>\$opt_unused))
{ print"Invalid Flag. please try -help.\n";exit;}

if (@ARGV == 2 )
{
my $list1=$ARGV[0];
my $list2=$ARGV[1];

open(L1,"<$list1") || die "cannot open Gold STND file";
open(L2,"<$list2") || die "cannot open Cadence file";
}
if ($opt_help) {
print ("\nARGS were: ",join(" ",@ARGV),"\n");
print ("\nSYNTAX is:\n",
"hierarchy_list cadence_list <Flag_options>\n");
print("\tFlag_options include:\n");
print("\t\t-help\n");
print("\t\t-unused\n");
exit if defined $opt_help;
}
if ($opt_unused){
print("dssc -retire {$cadcell}\n");
}

while(<L1>)
{
$show_file=$_;

if ($show_file=~/^\s?(\S+)\s+(\S+)/)
{
my ( $cell, $lib)= ($2, $1);
$hierec->{$cell}->{$lib}=1;
}
}

#-------------------------------------------------------------------------------
&comp_2_cell_list;
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{

my ($cadlib,$cadcell)=($1,$2);
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
}
# unless ( exists $hierec->{$cell}->{$cadlib})
# {
# print "mismatch libs in:$hierec ($hierec->{$cell},$cadlib)\n";

# print Dumper($hierec->{$lib});
# }
}
}
}
#-------------------------------------------------------------------------------
 
P

perl_newbie

Thank you Tad and Mark for comments and future help.
I still have some problems implementing the getoption::long to retire
unused cells. I believe the 'help' option is okay now but I need more
help. I have posted the
smallest program possible that can to demonstrate output.
Will you please help me figure out how to use the -unused option to
push it to another file to later run it to remove the unused cell from
the cad tree?
Can you also help to reference my $hierc->{$cell} into my
subroutine? I have tried several ways to reference the hash which
contains my library to compare it to the cad tree libraries the cell is
found in but had no luck doing so
Desire output with no option chosen:
list to dump: cell1A
list to dump: cell4a
library mismatch in cell4 (gold:lib3,cad:lib4)

Desired output with "-unused" option chosen to be run later in time:
dssc retire cell1A
dssc retire cell4a

Current ouput with code below and no options chosen:
% perl dup.cell gold cad
list to dump: cell1A
list to dump: cell4a
--input files--
lib0 cell1
lib1 cell2
lib2 cell3
lib3 cell4
lib4 cell5
gold (END)

lib0 cell1
lib0 cell1A --to be marked for deletion
lib1 cell2
lib3 cell4
lib3 cell4a --to be marked for deletion;
lib4 cell4 --to be marked for deletion; found in wrong lib
lib4 cell5

--my code---
#!usr/bin/perl -w
use strict;
use Data::Dumper;

my $show_file={};
my $hierec={};
my $cell={};
my $lib={};
my $cadcell={};
my $cadlib={};
my @cell=();
my ($opt_help,$opt_unused);
#------------------------------------------------------------------------
use Getopt::Long; #for getting right arguments on the command line

if (! & GetOptions('help'=>\$opt_help, 'unused'=>\$opt_unused))
{ print"Invalid Flag. please try -help.\n";exit;}

if (@ARGV == 2 )
{
my $list1=$ARGV[0];
my $list2=$ARGV[1];

open(L1,"<$list1") || die "cannot open Gold STND file";
open(L2,"<$list2") || die "cannot open Cadence file";
}
if ($opt_help) {
print("\tFlag_options include:\n");
print("\t\t-help\n");
print("\t\t-unused\n");
exit if defined $opt_help;
}
if ($opt_unused){
print("dssc -retire {$cadcell}\n");
}

while(<L1>)
{
$show_file=$_;
if ($show_file=~/^\s?(\S+)\s+(\S+)/)
{
my ( $cell, $lib)= ($2, $1);
$hierec->{$cell}->{$lib}=1;
}
}
&comp_2_cell_list;
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{

my ($cadlib,$cadcell)=($1,$2);
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
}
# unless ( exists $hierec->{$cell}->{$cadlib}) #problem
referencing $libs
# {
# print "mismatch libs in:$hierec ($hierec->{$cell},$cadlib)\n";

# print Dumper($hierec->{$lib});
# }
}
}
}
 
P

perl_newbie

Thank you Mark and Tad for your comments and help. Quick
question...Where can one go to look for a quick answer to a quick
question when the documents do not make are too difficult for a new
perl user? Again, thank you all for your comments and help :^)
 
A

A. Sinan Unur

Quick question...Where can one go to look for a quick answer to a
quick question when the documents do not make are too difficult
for a new perl user?

Huh?

I search the FAQ list, look up a function using perldoc, use Google, look
the concept up in "Programming Perl" or even "Learning Perl", sometimes.

I do not see what makes you think you are above putting effort into
finding a solution to your problem.

You have been working on this program for months now, and you don't seem
to have listened to much of the advice.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top