Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

suppressing stat/newline warning

by superpete (Beadle)
on Nov 14, 2002 at 06:17 UTC ( #212775=perlquestion: print w/replies, xml ) Need Help??

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://212775]
Approved by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-03-02 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (57 votes). Check out past polls.

    Notices?