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

I have a file. I am opening it. My fancy filename does not feel like the issue, since the output from the snippet below is:
reading movement file in
I have evaled the input

However, I would also like to see the input. I would like it evaled! I don't even get out from the second print. I certainly am not benefitting from the eval (which will assign some wonderful values to some local variables-- the values having been Data::Dumper->Dump'ed previously).

I have tried many variations on this theme using foreach and while with the . operator. I can look at the file and it's wonderful. I added "or print 'error'" statements to my read statements and get nothing. Once I did manage to get it to print out the first line of the file, but that's it. Any idea what simple thing(s) I'm doing wrong here?
if( open( MVMT, "< $Config{'temp_data_file'}_$Config{'current_period'} +" )) { print "reading movement file in\n"; my $input; undef $/; $input = <MVMT>; close MVMT; print "input: $input\n"; eval $input; print "I have evaled the input\n"; }

Replies are listed 'Best First'.
Re (tilly) 1: Why can I kind of read this file?
by tilly (Archbishop) on Oct 25, 2001 at 04:55 UTC
    Well here if I change the filename to one that I know works, it executes just fine. It even does what you think it should do. So there is no obvious reason for your lack of output.

    But looking at it, I hope you clean it up. You don't bother to do an error check on your open. You don't test $@ after your eval. You manipulate $/ and leave it hosed afterwards (just localize it).

    In short, if I was working with you, I would tell you to start rewriting from scratch with error checks. I strongly suspect that your above problem is going to turn out to be some, "D'oh, I was doing something silly so I didn't really have the problem that I thought I did!" kind of issue. But the lack of sanity checks is going to come back and bite you hard.

Re: Why can I kind of read this file?
by cLive ;-) (Prior) on Oct 25, 2001 at 04:44 UTC
    try adding "or die $!" to your open.

    cLive ;-)

      The open is in an if statement. If the open evaluates false (the necessary condition for "or die" to make a difference) the rest of the block following the if should not execute. If the open fails, I want to do something else besides die-- especially since this is a Tk application (in Tk applications all callback errors are trapped, and the application will stay running). On a failed open I put a message to that effect in my status label.

      Further research has indicated that the file is being read, since I can do:
      foreach my $line (<MVMT>) { print $line; }
      and get the results. But if I do:
      my @foo; foreach my $line (<MVMT>) { push( @foo, $line ); } my $file = join('', @foo);
      then $file will be empty where @foo is completely as expected.

      This is a Windows 2000 machine with ActivePerl's latest, if that makes a difference.
        What you are reporting is *extremely* hard to believe. Failing a serious problem with your computer or Perl installation, I would go so far as to call it impossible. Either that or the problem is with some buggy C library that you have loaded which has gone in and edited the Perl data structures behind Perl's back.

        Could you do us a favour and come up with the shortest complete program, along with associated movement file, which demonstrates the failure?