in reply to problem opening file

Perl provides a (usually helpful) error message in the variables $!.

So change your code to read

open (...) or die "Can't ope file: $!";

And you'll know more.

Replies are listed 'Best First'.
Re^2: problem opening file
by Fletch (Bishop) on Jan 10, 2008 at 18:00 UTC

    And it's also good practice to include the filename you're attempting to open in the message as well so you know what you were trying to monkey with as well as why exactly it failed.

    (And a hint as to your specific problem: backslashes, "\", are special characters in double quoted strings; Perl will allow you to use plain slashes, "/", in filenames that you pass to system calls to avoid just this kind of problem.)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      And if you had warnings enabled you would have got warnings about unrecognized escapes. Putting them in I got these messages:

      Unrecognized escape \H passed through at Perl-1.pl line 22. Unrecognized escape \P passed through at Perl-1.pl line 22.
      It is considered good practice to start each script with
      use warnings; use strict;
      which will pick up a lot of these types of problems.

      hello monks
      I tried using // because single / will be an escape character
      but it did not work even after doing that
      Unable to open file:No such file or directory at C:\Perl\hprd.pl line 14.
      is there any way to open files from a subdirectory

        No, a two slashes are . . . two slashes. Two backslashes make a single slash because the first escapes the later. It makes a difference which way they're pointing because they're different characters. Read the section on 'quotelike operators' in perlop.

        perl -le 'print "// \\"'

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.