p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Perl (http://p2p.wrox.com/forumdisplay.php?f=196)
-   -   Using ARGV in Perl (http://p2p.wrox.com/showthread.php?t=53716)

ghara September 13th, 2007 02:21 AM

Hi!
ive used this code...
#!/usr/bin/perl -w

use strict;
use warnings;

print "First Argument: $ARGV[0]";
print "\n********************\n";
print "Second Argument: $ARGV[1]";

and the output is....
First Argument: C:\First Folder\test
********************
Second Argument: C:Second Folder




mariahayek September 15th, 2007 11:16 AM

Quote:

quote:Originally posted by ghara
 Hi!
ive used this code...
#!/usr/bin/perl -w

use strict;
use warnings;

print "First Argument: $ARGV[0]";
print "\n********************\n";
print "Second Argument: $ARGV[1]";

and the output is....
First Argument: C:\First Folder\test
********************
Second Argument: C:Second Folder




it works.thank you very much..

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
http://coco4info.com
http://alwaysdirectory.com

bala2910 February 16th, 2010 05:20 AM

Hii,
I copied and pasted the code of yours and executed in my env. its working perfectly well. wat i have notices is that, i was in bash. in your terminal type "csh" which will set up the c shell env. its works perfectly well in this env.


[bala@DEV13 ~/Desktop]$ cat example.pl
#!/usr/bin/perl

use strict;
use warnings;

print "First Argument: $ARGV[0]";
print "\n********************\n";
print "Second Argument: $ARGV[1] \n";
[bala@DEV13 ~/Desktop]$ perl example.pl "D:\First Folder\test\" "D:\Second\ Folder"
First Argument: D:\First Folder\test\
********************
Second Argument: D:\Second\ Folder
[bala@DEV13 ~/Desktop]$


regards
Bala

anuragamodi May 27th, 2010 12:46 AM

Solution!!!
 
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

Try & execute this with quotes(") & slash(\) seperated with a space to get the desired output. [:)] Use as below:- [;)]
perl test.pl "D:\First Folder\test\ " "D:\Second Folder"

anishkumar_k May 28th, 2010 12:25 AM

Try giving the arguments inside single quotes.

tempxyz January 6th, 2012 09:31 AM

solution!
 
Hi

execute the script from command line as follows


perl test.pl "D:\First Folder\test\\" "D:\Second Folder"

i hope,this will work..

pavanucs April 19th, 2012 08:22 AM

Quote:

Originally Posted by Freedolen (Post 53716)
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

hi....
just place \n after $ARGV[0].
THATS IT..
HAVE FUN

indana_vamsi September 14th, 2012 10:44 AM

hi,
you have used "\" which is an escape character. try to use \\ instead

ciderpunx October 18th, 2012 06:36 PM

The following is redundant:

#!/usr/bin/perl -w
...
use warnings;

-w /means/ use warnings.

The previous poster means that when you use a \ character befor another it escapes that character. perl will read:

"D:\First Folder\test\" "D:\Second Folder"

As
"D:First Foldertest" "

So, place a \ before your \s and all will be well.
"D:\\First Folder\\test\\" "D:\\Second Folder"

Cheers


All times are GMT -4. The time now is 03:28 PM.

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