in reply to how to parse output from isql utility
I know how to open a file,write query to it and execute using isql through perl. I just dont know how to implement the above pseudo code.
If the DBI and appropriate DBD module are not in place for the perl you're using (and installing them is "outside your scope" -- nothing to be ashamed of), then your initial approach of using a known, working command line tool (like isql) is fine.
As for how to handle the data within the perl script, your pseudo-code suggests that you're not familiar with perl data types and data structures. I could point you to the "perldata" man page, but if you have trouble with that, try perldsc (data structures cookbook), or any basic book on learning perl, to get a handle on scalars, arrays and hashes, and more elaborate structures built from combinations of arrays and/or hashes. Once you understand how the data storage and structuring works, it can be pretty easy to figure out what sort of structure you need for your app, and how to build it up from (and apply it to) your database queries.
So taking the command-line "isql" tool as the data source, one way to get started would be:
It's likely that your app could use some other sort of data structure to good advantage, in place of the two parallel arrays suggested above, but you haven't said enough about what you're doing.# you already have this part: my $qry_file = "some_name.sql"; # or whatever open( QRY, ">$qry_file" ) or die "can't write $qry_file: $!"; print QRY "select foo from bar where baz='x'\n"; close QRY; # Run isql by opening it as a pipeline # (I'm guessing at the command-line usage): my @fnames, @lnames; # query output will be stored here # update: using the correct variable name for the query file: open( DB, "isql $qry_file |" ) or die "can't run isql: $!"; while (<DB>) { # assuming the tool prints one line per row chomp; # remove newline my ( $lname, $fname ) = split(/\t/); # assuming fields are tab-del +imited push @fnames, $fname; push @lnames, $lname; } close DB; # now you can do whatever you want, iterating over # the contents of @lnames and/or @fnames for my $i ( 0..$#fnames ) { print "Row = $i, Full_name = $fnames[$i] $lnames[i]\n"; }
|
|---|