directory - tilde (~) directories in Perl -


i found slight misbehaviour in perl script when create , check existence of directories tilde sign, doesn't happen if use full /home/user path. when run script first time, creates new directory. when run second time, doesn't recognise existence of directory, , tries create second time:

#!/usr/bin/perl use strict;  $outdir = '~/test'; $cmd = "mkdir $outdir"; unless (-d $outdir) {   0 == system($cmd) or die "error creating outdir $outdir\n $?"; }  1;   [~] $ rm test/ -rf [~] $ perl dir.pl [~] $ perl dir.pl mkdir: cannot create directory `/home/avilella/test': file exists error creating outdir ~/test  256 @ dir.pl line 7. 

how can reliably deal directories use tilde ~ sign in perl?

the tilde interpreted shell mean home directory.

hence perl's -d operator sees different (a file/directory called ~) shell invocation 'mkdir ~/whatever' (which expands ~ mean /home/user).

i try use exclusively perl functions perform operations. you'll avoid spawning new processes , file access performed in consistent fashion.

note perl's mkdir built-in function. note file::glob module does perform expansion of ~ character (perhaps useful if have users entering directory names manually)


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -