clscott has asked for the wisdom of the Perl Monks concerning the following question:

In my following code snippet $! is not populated and the script does not die but the diamond operator is not looping me through the lines.

The diamond operator works fine if I move the file contents into __DATA__ and read from there.

I know that there has to be some strange action at a distance thing going on because I'm working on someone else's code, with tons of included files that declare all kinds of globals and this operation only fails some of the time.

Any hints about what I should be looking for?

open (RESULTS, "<$tempfile") or die "Can't open results: $!"; while(<RESULTS>){ chomp; push @results, $_; print "$. $_\n"; }
Contents of $tempfile :
55940 82665 24560 31102 31160 82725 26161 82685
Absolutely perplexed, --
Clayton aka "Tex"

Replies are listed 'Best First'.
Re: open works fine but not working
by dragonchild (Archbishop) on Jul 26, 2001 at 23:30 UTC
    Try doing this:

    chomp(my $line = <RESULTS>); print "Read in: '$line'\n"; while (defined $line) { # Do stuff here chomp ($line = <RESULTS>); }
    That way, you can make sure of what you're reading. :)
      All I get is the warning that I'm chomping on an uninitialised value for the first chomp, which I already knew.

      The files I am reading have a maximum of 10 lines and all of them are written by the same routine. If I wrote the only thing should be different is the SQL

      I'm looking at the file via the command line both before and after I open it in the program. It has the data and remains intact (as it should).

      Like I said, perplexing.
      Plaform:

      bash-2.04$ uname -a OSF1 hostname V5.0 1094 alpha
      Perl:
      bash-2.04$ perl -v This is perl, v5.6.0 built for alpha-dec_osf
      Thanks,
      --
      Clayton aka "Tex"
        All I can say is that if the open doesn't fail, that means it opened a filehandle. Now, there is a way to have the open fail if the file doesn't exist.

        One more thing to check is to make sure that you don't have any relative-path craziness. Do you change directories during this program's execution? If you do, that could very possibly be the reason why this fails intermittently.

Re: open works fine but not working
by petral (Curate) on Jul 27, 2001 at 04:36 UTC
    I'm sure you did this, but no one's mentioned it yet, print out $tempfile just before (and after?!?) open, and fileno RESULTS.
    (The "is not a typwriter" is almost certainly from an earlier output command of some sort (or something returning its own errno which happens to match that value)).

      p

Re: open works fine but not working
by converter (Priest) on Jul 27, 2001 at 01:19 UTC

    Just a shot in the dark, but is it possible that another process is clobbering the file? Maybe you should try

    warn "size: ", -s $tempfile;

    after the open() statement.

Re: open works fine but not working
by converter (Priest) on Jul 27, 2001 at 05:27 UTC

    A clue to the meaning of the "not a typewriter" message. An excerpt:

    "Not a typewriter" is an unfortunate message, that is really only meaningful in a limited context while the same error can happen in other cases. A better message is "Innapropriate ioctl for device". (and some versions of Unix have changed it to this). This error happens when the ioctl() function attempts an operation that is not supported, for example, trying to rewind a tty or to set the baud rate on a magtape.

    Since this problem seems to fall under the category "strange," I'd try to track down the source of this message and find out which device it's related to.