Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
| 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 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
  #1 (permalink)  
Old February 6th, 2007, 11: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
  #2 (permalink)  
Old February 14th, 2007, 09: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
  #3 (permalink)  
Old February 15th, 2007, 04: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

  #4 (permalink)  
Old February 21st, 2007, 08: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
  #5 (permalink)  
Old March 4th, 2007, 11: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

  #6 (permalink)  
Old March 5th, 2007, 10: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
  #7 (permalink)  
Old March 6th, 2007, 12:14 AM
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

  #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
  #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
  #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






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 01:22 AM
perl vidura Perl 6 December 7th, 2006 06:50 AM
perl jeet Perl 1 March 6th, 2006 05:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.