Print out first value from each file

How do i print out the first value for each parameter
from each file to another file in the desired output??
Note: A parameter is
NE2 40/40 Vth0!1K ohm resister!R!ohm!
and
Vth Vb/2.5!MOSFET!R!A!
Each file is runt1 and runt2

I provided Input file,runt1 and runt2 files,
Desired Output file and my codes.
Please see my explanation below.Thanks!!

Input file:

runt1!3!14
runt2!3!15

It will read from Input file,runt1 file the value
of 14 where 14 is found inside runt1 where
SYS_WAFERID!14 to SYS_WAFERID!14,then subsequently
will read from runt2 the value of 15 where
SYS_WAFERID!15 to SYS_WAFERID!15:

runt1:
SYS_WAFERID!14
=16x13
NE2 40/40 Vth0!1K ohm resister!R!ohm!+9.939227E+02!+9.960116E+02!+9.953210E+02
Vth Vb/2.5!MOSFET!R!A!+3.985872E-08!+3.974027E-08!+3.998509E-08
=7x2
SYS_WAFERID!14

runt2:
SYS_WAFERID!15
=16x13
NE2 40/40 Vth0!1K ohm resister!R!ohm!-9.982348E+02!+1.002406E+03!+1.002990E+03
Vth Vb/2.5!MOSFET!R!A!+3.948130E-08!+3.971276E-08!+3.982617E-08
=7x2
SYS_WAFERID!15

Then it will extract the first value of each parameter from each file
e.g NE2 40/40 Vth0!1K ohm resister!R!ohm! will extract until the 1st
exclaimation mark then,
the first value +9.939227E+02! from runt1 and first value
-9.982348E+02! from runt2,extract until the E
to print out to another file in this way(This is also the
same for the second parameter):

Desired Output:

s1!NE2 40/40 Vth0!+9.939227E!-9.982348E!
s1!Vth Vb/2.5!+3.985872E!+3.948130E!


My codes:

open(FILE1,"infile") || die "Can't open infile because $!";
open(FILE2,">outfile") || die "Can't open outfile because $!";

while(<FILE1>)
{
     if(/!/)
     {
       ($a,$b,$c) = split(/!/,$_);
       open(FILE3,"$a") || die "Can't open runt1 because $!";
       ($value) = $c;
       push (@value,$value) unless $value{$value}++;
 
       $file3 = join('',<FILE3>);
       while($file3 =~ /SYS_WAFERID!(\d+)([^\0]*)SYS_WAFERID!\1/g)
       {
          $id = $1;
            if($value[0] == $id)
          {
            ($para) = /([^!])/;
              push (@para,$para) unless $para{$para}++;
          }
       }
     }
}
print FILE2 "s1!$para[0]";
yu12koeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yu12koeAuthor Commented:
Adjusted points to 80
0
ozoCommented:
while( <> ){
  chomp;
  next unless ($a,$b,$c) = split/!/;
  open FILE3,"<$a" or die "Can't open $a because $!";
  while( <FILE3> ){
    next unless /SYS_WAFERID!$c\b/.../SYS_WAFERID!$c\b/;
    next unless ($para,$value) = /([^!]+)!.*?!([-+\d.]+E)[-+\d]+!/;
    push @para,$para unless $para{$para};
    push @{$para{$para}},$value;
  }
}
for( @para ){
  print join"!","s1",$_,@{$para{$_}};
  print "\n";
}
0
yu12koeAuthor Commented:
Will the above codes work in perl 4??
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

ozoCommented:
no
0
yu12koeAuthor Commented:
How am I going to change the codes above to be workable in perl 4 ??
0
yu12koeAuthor Commented:
For the codes by ozo, if the input file has 5 files like this:
Input file:

runt1!9!14
runt2!9!14
runt3!9!15
runt4!9!25
runt5!9!3

Your codes only print out the first value of each parameter of first 4 files but not the first
value of each parameter of the last file.

How do I correct this error to be workable in perl4??
Thanks

0
ozoCommented:
Is there a
SYS_WAFERID!3
in runt5?
What do the parameters look like there?
0
yu12koeAuthor Commented:
The parameters are the in the same way as the other parameters in runt1,run2,runt3,run4
0
yu12koeAuthor Commented:
in runt5 file,SYS_WAFERID!03 and not
SYS_WAFERID!3

SYS_WAFERID!03
=16x13
NE2 40/40 Vth0!1K ohm resister!R!ohm!-1.002028E+03!-9.961530E+02!-9.942889E+02
Vth Vb/2.5!MOSFET!R!A!+3.941366E-08!+3.954584E-08!+3.951395E-08
=7x2
SYS_WAFERID!03
0
ozoCommented:
is the number after SYS_WAFERID! always two digits?
0
yu12koeAuthor Commented:
yes.The nos after SYS_WAFERID! is always 2 digits.

If I want to print out the 2nd values for each parameter from each file,then subsequently,3rd values from each file and so on...,
How do i change the codes by you (your codes only print out the 1st value of each parameter from each file)?
Thus,the output will be
(s1 will represent the 1st value for each parameter from each file,
s2 represent the 2nd value for each parameter from each file,
s3 represent the 3rd value for each parameter from each file) :

s1!NE2 40/40 Vth0!+9.939227E!+9.982348E!+9.964815E!
s2!NE2 40/40 Vth0!+9.960116E!+1.002406E!+9.984025E!
s3!NE2 40/40 Vth0!+9.953210E!+1.002990E!+1.001633E!

s1!Vth Vb/2.5!+3.985872E!+3.948130E!+3.959628E!
s2!Vth Vb/2.5!+3.974027E!+3.971276E!+3.941408E!
s3!Vth Vb/2.5!+3.998509E!+3.982617E!+3.977742E!
0
ozoCommented:
while( <> ){
  next unless ($a,$b,$c) = split/!/;
  $c = sprintf"%02d",$c;
  open FILE3,"<$a" or die "Can't open $a because $!";
  while( <FILE3> ){
    next unless /SYS_WAFERID!$c\b/.../SYS_WAFERID!$c\b/;
    next unless ($para,@values) = /([^!]+)!.*?!([-+\d.]+E)[-+\d]+!([-+\d.]+E)[-+\d]+!([-+\d.]+E)/;
    push @para,$para unless $para{$para};
    for( 's1'..'s3' ){
       push @{$para{$para}{$_}},shift @values;
    }
  }
  close FILE3;
}
for $p ( @para ){
  for $s ('s1'..'s3' ){
    print join"!",$s,$p,@{$para{$p}{$s}};
    print "\n";
  }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.