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

Hello Monks! Been a long time, but I am in need of some expert knowledge. I have literally fought with this issue all day and it's driving me nuts. Every time I run the script I am getting "Could not open Server IN2 (/tmp/CommonLog.10.10.10.10): No such file or directory". Yet, I can run ls, head, more, cat, etc against /tmp/CommonLog.10.10.10.10 all day long with no issues. Why would Perl think the file doesn't exist when it plainly does.
foreach my $server (@servers) { open IN2, "<", $provinfile.$server or die "Could not open Serv +er IN2 ($provinfile.$server): $!\n"; open OUT2, ">", $provoutfile or die "Could not open OUT2: $!\n +"; while (<IN2>) { if (/\<13\>/../END OF REPORT/) { #next if /PROXY500/ || /END OF REPORT/; print OUT; } } } close(OUT2); close(IN2);
If you see anything wrong or have any thoughts on where I can go from here (went about 40 different ways today and all dead ends), I would appreciate any assistance.

Replies are listed 'Best First'.
Re: Phantom "No such file" issue
by Athanasius (Archbishop) on Nov 02, 2018 at 02:53 UTC

    Hello ImJustAFriend,

    Because you haven’t explicitly stringified the expession $provinfile.$server, the dot functions as a concatenation operator. So the result is a string, but there is no dot character inserted between the two strings. This is obscured by the error message, which does contain an inserted dot character.

    Update: It’s good practice to ensure that an error message reflects exactly what’s happening. Here, you can accomplish this with an extra assignment:

    for my $server (@servers) { my $full_path = $provinfile . '.' . $server; # or = "$provinfil +e.$server"; open IN2, '<', $full_path or die "Could not open Server IN2 ($full_path): $!\n"; ... }

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Worked like a dream, thank you!