http://www.perlmonks.org?node_id=212775

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

In my quest to make my code support completely arbitrary filenames, I think i've succeeded.

But I have uncovered a new issue. Whenever a "-X" test returns a negative result, and the filename happens to have a newline in it (newlines are valid in unix filenames), perl issues a "Unsuccessful stat on filename containing newline" warning. (if we're running perl -w)

According to the perldiag manpage, perl thinks I forgot to chomp my filename. But what if the filename really has a newline in it?

-e "$dir/foo" or mkdir "$dir/foo"

If $dir happens to have a newline in it, the code results in a warning :-(

What to do? Is there a way to suppress that one specific warning?

Replies are listed 'Best First'.
Re: suppressing stat/newline warning
by Zaxo (Archbishop) on Nov 14, 2002 at 06:27 UTC

    In old perl you can't be so specific, but in 5.6+ you can say:

    { no warnings 'newline'; -e "${dir}/foo" or mkdir "${dir}/foo"; }

    After Compline,
    Zaxo

      Rats! I want to support perl 5.0x Thanks for the post, though, I learned something new!