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
As stated by prior answer, "~
" (tilde) is expanded by shell, not perl.
Most likely, it was working due to existence of a directory "~
" in your current directory, which eventually got removed, leading to the bug surfacing:
To illustrate:
Tilde not working in Perl, using $ENV{HOME} works:
$ echo MM > MM $ perl5.8 -e '{print `cat ~/MM`}' cat: cannot open ~/MM $ perl5.8 -e '{print `cat $ENV{HOME}/MM`}' MM
Making the tilde-named directory works:
$ mkdir \~ $ echo MM > \~/MM $ ls -l \~ -rw-rw-r-- 1 DVK users 3 Jun 10 15:15 MM $ perl5.8 -e '{print `cat ~/MM`}' MM
Removing it restores the error, as you observed:
$ /bin/rm -r \~ $ ls -l \~ ~: No such file or directory $ perl5.8 -e '{print `cat ~/MM`}' cat: cannot open ~/MM
This offers a plausible explanation, though I'm not 100% there can't be others.
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': $!";
~
is expanded by the shell. Perl has no idea about it. So, it would work only within a shell script.