You read the files from the folder $Line_QC, and check that they exist in "$Nav_Line_QC/098/", but try to open them in the current directory.

Also for your information, the $ sigil should be used whenever you fetch a single (scalar) value from a variable. Either the variable already is a scalar, like $diag_file, or you are trying to fetch a single element out of an array (or hash): $diag_files_array[0]. Perl will actually complain about this if you have use warnings; at the top of your program (you should, it lets perl try to guess when you have done something wrong, and perl is often right).

The quotemeta is not required here, instead if you want to be sure that perl interprets your path correctly, you should use the three parameters version of open,

my $file; open($file, '<', $path) or die "Can't open file $path: $!"; while (my $line = <$file>) { ... } close($file);
The '<' parameter tells perl that you are trying to open the file for reading, and so it doesn't need to guess depending on what is inside the variable $path.

For the filehandle, using a lexical (a my variable) instead of bareword (DIAG in your case) protects your file against being used in the wrong place (DIAG can be used anywhere), and the file would actually be closed automatically when the variable goes out of scope (at the end of the block).

Last advice, instead of writing die after each open, you can just add use autodie; at the top of your file, to get a useful error message without having to write it yourself.

Edit: fixed the grammar a little


In reply to Re: Dealing with files that contain '@' in the filename by Eily
in thread Dealing with files that contain '@' in the filename by elef4nt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.