 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 6th, 2007, 11:52 PM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 14th, 2007, 09:14 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Use single quotes round your commandline arguments. Or change your code to:
Code:
print 'First Argument: ' . $ARGV[0];
print "\n********************\n";
print 'Second Argument: ' . $ARGV[1];
(don't have access to a windows machine, so this hasn't been tested)
HTH
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
|
|

February 15th, 2007, 04:19 AM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks for your work. But it doesn't works on Windows. Any other idea?
Freedolen
|
|

February 21st, 2007, 08:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
what is your "shebang" line at the top of the script?
www.crmpicco.co.uk
www.ie7.com
|
|

March 4th, 2007, 11:50 PM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 5th, 2007, 10:00 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
C:\Perl\bin\perl.exe
for Windows...... :-)
www.crmpicco.co.uk
www.ie7.com
|
|

March 6th, 2007, 12:14 AM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 14th, 2007, 06:07 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 9th, 2007, 01:13 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 8th, 2007, 11:07 PM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |