CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [ohgiap] extracting a .lib file-2: Edit Log


May 17, 2005, 3:17 AM

Views: 3693
Re: [ohgiap] extracting a .lib file-2

not to confuse the issue after dave's post, but if you can't get that to work, this seems to work OK for creating a data set that could then be fed into the rest of your routines.

use strict;
use warnings;
use Data::Dump qw(dump);
open Infile, "AGLMII_IOST_NOM.lib" or die $!;
my @data=<Infile>;

my @AofH = ();
my ($i,$n,$f) = (0,0,0);
for (@data) {
$AofH[$i]{'index_1'} = [strip($_)] if (/index_1/);
$AofH[$i]{'index_2'} = [strip($_)] if (/index_2/);
($n,$f)=(1,1) if (/values/);
push @{$AofH[$i]{'values'}},[strip($_)] if ($f == 1);
($f=0) if (/;/);
($i++,$n=0) if ($n == 1 && $f == 0);

sub strip {
local $_ = shift;
print dump(@AofH);

the above makes an array of hashes out of the lib file. You would then loop through the array (@AofH) to get the rest of your output. It might be better to store the data as references instead of annonymous arrays if there is a lot of data.

Note that:

use Data::Dump qw(dump);


print dump(@AofH);

are just to test to see if the script is producing the correct data, they are not needed to run the script to do what you want. Data::Dump is a very good tool to use when creating complex data records.

(This post was edited by KevinR on May 17, 2005, 2:05 PM)

Edit Log:
Post edited by KevinR (Veteran) on May 17, 2005, 11:52 AM
Post edited by KevinR (Veteran) on May 17, 2005, 1:59 PM
Post edited by KevinR (Veteran) on May 17, 2005, 2:05 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives