CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [ohgiap] extracting a .lib file-2: Edit Log



KevinR
Veteran


May 25, 2005, 10:59 PM


Views: 2124
Re: [ohgiap] extracting a .lib file-2

OK, I see what you are trying to do with that short script. It's only printing the last line because you are not printing the lines after each loop, and instead only printing the line that the very last loop creates. You could that with just one "for" loop, like this


Code
my %name=( 
type=>['cell_fall', 'fall_transition', 'cell_fall', 'fall_transition'],
sense=>['positive', 'negative'],
pin=>['OE_N', 'DATA_OUT', 'SIGNAME']
);

my($pin,$sense,$type);

for my $i (0 .. 15){
if ($i <= 7) {
$pin=$name{pin}[0];
if ($i <= 3){
$sense=$name{sense}[1];
if ($i==0 || $i==4){
$type=$name{type}[0];
}
elsif ($i==1 || $i==5){
$type=$name{type}[1];
}
elsif ($i==2 || $i==6){
$type=$name{type}[2];
}
elsif ($i==3 || $i==7){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
elsif ($i > 3 && $i <= 7){
$sense=$name{sense}[0];
if ($i==0 || $i==4){
$type=$name{type}[0];
}
elsif ($i==1 || $i==5){
$type=$name{type}[1];
}
elsif ($i==2 || $i==6){
$type=$name{type}[2];
}
elsif ($i==3 || $i==7){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
}
elsif ($i > 7 && $i <= 11){
$pin=$name{pin}[1];
$sense=$name{sense}[0];
if ($i==8){
$type=$name{type}[0];
}
elsif ($i==9){
$type=$name{type}[1];
}
elsif ($i==10){
$type=$name{type}[2];
}
elsif ($i==11){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
else {
$pin=$name{pin}[2];
$sense=$name{sense}[0];
if ($i==12){
$type=$name{type}[0];
}
elsif ($i==13){
$type=$name{type}[1];
}
elsif ($i==14){
$type=$name{type}[2];
}
elsif ($i==15){
$type=$name{type}[3];
}
print "$i is $pin and $sense and $type\n";
}
}


which outputs:


Code
0 is OE_N and negative and cell_fall 
1 is OE_N and negative and fall_transition
2 is OE_N and negative and cell_fall
3 is OE_N and negative and fall_transition
4 is OE_N and positive and cell_fall
5 is OE_N and positive and fall_transition
6 is OE_N and positive and cell_fall
7 is OE_N and positive and fall_transition
8 is DATA_OUT and positive and cell_fall
9 is DATA_OUT and positive and fall_transition
10 is DATA_OUT and positive and cell_fall
11 is DATA_OUT and positive and fall_transition
12 is SIGNAME and positive and cell_fall
13 is SIGNAME and positive and fall_transition
14 is SIGNAME and positive and cell_fall
15 is SIGNAME and positive and fall_transition


Note that the elements in the arrays have to be quoted:


type=>['cell_fall', 'fall_transition', 'cell_fall', 'fall_transition'],
sense=>['positive', 'negative'],
pin=>[qw(OE_N DATA_OUT SIGNAME)]

like any array you must use quotes around alpha (words) elements.
-------------------------------------------------


(This post was edited by KevinR on May 25, 2005, 11:00 PM)


Edit Log:
Post edited by KevinR (Veteran) on May 25, 2005, 11:00 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives