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:

# 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"; }
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.

In reply to Re: how to parse output from isql utility by graff
in thread how to parse output from isql utility by reuben12

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.