I use Perl on Linux, but I started using File::Spec->catfile to make my perl code run on Windows as well, e.g.,
$tmp = File::Spec->catfile($ENV{HOME}, "tmp");
instead of
$tmp = "$ENV{HOME}/tmp";
But how can I make the following code portable:
my @files = <$ENV{HOME}/tmp/*>;
It uses slashes as file separators, so I assume it won’t work on Windows. And I don’t see how to use File::Spec->catfile in that expression?
Since
catfilejust returns a string that can be used as a file name, you can do something like this (untested):But
$ENV{HOME}isn’t likely to be set on a Windows system.You might consider using
File::Spec->tmpdir().