""Ralph H. Stoos Jr."" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> All,
>
> I have been asked to do something in Access or Excel which I find
> disagreeable.  Open Source is the way to go and also, PERL is more
> flexible.  I might even obtain a little professional development on this.
>
> My last post seemed to confuse folks (thanks to all who responded).  I
> will try to clarify.
>
<snip data>
>
> OK, so here is the task.  The first row I want to turn into variable
> names. Machine, PurgeSuccess, etc.  Then with that removed the real work
> happens.  The script would then request which variables I would like to
> sort on or find records (rows) that contain the "matches" specified.
>

Ralph,

The other suggestions are correct, you want this data in a rdbms. But perl 
has modules that treat csv files as a database:

$ cat driver.pl
use warnings;
use strict;

use DBD::CSV;
my $dbh = DBI->connect("DBI:CSV:f_dir=./shop;csv_eol=\n;");

my $sql = 'select * from machines';
my $sth = $dbh->prepare( $sql );
$sth->execute;

while ( my $row = $sth->fetchrow_hashref ) {
  print( "$row->{Machine}: $row->{NameJobCfg}\n");
}

using your data, I get this:

$ perl driver.pl
1125785731: _SFM20_IOT7_SFM7_BFM20_BFM2
1125785731: _SFM20_IOT7_SFM7_BFM20_BFM2

In other words, do NOT write a parser for the file. Your client will loose 
interest long before you get it right. Its a wheel that has already been 
invented.

DBD::CSV (a la SQL::Statement) allows arbitrairily complex WHERE and ORDER 
BY clauses for filtering and sorting.

Here is how to set up the directory structure for the above program:

$ ls -l
total 8
-rw-rw-r--    1 trwww    trwww         285 Jun 23 12:26 driver.pl
drwxrwxr-x    2 trwww    trwww        4096 Jun 23 12:12 shop
$ ls -l shop
total 4
-rw-rw-r--    1 trwww    trwww         741 Jun 23 12:04 machines

driver.pl is the program above. The file shop/machines is your csv file.

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to