[31155] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2400 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 8 00:09:49 2009

Date: Thu, 7 May 2009 21:09:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 7 May 2009     Volume: 11 Number: 2400

Today's topics:
        Best way to extract numeric values from a report? <r.mariotti@fdcx.net>
    Re: Best way to extract numeric values from a report? <glex_no-spam@qwest-spam-no.invalid>
    Re: Best way to extract numeric values from a report? <ben@morrow.me.uk>
    Re: Best way to extract numeric values from a report? <jurgenex@hotmail.com>
    Re: Best way to extract numeric values from a report? <cartercc@gmail.com>
        Console output on Win32? <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 07 May 2009 17:48:33 -0400
From: bobmct <r.mariotti@fdcx.net>
Subject: Best way to extract numeric values from a report?
Message-Id: <8fl605ha7o1c5r95d4retg0dm2jfq07c9e@4ax.com>

I'm reasonably familiar with perl as I have been programming with it
for a number of years.

I am trying to extract information from a text based report file and
create a file of data records for use as input to some other perl
programs.

The report file in question has about 13 columns of financial amounts
such as -1,234,567.89 and I wish to extract each column and output to
a record in a signed, efficient format for later use by these other
perl programs.

I am currently using unpack and pack but I am not having luck with the
floating point values.

What are some suggestions as to how to extract and export these
values?  Any good suggestions/recommendations/examples greatly
appreciated.

signed: just another perl monger



------------------------------

Date: Thu, 07 May 2009 17:23:37 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Best way to extract numeric values from a report?
Message-Id: <4a03548d$0$1333$815e3792@news.qwest.net>

bobmct wrote:
> I'm reasonably familiar with perl as I have been programming with it
> for a number of years.
> 
> I am trying to extract information from a text based report file and
> create a file of data records for use as input to some other perl
> programs.
> 
> The report file in question has about 13 columns of financial amounts
> such as -1,234,567.89 and I wish to extract each column and output to
> a record in a signed, efficient format for later use by these other
> perl programs.

What separates the columns?

Use whatever that is, with split, and you should be on your way.

> 
> I am currently using unpack and pack but I am not having luck with the
> floating point values.

Show us what you've tried.

> 
> What are some suggestions as to how to extract and export these
> values?  Any good suggestions/recommendations/examples greatly
> appreciated.


Treating it as a string, using a regular expression, would
be much easier than pack, IMHO.


------------------------------

Date: Thu, 7 May 2009 23:23:05 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Best way to extract numeric values from a report?
Message-Id: <9j3cd6-ulh1.ln1@osiris.mauzo.dyndns.org>


Quoth bobmct <r.mariotti@fdcx.net>:
> 
> I am trying to extract information from a text based report file and
> create a file of data records for use as input to some other perl
> programs.
> 
> The report file in question has about 13 columns of financial amounts
> such as -1,234,567.89 and I wish to extract each column and output to
> a record in a signed, efficient format for later use by these other
> perl programs.
> 
> I am currently using unpack and pack but I am not having luck with the
> floating point values.

You need to show some code. 

What are using pack/unpack for: extracting the values from the file, or
storing them for later retrieval? If it's the former, you'd be better
off using something like Regexp::Common::number to extract them. If it's
the latter, you should be aware that packed float formats are not
portable between machines.

Ben



------------------------------

Date: Thu, 07 May 2009 17:08:41 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Best way to extract numeric values from a report?
Message-Id: <3ot605h0rcn7kindrj3rcouernjgup86mj@4ax.com>

bobmct <r.mariotti@fdcx.net> wrote:
>I am trying to extract information from a text based report file and
>create a file of data records for use as input to some other perl
>programs.
>
>The report file in question has about 13 columns of financial amounts
>such as -1,234,567.89 and I wish to extract each column and output to
>a record in a signed, efficient format for later use by these other
>perl programs.

How are the columns identified/separated? By fixed position within the
line (i.e. characters 12-18 are always column 4) or by a known
separator, e.g. a comma, a semicolon, or a space character?

If the former then unpack is the tool of choice, if the latter then
split() will work nicely. 
And if it's a CSV-format then one of the CSV-modules will work best,
because they will deal with all the oddities like quoted values or
escaped characters automatically.

jue


------------------------------

Date: Thu, 7 May 2009 17:23:21 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Best way to extract numeric values from a report?
Message-Id: <7f2705b3-00d2-4a1a-b009-a9eca866ce4b@g19g2000vbi.googlegroups.com>

On May 7, 5:48=A0pm, bobmct <r.mario...@fdcx.net> wrote:
> I am trying to extract information from a text based report file and
> create a file of data records for use as input to some other perl
> programs.

First, I assume that you are dealing with some kind of delimited
format. The algorithm is easy -- here is some pseudo-pseudo code:

open INFILE, '<', 'text_based_report_file.txt';
while(<INFILE>)
{
 chomp;
 my ($c1, $c2, etc. all the way to $c13) =3D split /delimiter/, $_;
 #you can now access your values like $c1, $c2, ... $c13)
}
close INFILE;

> The report file in question has about 13 columns of financial amounts
> such as -1,234,567.89 and I wish to extract each column and output to
> a record in a signed, efficient format for later use by these other
> perl programs.

It's not clear to me exactly how you want your output, but assuming
that it's a signed float and all you need to do is delete the commas,
this will do it:
$c1 =3D~ s/,//g;

> What are some suggestions as to how to extract and export these
> values? =A0Any good suggestions/recommendations/examples greatly
> appreciated.

How do you want to export the values? Seems to me that if you input
them in a delimited file your work is done, that you don't need to
export the values. If you need to 'export' the values into some data
structure in memory, use an array of array references. You can then
access each individual value like this:
$arr_ref->[0][0] #gets the first column in the first row
$arr_ref->[1][12] # gets the last column in the second row

CC



------------------------------

Date: Fri, 08 May 2009 01:42:35 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Console output on Win32?
Message-Id: <slrnh0733f.s3j.nospam-abuse@chorin.math.berkeley.edu>

Is it possible to use `binmode($fh, SOMETHING)' in Win32 to get "the
expected console-like behaviour" on the handle?  Something other API?

I mean something like what I find on:
 http://blogs.msdn.com/junfeng/archive/2004/02/25/79621.aspx

(the semantic is to get full unicode text on the console, and text
converted to the current codepage if the output is redirected to a
pipe/file; cp65001 [=UTF-8] not excluded).

Thanks,
Ilya

P.S.  Since the code is portable (mp3info2) and very short, I would
      prefer a solution as terse as possible...


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2400
***************************************


home help back first fref pref prev next nref lref last post