Reading integer values from a file

Discussion in 'Perl Misc' started by praveen.kantharajapura@gmail.com, Aug 11, 2006.

  1. Guest

    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
     
    , Aug 11, 2006
    #1
    1. Advertising

  2. -berlin.de Guest

    <> wrote in comp.lang.perl.misc:
    > 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
     
    -berlin.de, Aug 11, 2006
    #2
    1. Advertising

  3. Guest

    wrote:

    > [a multiposted question]


    This question has been multiposted to Perl.Beginners (the usenet mirror
    of the mailing list).

    Please ignore and burn this thread.

    --
    David Filmer (http://DavidFilmer.com)
     
    , Aug 11, 2006
    #3
  4. wrote:
    >
    > 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
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Aug 11, 2006
    #4
  5. Guest

    Michele Dondi wrote:
    > On 11 Aug 2006 01:06:27 -0700, wrote:
    > >This question has been multiposted to Perl.Beginners
    > >Please ignore and burn this thread.

    >
    > 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.

    --
    David Filmer (http://DavidFilmer.com)
     
    , Aug 11, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,966
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. Replies:
    3
    Views:
    552
    Roedy Green
    Oct 8, 2005
  3. Replies:
    1
    Views:
    11,375
    Dan Andrews
    Sep 29, 2006
  4. srikanth
    Replies:
    1
    Views:
    282
    Mike Wahler
    Jun 28, 2005
  5. GIMME
    Replies:
    1
    Views:
    179
    Dr John Stockton
    Apr 9, 2004
Loading...

Share This Page