in reply to Re: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
in thread Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE

error opening D:/www/data/text/: No such file or directory at D:\www\cgi-bin\init.pl line 70.

Thats what the the error said. Why $_ didnt get interpolated?
Why? while (@files) supposed to contain all available .txt filenames from '/data/text'
And i say while(@files) so to iterate one filename item after another in the loop so with the use of $_ i could open them and read the contents of it.
Did i made a syntax error in the code? Isn't while (@files) a valid statement meaning iterate on every item of array @files?

  • Comment on Re^2: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE

Replies are listed 'Best First'.
Re^3: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
by runrig (Abbot) on Dec 31, 2007 at 21:01 UTC
    Isn't while (@files) a valid statement meaning iterate on every item of array @files?

    It is a valid statement, but it does not mean what you think it means. It iterates as long as @files is true, i.e., forever (since you do not modify @files). Again, I implore you to go read perlsyn (and/or a good perl book) and learn something.

      I was under the impression that 'while(@files)' iterates over each item of the array as long as @files is true, which means as long as it reaches up to the last item of tha array @files. ps. I have a book and read a few things last year but i guess that i need to read more...
        Yes you should probably read more of that book :-)

        Anway: an array only becomes false when it's empty. while (@array) will either not loop at all if the array is empty or loop forever until the array is empty.

        while (<filehandle>) is a special case. all other construct with while(something) just test if something is true.

        Compare the results of running
        perl -e 'print "$_\n" for (1,2,3,4)'
        to
        perl -e 'print "$_\n" while (1,2,3,4)'
        See what kind of results you get... The truth is that, no, 'while' does not iterate over the list/array, it loops while it is true (evaluated as a boolean). What you're looking for is the 'for' statement.

        -Paul