Hello folks. I was wondering if somebody could help me out and let me know
how to solve this problem.

I am trying to write an interactive script that prompts the user to specify
a path to a DMG file on their system. It seems that once a file is inputted
via drag and drop in this manner, the file does not seem to exist to the
script. I figured at first this may be due to the shell escaping the input,
but removing these escapes did not help matters. Here is what I built to
describe my issue (tested with directories w/ spaces on purpose):

#!/usr/bin/perl

sub line { print "-" x 50, "\n"; }

# Path as script argument
my $fileOne = $ARGV[0];

# Path as user input
print "Enter file: ";
chomp(my $fileTwo = <STDIN>);

# Path as explicit 
my $fileThree = "/Users/my_username/Desktop/with spaces/IAOD.dmg";

# Another test to remove the escapes from the shell
my $fileFour = $fileTwo;
$fileFour =~ s/\\//g;

print "\nDumping paths\n";
&line;
print <<EOF;
\$fileOne => $fileOne
\$fileTwo => $fileTwo
\$fileThree => $fileThree
\$fileFour => $fileFour
EOF
print "\nTesting formats:\n";
&line;
print -f $fileOne ? "\$fileOne => exists\n"
  : "\$fileOne => does not exist\n";
print -f $fileTwo ? "\$fileTwo => exists\n"
  : "\$fileTwo => does not exist\n";
print -f $fileThree ? "\$fileThree => exists\n"
  : "\$fileThree => does not exist\n";
print -f $fileFour ? "\$fileFour => exists\n"
  : "\$fileFour => does not exist\n";

__DATA__
prompt$: perl test /Users/my_username/Desktop/with\ spaces/IAOD.dmg
Enter file: /Users/my_username/Desktop/with\ spaces/IAOD.dmg

Dumping paths
--------------------------------------------------
$fileOne => /Users/my_username/Desktop/with spaces/IAOD.dmg
$fileTwo => /Users/my_username/Desktop/with\ spaces/IAOD.dmg
$fileThree => /Users/my_username/Desktop/with spaces/IAOD.dmg
$fileFour => /Users/my_username/Desktop/with spaces/IAOD.dmg

Testing formats:
--------------------------------------------------
$fileOne => exists
$fileTwo => does not exist
$fileThree => exists
$fileFour => does not exist


--
Ian Ferguson
Toronto, Canada
mailto:[EMAIL PROTECTED]




Reply via email to