Home > Archive > PerlTk > August 2006 > Reading integer values from a file in to an array
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Reading integer values from a file in to an array
|
|
| praveen.kantharajapura@gmail.com 2006-08-11, 3:59 am |
| Hi all,
I have a text file the format is shown below:
*** Lib cond : worst *** Ref phase : RISE *** SETUP ***
start point start edge end edge slack
------------- --------- ---------- -------
xi_mb0_dq[20] RISE RISE -134
*** Lib cond : best*** Ref phase : RISE *** SETUP***
start point start edge end edge slack
------------- --------- ---------- -------
xi_mb0_dq[20] RISE RISE 150
*** Lib cond : worst *** Ref phase : RISE *** SETUP ***
start point start edge end edge slack
------------- --------- ---------- -------
xi_mb0_dq[20] RISE RISE -150
*** Lib cond : best*** Ref phase : RISE *** SETUP ***
start point start edge end edge slack
------------- --------- ---------- -------
xi_mb0_dq[20] RISE RISE 200
*** Lib cond : worst *** Ref phase : RISE *** SETUP ***
start point start edge end edge slack
------------- --------- ---------- -------
xi_mb0_dq[20] RISE RISE -170
*** Lib cond : best*** Ref phase : RISE *** SETUP ***
start point start edge end edge slack
------------- --------- ---------- -------
xi_mb0_dq[20] RISE RISE 220
Now i should read the slack values in to two arrays on the following
conditions.
@worst_setup=(-134,-150,-170) if it is worst SETUP
@best_setup=(150,200,220) if it is best SETUP
Thanks in advance,
Praveen
| |
| Ala Qumsieh 2006-08-11, 6:59 pm |
| praveen.kantharajapura@gmail.com wrote:
> Hi all,
>
> I have a text file the format is shown below:
>
> *** Lib cond : worst *** Ref phase : RISE *** SETUP ***
> start point start edge end edge slack
> ------------- --------- ---------- -------
> xi_mb0_dq[20] RISE RISE -134
>
> *** Lib cond : best*** Ref phase : RISE *** SETUP***
> start point start edge end edge slack
> ------------- --------- ---------- -------
> xi_mb0_dq[20] RISE RISE 150
>
> *** Lib cond : worst *** Ref phase : RISE *** SETUP ***
> start point start edge end edge slack
> ------------- --------- ---------- -------
> xi_mb0_dq[20] RISE RISE -150
>
> *** Lib cond : best*** Ref phase : RISE *** SETUP ***
> start point start edge end edge slack
> ------------- --------- ---------- -------
> xi_mb0_dq[20] RISE RISE 200
>
> *** Lib cond : worst *** Ref phase : RISE *** SETUP ***
> start point start edge end edge slack
> ------------- --------- ---------- -------
> xi_mb0_dq[20] RISE RISE -170
>
> *** Lib cond : best*** Ref phase : RISE *** SETUP ***
> start point start edge end edge slack
> ------------- --------- ---------- -------
> xi_mb0_dq[20] RISE RISE 220
>
> Now i should read the slack values in to two arrays on the following
> conditions.
>
> @worst_setup=(-134,-150,-170) if it is worst SETUP
>
> @best_setup=(150,200,220) if it is best SETUP
Best to use a hash of arrays. Something like (untested):
my %slack;
my $case;
while (<> ) {
if (/Lib cond : (\w+)/) { $case = $1; next }
if (/(?:RISE|FALL).*\s(-?\d+)/) { push @{$slack{$case}} => $1 }
}
Checkout 'perldoc perldsc' for more info on Perl's multi-dimentional
data structures.
--Ala
|
|
|
|
|