in reply to opening a file

Your code:

open($site_dnm); @DNM = <$site_dnm>; close($site_dnm);

One immediate problem is that open requires a filehandle AND a filename, i.e. open FOO, "foo.txt";

Or, even better,

open FOO, "foo.txt" or die "Can't open foo.txt: $!\n";

Which will abort the script and tell you why it couldn't open.

Then, when you read, you read from the filehandle, i.e. my @foo = <FOO>;

See perlfunc:open for more details.

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Replies are listed 'Best First'.
RE: RE: opening a file
by Shendal (Hermit) on Nov 01, 2000 at 02:14 UTC
    Technically speaking, open does not require a filehandle and a filename. From the page you referred to:

    Opens the file whose filename is given by EXPR, and associates it with FILEHANDLE. If FILEHANDLE is an expression, its value is used as the name of the real filehandle wanted. If EXPR is omitted, the scalar variable of the same name as the FILEHANDLE contains the filename. (Note that lexical variables--those declared with my()--will not work for this purpose; so if you're using my(), specify EXPR in your call to open.)

    That said, it's rare/dangerous/not-a-good-idea to use this fuctionality. I'd recommend using the two-parameter form you describe.

    Cheers,
    Shendal
RE: RE: opening a file
by ImpalaSS (Monk) on Oct 31, 2000 at 22:36 UTC
    The problem is, the files dont have an extension, they are just called de-nj-md for example. Kilinrax, I tried it the way you showed me and the array's still came up blank? Any suggestions??
    Thanks Guys
    Dipul
      This script will check the files you named to see that they all exist, are readable by the script, and are not empty.
      Hopefully, running it will help you pinpoint the problem.
      #!/usr/bin/perl -w use strict; my @files = ("/mnt/csphil/home/fburns/domereports/Weekly_Reports/de-nj +-md", "/mnt/csphil/home/fburns/domereports/Weekly_Reports/pa_only", " +/mnt/csphil/home/fburns/domereports/Weekly_Reports/phila_market"); my $file; foreach $file (@files) { if (! -e $file) { warn "$file does not exist"; next; } warn "$file is unreadable" unless -r $file; warn "$file has zero size" if -z $file; }