Really dumb perl/terminal question

Agroking

Registered
Please don't bite my balls off for this one, this is going to make me look like an idiot, I can tell.
How do I run a perl script in terminal when it has spaces in it's name? It thinks the directory is over when I try... It looks like this:

RewardsForPrimeNumbers:~ Riley$ perl /Users/Riley/Desktop/PERL/2 The Australian-Search for "Stephen Fitzpatrick".pl
Can't open perl script "/Users/Riley/Desktop/PERL/2": No such file or directory


Thankyou in advance!
 
Use quotes or \ as escape. For now it thinks the path ends at "/Users/Riley/Desktop/PERL/2"

perl /Users/Riley/Desktop/PERL/2\ The\ Australian-Search\ for\ "Stephen Fitzpatrick".pl
Or perl "/Users/Riley/Desktop/PERL/2 The Australian-Search" for "Stephen Fitzpatrick".pl

If "2 The Australian-Search" is the directory ..
 
no, sorry, that was the entire name, Just say if i use a different example:

RewardsForPrimeNumbers:~ Riley$ perl /Users/Riley/Desktop/PERL/Hello World.pl
Can't open perl script "/Users/Riley/Desktop/PERL/Hello": No such file or directory


Is this what you mean?

RewardsForPrimeNumbers:~ Riley$ perl /Users/Riley/Desktop/PERL/Hello\ World.pl

Because that doesn't seem to work for me...
 
You could encapsulate it in quotes, like so:
Code:
perl "/Users/Riley/Desktop/PERL/Hello World.pl"
And the backslash thing should work as well -- you can try using terminal completion: type "perl /Users/Riley/Desktop/PERL/Hello" and then hit the TAB key -- the rest of the path should be filled in automatically (provided you don't have any other files in there that start with "Hello") and you can see the proper syntax after the shell auto-completes the path and filename.
 
There is one reason why ' (single quotes) are better than " (quotes): In shell (both commandline and script mode), text inside ' quotations is read character by character, but in " quotations variables are expanded first. So, if you have variable

Code:
name='Hello World'

code

Code:
perl "$name.pl"

executes "Hello world.pl", but

Code:
perl '$name.pl'

executes $name.pl, i.e. with the dollar character. Of course it might come handy, but if you do hot remember it, the reason might be hard to find.
 
Back
Top