This is probably trivial to most of you, but I still do not feel very confident in this area![[sadeyes] [sadeyes] [sadeyes]](/data/assets/smilies/sadeyes.gif)
Following program tries to constitute a filename from its basic constituents:
The name parts have deliberately escape characters sequences. Judging the output, either dsn1 or dsn11 is the way to go:
Out of the two possibilities, I would rather prefer option dsn11 - as to avoid all interpolation.
In my real program however I am not in control of the filenames: they are read from a database into a perl variable (via DBI ODBC) and then split into their base/dir parts (via use File::Basename). Or they can be read by readdir into an array.
My question now is: Can I be sure that the variable that is used to read the filename behaves like a single quoted string (like $sa and $sb)? And if not what is the best way to handle this problem?
PS: Windows is the OS (and I don't like a mixture of forward- and backward slashes in the same filename)
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
![[sadeyes] [sadeyes] [sadeyes]](/data/assets/smilies/sadeyes.gif)
Following program tries to constitute a filename from its basic constituents:
Code:
$sa='C:\tabc\nxyz';
$sb='log.txt';
$dsn1="$sa\\$sb";
$dsn11=$sa.'\\'.$sb;
print "dsn1= $dsn1\n";
print "dsn11= $dsn11\n";
print "\n";
$sc="C:\tabc\nxyz";
$sd="log.txt";
$dsn2="$sc\\$sd";
$dsn22=$sc.'\\'.$sd;
print "dsn2= $dsn2\n";
print "dsn22= $dsn22\n";
The name parts have deliberately escape characters sequences. Judging the output, either dsn1 or dsn11 is the way to go:
Code:
STDOUT output area
dsn1= C:\tabc\nxyz\log.txt
dsn11= C:\tabc\nxyz\log.txt
dsn2= C: abc
xyz\log.txt
dsn22= C: abc
xyz\log.txt
In my real program however I am not in control of the filenames: they are read from a database into a perl variable (via DBI ODBC) and then split into their base/dir parts (via use File::Basename). Or they can be read by readdir into an array.
My question now is: Can I be sure that the variable that is used to read the filename behaves like a single quoted string (like $sa and $sb)? And if not what is the best way to handle this problem?
PS: Windows is the OS (and I don't like a mixture of forward- and backward slashes in the same filename)
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]