Reading integer values from a file

  • Thread starter praveen.kantharajapura
  • Start date
P

praveen.kantharajapura

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
 
A

anno4000

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

[data trimmed]
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

We are not in the business of delivering programs to specification
(not much of a specification, at that).

What have you tried?

Anno
 
J

John W. Krahn

I have a text file the format is shown below:

[ snip ]

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

You probably want to use a Hash of Arrays:

$ echo "*** 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
" | perl -ln00e'
/Lib cond : +(\w+).*?(-?\d+)$/s and push @{$hash{$1}}, $2
}{
print "$_: @{$hash{$_}}" for keys %hash
'
worst: -134 -150 -170
best: 150 200 220




John
 
U

usenet

Michele said:
Oh my! I agree with you on the inconvenience of multiposting, but
isn't your proposed solution a little bit too drastic?

Multiposting is not inconvenient - it's rude. I don't believe rudeness
should be tolerated in any forum, and I believe any multiposted thread
should be burned (once exposed) because offering assistance only
condones and encourages rudeness. It would have been "drastic" if I
had flamed or encouraged that the OP be killfiled, but I did neither.
How 'bout a warning to the op, to the effect of *at least* crosspost, if real need

Crossposting is rarely (if ever) "needed" in similar groups (such as
between Perl groups), and doing so is almost always (or always)
considered impolite. It might be appropriate between dissimilar groups
(such as a problem with a networking-related Perl program - maybe
crosspost to a Perl and a networking newsgroup because you're not sure
where the problem lies). But I don't want to encourage or even mention
crossposting to neophytes because they will do it (between Perl
groups), and then the groups will begin to resemble mirrors of each
other.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top