Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Re^5: How to pass a file to GetOpt

by kcott (Archbishop)
on Jul 11, 2012 at 00:57 UTC ( #980988=note: print w/replies, xml ) Need Help??

in reply to Re^4: How to pass a file to GetOpt
in thread How to pass a file to GetOpt

You'll need to quote pathnames with embedded spaces:

perl -input "C:\Users\Mruppe2\workspace\Perl 5 Essent +ial Training\MPMStats Project\error_log" -output C:\temp\output9.csv

-- Ken

Replies are listed 'Best First'.
Re^6: How to pass a file to GetOpt
by frozenwithjoy (Priest) on Jul 11, 2012 at 04:58 UTC
    OP: for reasons like this, I recommend not putting spaces in any filenames. It makes things much easier in the long run.
      Whereas I agree that it's better to avoid spaces, unfortunately we don't always have control over filenames. It may be ok to not care about spaces in quick and dirty test scripts, but we normally don't have that luxury in production environments for example. It's better when the code is prepared to handle unusual characters in the file names rather that assume that they will never happen.

        You are correct that code should handle the case of, for instance, file names with spaces. However, in the example given, where the Perl interpreter is being invoked on the Windows cmd.exe command line along with a script name and command line parameters, it is cmd.exe that is handling the command line arguments and passing them to Perl. No amount of defensive programming in one's script would prevent a file name with space that does not have double quotes around it from being interpreted as two different elements of what becomes @ARGV.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://980988]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2023-09-30 10:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found