perlfaq nodetype
faq_monk
<P>
Normally perl ignores trailing blanks in filenames, and interprets certain
leading characters (or a trailing ``|'') to mean something special. To
avoid this, you might want to use a routine like this. It makes incomplete
pathnames into explicit relative ones, and tacks a trailing null byte on
the name to make perl leave it alone:
<P>
<PRE> sub safe_filename {
local $_ = shift;
return m#^/#
? "$_\0"
: "./$_\0";
}
</PRE>
<P>
<PRE> $fn = safe_filename("<<<something really wicked ");
open(FH, "> $fn") or "couldn't open $fn: $!";
</PRE>
<P>
You could also use the
<CODE>sysopen()</CODE> function (see <U>sysopen</U>).
<P>