Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 6th, 2007, 10:52 PM
Registered User
 
Join Date: Feb 2007
Location: Chennai, TamilNadu, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old February 14th, 2007, 08:14 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old February 15th, 2007, 03:19 AM
Registered User
 
Join Date: Feb 2007
Location: Chennai, TamilNadu, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

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

Freedolen

Reply With Quote
  #4 (permalink)  
Old February 21st, 2007, 07:30 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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

www.crmpicco.co.uk
www.ie7.com
Reply With Quote
  #5 (permalink)  
Old March 4th, 2007, 10:50 PM
Registered User
 
Join Date: Feb 2007
Location: Chennai, TamilNadu, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old March 5th, 2007, 09:00 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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

www.crmpicco.co.uk
www.ie7.com
Reply With Quote
  #7 (permalink)  
Old March 5th, 2007, 11:14 PM
Registered User
 
Join Date: Feb 2007
Location: Chennai, TamilNadu, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #8 (permalink)  
Old March 14th, 2007, 06:07 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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
Reply With Quote
  #9 (permalink)  
Old April 9th, 2007, 01:13 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #10 (permalink)  
Old May 8th, 2007, 11:07 PM
Registered User
 
Join Date: Feb 2007
Location: Chennai, TamilNadu, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl help ZORCH Perl 3 April 25th, 2007 12:09 PM
char* argv in main() - counting and termination proslambano BOOK: Ivor Horton's Beginning Visual C++ 2005 1 March 14th, 2007 04:33 PM
char* argv to main - counting and termination proslambano C++ Programming 1 March 4th, 2007 12:22 AM
perl vidura Perl 6 December 7th, 2006 05:50 AM
perl jeet Perl 1 March 6th, 2006 04:06 PM



All times are GMT -4. The time now is 06:54 PM.


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