Hi Monks,

I am writing a script to open a file that contains a list of path to various files and open each file at the specified path. I have written a function that generates the file containing the path to the files. However, when I open that file to try to open the path of a file, my script is not picking up the entire path.

Example:

The file containing the paths is database.txt. Within database.txt are various paths such as C:\edman\file1.xml, c:\edman\file2.xml. note that each path is on a separte line in database.txt. When I open database.txt any try to read the path open file1 from the specified path, the $_ command only picks up c:\edman\fi thus causing the file not to be opened. Can any monk kindly help me solve this problem?. Pls see my code below.

$| = 1; sub GenerateKeywordsDatabase { print "\nDate: ".localtime(time)."\n"; $kwords = $path."keywords_database.txt"; $temp = $path."temp.txt"; if (opendir (KWORDS, $path) && open(LIST, ">$kwords")) { print LIST "\n================================================ +================\n"; print LIST "\nDATE: ".localtime(time)."\n"; print LIST "\nNAME: ".$ENV{USERNAME}."\n"; print LIST "\n================================================ +================\n\n"; @kwds = sort grep {$_ ne '.' and $_ ne '..'} readdir(KWORDS); foreach(@kwds) { if($_ eq "database.txt") { print ("I can process $_, without calling GenerateTest +File!!!\n"); } elsif($_ ne "database.txt") { GenerateTestFileList(); if (open(DBASE, $path."database.txt")) { while(<DBASE>) { chomp; open(TEMP, ">$temp") || die "cannot open [$tem +p], $!\n"; print TEMP "$_\n"; open(XFILE, $_) || die ("Cannot open [$_], $!\ +n"); while (<XFILE>) { chomp; #if ($_ =~ /\<name\>|\<\/name\>/) #{ print (LIST "$_\n"); #} } } } else { die ("File does not exist, $!\n") } } } } else { die ("Could not open $path, $!\n"); } } 1;

The GenerateTestFileList() function is used to generate the path to the various files I which to open. I have check the paths generated and the are all fine.

Thanks for your assistance.


In reply to Getting path from file 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.