Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Using the read function...

by thatguy (Parson)
on Oct 08, 2001 at 21:04 UTC ( #117509=note: print w/replies, xml ) Need Help??

in reply to Using the read function...

here's my suggestion.. it uses the line number to determine what data it is looking at.

#!/usr/bin/perl -w use strict; use vars qw/ $Destination $Program_Type $Program_Name $Incomming_Foo $Decision $Date_Applied $Appl_Number $junk /; my $i; open(DATA," basicdez.dat") || die "Cannot open datafile!: $!\n"; while(<DATA>){ chomp; $i++; # if you do not need the quotes, uncomment the next line # $_=~ s/"//g; # use line number to decide what data goes where # if the current data is EOS then reset the linenumber to 0 if ($_ =~ /EOS/){ $i=0; } # line one is Destination if ($i eq 1){ ($junk,$Destination)=split(/ /, $_); print "Destination = $Destination\n"; # line two is unused # line three is Program_Type,Program_Name,Incomming_Foo } elsif ($i eq 3){ ($Program_Type,$Program_Name,$Incomming_Foo)=split(/ /, $_); print "Program_Type = $Program_Type\n"; print "Program_Name = $Program_Name\n"; print "Incomming_Foo = $Incomming_Foo\n"; # line four is unused # line 5 is Decision,Date_Applied,Appl_Number } elsif ($i eq 5){ ($Decision,$Date_Applied,$Appl_Number)=split(/ /, $_); print "Decision = $Decision\n"; print "Date_Applied = $Date_Applied\n"; print "Appl_Number = $Appl_Number\n"; } # lines six and seven should be EOS and caught by # earlier statement } close(DATA); exit;

This can be easily broken if the number of lines changes, but if your data never changes or keeps the same model then it should be fine.

Update: instead of line numbers, just parsing it all as one line:

#!/usr/bin/perl use strict; my $i; my $data; open(DATA," basicdez.dat") || die "Cannot open datfile: $!\n"; while(<DATA>){ chomp; unless ($_=~ /"EOS"/){ $data .= "$_"; } elsif ($i ne 1) { $data .="\n"; } if ($_=~ /"EOS"/){ $i=1; } } close(DATA); my @data=split(/\n/, $data); for(@data){ my($Destination,$Program_Type,$Program_Name,$Incomming_Foo, $Decision,$Date_Applied,$Appl_Number)=split; print "$Destination,$Program_Type,$Program_Name,$Incomming_Foo,"; print "$Decision,$Date_Applied,$Appl_Number\n"; } exit;


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://117509]
[thezip]: G'day all. Apparently Strawberry Perl has issues with deploying Spreadsheet::XLSX for Perl 5.24.1. I need this module to maintain compatability with an existing script. I'm new to Strawberry -- is there a safe way to manually deploy this?
[MidLifeXis]: Where is it hanging up?
[MidLifeXis]: ISTR having a couple of issue based on undeclared dependencies around the time I was looking at that module on my last project, but cannot say if that was the module that I had the dependency issues with.
[MidLifeXis]: (5.22 at that time)
[MidLifeXis]: Yeah, I know, really helpful :-)
[Corion]: If all else fails, Spreadsheet::XLSX should be "installable" by manually copying the files, provided that the prerequisites are met
[thezip]: It fails in the "formatted 2-digit numeric" tests
[thezip]: Okay Corion, that's what I wanted to hear. Thanks!
[Corion]: Oh, a test failure... Just force-install it then? --force and potentially --notest to skip the tests alltogether ?

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2017-03-23 17:12 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (290 votes). Check out past polls.