I searched around my trusty Perl documentation and of course, online at http://perldoc.perl.org/ and I found I could use a special variable that contains the operating system name. Here's what I came up with:
my $infile = $ARGV[0];
my $os = $^O; # woohoo there's a special variable I can use for this
get_xmlpath();
sub get_xmlpath
{
if ( $os eq "darwin" )
{
$xmlpath = '/private/var/tmp/xml-data/';
}
else
{
$xmlpath = '/var/tmp/xml-data/';
}
$infile = "$xmlpath$infile.xml";
print "Using XML file: " . $infile . "\n";
return ($infile);
}
Could it be done using less lines? Of course, but then I think Perl Golf is just plain dumb. Disclaimer: this will not work on Win32, fortunately I never have to use Perl on Win32.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.