![]() |
Using ARGV in Perl
Hi All,
I am new to this Forum. Below is my perl script: use strict; use warnings; print "First Argument: $ARGV[0]"; print "\n********************\n"; print "Second Argument: $ARGV[1]"; and i save the code in a file test.pl When I execute this with arguments perl test.pl "D:\First Folder\test\" "D:\Second Folder" The Output shown was: First Argument: D:\First Folder\test" D:\Second ******************** Second Argument: Folder The Output what I expect is: First Argument: D:\First Folder\test ******************** Second Argument: D:\Second Folder Is there any idea to get the output what i expect, without changing Backward slashes to Forward slashes or Deleting the Final slash in First argument Thanks in Advance Freedolen |
Use single quotes round your commandline arguments. Or change your code to:
Code:
print 'First Argument: ' . $ARGV[0];HTH -- Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk |
Hi,
Thanks for your work. But it doesn't works on Windows. Any other idea? Freedolen |
|
Hi,
Generally i won't use shebang line in my script. According to my knowledge the shebang line for windows "#!perl". Is this cause any problem on windows perl? Freedolen |
|
Hi,
The inclusion of shebang line also doesn't helps me. Iam getting the same result First Argument: D:\First Folder\test" D:\Second ******************** Second Argument: Folder Regards, Freedolen |
you must have a line at the top of your script, either #! C:\Perl\bin\Perl.exe for Windows or #! /usr/bin/perl for Unix (what i use).
www.crmpicco.co.uk www.ie7.com |
Hi,
You can try putting a \ after Second to represent the space. Try creating such a directory in windows and do a list to see how it prints the directory and use that format. Sorry I am not a windows user but I can think of this... Let me know if this works. If not I can def try helping u out... HTH |
Hi,
Thanks for your reply, but sorry the solution doesn't works and i have also created directories named "First Folder" and "Second Folder" and listed using "dir" command and they lists properly as what i have created. Now i execute as perl test.pl "D:\First Folder\test\" "D:\Second\ Folder" The Output shown was: First Argument: D:\First Folder\test" D:\Second\ ******************** Second Argument: Folder The Output what I expect is: First Argument: D:\First Folder\test ******************** Second Argument: D:\Second\ Folder Freedolen |
| All times are GMT -4. The time now is 04:32 AM. |
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.