p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   Perl (http://p2p.wrox.com/perl-196/)
-   -   Using ARGV in Perl (http://p2p.wrox.com/perl/53716-using-argv-perl.html)

Freedolen February 6th, 2007 10:52 PM

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

ciderpunx February 14th, 2007 08:14 AM

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

Freedolen February 15th, 2007 03:19 AM

Hi,

   Thanks for your work. But it doesn't works on Windows. Any other idea?

Freedolen


crmpicco February 21st, 2007 07:30 AM

what is your "shebang" line at the top of the script?

www.crmpicco.co.uk
www.ie7.com

Freedolen March 4th, 2007 10:50 PM

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


crmpicco March 5th, 2007 09:00 AM

Code:

    C:\Perl\bin\perl.exe
for Windows...... :-)

www.crmpicco.co.uk
www.ie7.com

Freedolen March 5th, 2007 11:14 PM

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


crmpicco March 14th, 2007 06:07 AM

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

prettyrao April 9th, 2007 01:13 PM

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

Freedolen May 8th, 2007 11:07 PM

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 10:13 PM.

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.