Why does my Perl script fail on “~/” but works with “$ENV{HOME}”?

后端 未结 3 1687
陌清茗
陌清茗 2021-01-26 22:47

I have been using this script of mine FOREVER and I have always been using \"~/\" to expand my home directory. I get into work today and it stopped working:

#if          


        
3条回答
  •  死守一世寂寞
    2021-01-26 23:06

    The tilde expansion is not done by perl, it is done by the shell.

    You should instead use:

     use File::Spec::Functions qw( catfile );
     ...
     my $fn = catfile $ENV{HOME}, 'tmp', "find_$strings[0].rslt";
     ...
     open my $out, '>', $fn or die "Cannot open '$fn': $!";
    

提交回复
热议问题