Help - Search - Member List - Calendar
Full Version: passing arguments with white spaces
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Lohit
Hi there,
how do i pass arguments with spaces in it.
exaple if i pass fun("abc is not bcd");
@ARGV would store this as 4 words. how do i retrieve it as $var = "abc is
not bcd";
thanks!!

John Doe
lohit am Montag, 4. Juli 2005 09.17:
QUOTE
Hi there,
how do i pass arguments with spaces in it.
exaple if i pass fun("abc is not bcd");

indicates that you pass the string to a _subroutine_

QUOTE
@ARGV

is normally used to get arguments to the _script_

QUOTE
would store this as 4 words. how do i retrieve it as $var = "abc is
not bcd";
thanks!!

Could you provide some code, and how you invoke it?

joe

Lohit
lets assume I call the function as show below
func("arg1","arg2","this is arg 3", "this is arg 4");
now inside func function how do I retrieve my arguments
sub func()
{
foreach $arg in (@ARGV) {
print "$argn";
}
}
this would print
arg1
arg2
this
is
arg3
this
is
arg4

On 7/4/05, John Doe <[Email Removed]> wrote:
QUOTE

lohit am Montag, 4. Juli 2005 09.17:
Hi there,
how do i pass arguments with spaces in it.
exaple if i pass fun("abc is not bcd");

indicates that you pass the string to a _subroutine_

@ARGV

is normally used to get arguments to the _script_

would store this as 4 words. how do i retrieve it as $var = "abc is
not bcd";
thanks!!

Could you provide some code, and how you invoke it?

joe

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response




Ing. Branislav Gerzo
lohit [l], on Monday, July 4, 2005 at 13:21 (+0530) contributed this
to our collective wisdom:

l> lets assume I call the function as show below
l> func("arg1","arg2","this is arg 3", "this is arg 4");
l> now inside func function how do I retrieve my arguments
l> sub func()
l> {
l> foreach $arg in (@ARGV) {
l> print "$argn";
l> }

use @ARGV for passing args from commandline. You should use @_ for
function, try this:

func("arg1","arg2","this is arg 3", "this is arg 4");

sub func {
foreach my $arg (@_) {
print "$argn";
}
}

--

How do you protect mail on web? I use http://www.2pu.net

[We will release no software before its time.]

John Doe
lohit am Montag, 4. Juli 2005 09.51:
QUOTE
lets assume I call the function as show below
func("arg1","arg2","this is arg 3", "this is arg 4");
now inside func function how do I retrieve my arguments
sub func()
{
foreach $arg in (@ARGV) {
print "$argn";
}
}
this would print
arg1
arg2
this
is
arg3
this
is
arg4

sub func() {
# arguments are in @_, not @ARGV
print join "-", @_;
}

Invocations:

func("arg1", "arg2");
# prints:
arg1-arg2

func("a string with blanks", "another one");
# prints:
a string with blanks-another one


You should at least read

perldoc perlsub


joe

[snip]


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.