Hi Monks!

I am stuck here, I have a direcory with about 40 xml files, I need to parse these files all at once, or by a range from a select dropdown menu, I have the code to go to the direcory and search for the files I need. But on the next step is where I am having a problem, how to pass the range of files and use it with this line,

my $xp = XML::XPath->new(filename => $x_file);

Is it possible? How could I do that?
I got it to work with one file, but now that I have this much more files I am kind of lost.
I think I need to pass these files into an array or something, using a range between to first file till the last one selected, any help will be great!!!!
Thank you!!!

#!/perl/bin/perl #use strict; #commented out for testing propose only use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use DBI; use XML::XPath; use XML::XPath::XMLParser; my $q = new CGI; print header(); my $transac = $q->param('transac'); my $get_file_from = $q->param('get_file_from'); my $get_file_to = $q->param('get_file_to'); if($transac eq "parse_now"){ &parse_now; }else{ &main; } sub main{ print "Start Main:<br><br>"; print " <table border=\"1\" width=\"600\" cellspacing=\"0\" cellpadding +=\"0\"> <tr><form name=\"xmlform\" action=\"get_node.pl\" method=\"GET +\"> <input type=\"hidden\" name=\"transac\" value=\"parse_now\ +"> <td>Check Policies from:&nbsp;&nbsp;&nbsp;&nbsp;</td> <td><div align=\"center\"> <select name=\"get_file_from\">"; my $dir = '/xml'; opendir(DIR, $dir) or die $!; while (my $file = readdir(DIR)) { # We only want files next unless (-f "$dir/$file"); # Use a regular expression to find files ending in .xml next unless ($file =~ m/\.xml$/); # change to the date format if needed $file=~/(.*?)_(\d{4})(\d{2})(\d{2})_(.*?)/; my $year= $2; my $month= $3; my $day = $4; print "<option value=\"$file\">$file</option>"; } closedir(DIR); #exit; print " </select> </td> <td>&nbsp;&nbsp;&nbsp;to&nbsp;&nbsp;&nbsp;</td> <td><div align=\"center\"> <select name=\"get_file_to\">"; my $dir = '/xml'; opendir(DIR, $dir) or die $!; while (my $file = readdir(DIR)) { # We only want files next unless (-f "$dir/$file"); # Use a regular expression to find files ending in .xml next unless ($file =~ m/\.xml$/); # change to the date format if needed later $file=~/(.*?)_(\d{4})(\d{2})(\d{2})_(.*?)/; my $year= $2; my $month= $3; my $day = $4; print "<option value=\"$file\">$file</option>"; } closedir(DIR); #exit; print " </select> </td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td align=\"right\"><input type=\"submit\" value=\"Send\"></td> </tr></div> </table></form>"; } # End Sub Main sub parse_now{ # change to the date format if needed later $get_file_from=~/(.*?)_(\d{4})(\d{2})(\d{2})_(.*?)/; my $year= $2; my $month= $3; my $day = $4; my $x_file = "/xml/$get_file_from"; my $xp = XML::XPath->new(filename => $x_file); # more stuff here ........ exit; } #end sub parse now

In reply to Range File Open by Anonymous Monk

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.