Re: passing arguments to perl function with - in the string

2011-11-30 Thread Brandon McCaig
On Wed, Nov 30, 2011 at 10:21:19AM -0500, Brandon McCaig wrote: > You can use subroutines to split functionality into multiple > pieces and store them each in a different file. Oops. xD That sounds like I suggest for you to use a different file for every subroutine. Of course I meant that you shou

Re: passing arguments to perl function with - in the string

2011-11-30 Thread Brandon McCaig
On Tue, Nov 29, 2011 at 06:19:59PM -0500, Nemana, Satya wrote: > Hi Brandon, Igor, Shawn Hello (not sure if it's proper to call you Nemana or Satya or if both names are necessary): > The horror was that the perl compiler pointed at a code some > 1000s of lines below this line for the error which

Re: passing arguments to perl function with - in the string

2011-11-29 Thread Peter Scott
On Tue, 29 Nov 2011 18:19:59 -0500, Nemana, Satya wrote: > P.S : unfortunately, I cant provide more details due to the IP > restrictions, sorry about that, hope you understand, otherwise would > have posted the code in the first go. This is a common constraint. You can always post a version of th

RE: passing arguments to perl function with - in the string

2011-11-29 Thread Nemana, Satya
tions, sorry about that, hope you understand, otherwise would have posted the code in the first go. -Original Message- From: Brandon McCaig [mailto:bamcc...@gmail.com] Sent: 29 November 2011 15:15 To: Nemana, Satya Cc: beginners@perl.org Subject: Re: passing arguments to perl function with

Re: passing arguments to perl function with - in the string

2011-11-29 Thread Brandon McCaig
On Tue, Nov 29, 2011 at 08:12:29AM -0500, Nemana, Satya wrote: > Hi Hello: > I need to pass argument to a function like this -chan_range => > "$chs-$che" > > Normally when this used which works -chan_range => "1-24" > > However, when I try to put variable values instead of a scalar string, I

Re: passing arguments to perl function with - in the string

2011-11-29 Thread Shawn H Corey
On 11-11-29 08:12 AM, Nemana, Satya wrote: However, when I try to put variable values instead of a scalar string, I get compilation errors (the errors are in different part of the code which is completely clueless) Could you post the code that fails and its error message? -- Just my 0.000

Re: passing arguments to perl function with - in the string

2011-11-29 Thread Igor Dovgiy
Hi Satya, Might I suggest to look up a bit into the function's source code? Because it's, well, pretty normal to call subs like that: ... some_func_call(-chan_range => "$beg-$end") ... Of course, $beg and $end variables should be defined already (and contain numeric values, as I see). If not, war

passing arguments to perl function with - in the string

2011-11-29 Thread Nemana, Satya
Hi Sorry for the silly question, but thought someone might help here.(tried googling but this may too silly a beginners question for anyone to have answered previously) I need to pass argument to a function like this -chan_range => "$chs-$che" Normally when this used which works -chan_range

Re: AW: Passing arguments @_

2010-04-30 Thread Shawn H Corey
HACKER Nora wrote: If you do: my ($var1) = @_; You're doing list assignment and, as a result, you assign $var1 to the $_[0] and don't make use of $_[1], $_[2], $_[3], etc., which may or may not exist. Thanks, perfectly clear now. In 'perldoc perlsub' I read that I only have to use parenthe

AW: Passing arguments @_

2010-04-30 Thread HACKER Nora
Hi Shlomi, > Because the lack of parenthesis signifies that the right-hand-side will > be > done in scalar context. As a result it is equivalent to: > > my $var1 = scalar(@_); > > Which is the length of the @_ array (which sometimes have some valid > uses if > you're checking for optional argum

Re: Passing arguments @_

2010-04-30 Thread Shlomi Fish
Hi Nora, On Friday 30 Apr 2010 09:55:33 HACKER Nora wrote: > Hi, > > For calling subroutines and passing arguments on I use e.g. > > my ( $var1, $var2 ) = @_; > > If I have only one argument, this is also ok: > > my ( $var1) = @_; > > But why does > >

Passing arguments @_

2010-04-29 Thread HACKER Nora
Hi, For calling subroutines and passing arguments on I use e.g. my ( $var1, $var2 ) = @_; If I have only one argument, this is also ok: my ( $var1) = @_; But why does my $var1 = @_; not work? In 'perldoc perlsub' I read that I only have to use parentheses when defining mor

Re: Passing arguments to subroutine

2007-06-05 Thread Chas Owens
On 6/5/07, Brad Baxter <[EMAIL PROTECTED]> wrote: snip Apparently, unlike with named subs, both &$anon() and $anon->() ignore prototypes. However, like named subs &$anon gets the caller's @_. But that is almost never mentioned afaict at the places in the docs where the &$anon style call is used

Re: Passing arguments to subroutine

2007-06-05 Thread Brad Baxter
On Jun 1, 9:58 am, [EMAIL PROTECTED] (Chas Owens) wrote: > On 31 May 2007 10:58:54 -0700, Paul Lalli <[EMAIL PROTECTED]> wrote: > > > On May 31, 10:15 am, [EMAIL PROTECTED] (Yitzle) wrote: > > > I suspect one of the tutorials that Google or Perl.org points to has > > > something in it that needs co

Re: Passing arguments

2007-06-02 Thread Paul Lalli
On Jun 2, 9:18 am, [EMAIL PROTECTED] (Steve Bertrand) wrote: > > testsub(35); > > You call the sub with one parameter, integer 35. However, this won't > work as calling the sub before the sub is defined with a prototype will > barf with an error. No it won't. It will print a warning, if and only

Re: Passing arguments

2007-06-02 Thread Chas Owens
On 6/2/07, Alma <[EMAIL PROTECTED]> wrote: Hi, I need to pass id as parameters to a subroutine testsub(35); sub testsub($) { my $self = shift; my $id = @_; print "$id"; } Its printing 3 . am i going wrong in prototype . First off, don't use prototypes until you know exactly what

Re: Passing arguments

2007-06-02 Thread Steve Bertrand
> testsub(35); You call the sub with one parameter, integer 35. However, this won't work as calling the sub before the sub is defined with a prototype will barf with an error. Let's assume had the sub call beneath the definition from the start. > sub testsub($) Above, your prototype says testsub

Re: Passing arguments

2007-06-02 Thread Paul Lalli
On Jun 2, 3:54 am, [EMAIL PROTECTED] (Alma) wrote: > Hi, > > I need to pass id as parameters to a subroutine > > testsub(35); > > sub testsub($) >{ >my $self = shift; >my $id = @_; >print "$id"; > > } > > Its printing 3 That's just a lie. Why are you lying to us? Why are you not

Passing arguments

2007-06-02 Thread Alma
Hi, I need to pass id as parameters to a subroutine testsub(35); sub testsub($) { my $self = shift; my $id = @_; print "$id"; } Its printing 3 . am i going wrong in prototype . -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://

Re: Passing arguments to subroutine

2007-06-01 Thread Chas Owens
On 31 May 2007 10:58:54 -0700, Paul Lalli <[EMAIL PROTECTED]> wrote: On May 31, 10:15 am, [EMAIL PROTECTED] (Yitzle) wrote: > I suspect one of the tutorials that Google or Perl.org points to has > something in it that needs correcting. Actually, it's an unfortunate truth that up until Edition 3,

Re: Passing arguments to subroutine

2007-06-01 Thread Rob Dixon
Paul Lalli wrote: On May 31, 9:35 am, [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote: On May 31, 9:27 am, [EMAIL PROTECTED] (Alma) wrote: # extract the file name # my @parts = split('\/',$file_path); Your split statement seems to be wrong. split uses a regex to match so it should be: s

Re: Passing arguments to subroutine

2007-06-01 Thread Paul Lalli
On May 31, 9:35 am, [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote: > On May 31, 9:27 am, [EMAIL PROTECTED] (Alma) wrote: > > > # extract the file name > > # my @parts = split('\/',$file_path); > Your split statement seems to be wrong. split uses a regex to match so > it should be: > > split /\

Re: Passing arguments to subroutine

2007-05-31 Thread [EMAIL PROTECTED]
On May 31, 9:27 am, [EMAIL PROTECTED] (Alma) wrote: > Hi All, > > I need to pass the result of prepare statement as an argument to the > subroutine. > > sub abc() > { > my $self= shift; > my($id,$title) = @_; > my $sth1= $databasehandle->prepare("select file_path from xyz >

Re: Passing arguments to subroutine

2007-05-31 Thread [EMAIL PROTECTED]
On May 31, 9:27 am, [EMAIL PROTECTED] (Alma) wrote: > sub delete_file() > { > my $self = shift; > my $file_path = @_; That sets $file_path to the number of arguments in the call to the method delete_file(). To set $file_path to the first of the arguments in the call to the method

Re: Passing arguments to subroutine

2007-05-31 Thread Paul Lalli
On May 31, 10:15 am, [EMAIL PROTECTED] (Yitzle) wrote: > I suspect one of the tutorials that Google or Perl.org points to has > something in it that needs correcting. Actually, it's an unfortunate truth that up until Edition 3, the Llama itself recommended that you use the & to call subroutines...

Re: Passing arguments to subroutine

2007-05-31 Thread Chas Owens
On 5/31/07, yitzle <[EMAIL PROTECTED]> wrote: snip I suspect one of the tutorials that Google or Perl.org points to has something in it that needs correcting. snip Probably more than one thing. I would suggest reading the following books to learn Perl and to only use random tutorials on the In

Re: Passing arguments to subroutine

2007-05-31 Thread yitzle
On 31 May 2007 01:27:26 -0700, Alma <[EMAIL PROTECTED]> wrote: -- snip -- unlink($file_path); -- snip -- I'm aware that the question was already answered, but a generic tip for the future. You could try adding a statement like: print "Deleting $file_path\n"; to help debug and ensure t

Re: Passing arguments to subroutine

2007-05-31 Thread Chas Owens
On 31 May 2007 01:27:26 -0700, Alma <[EMAIL PROTECTED]> wrote: snip &deleteposter_file(@row); snip sub delete_file() snip This would seem to be the problem, also where did you learn that you should put & on the front of your subroutine calls? I am curious because I keep seeing people

Re: Passing arguments to subroutine

2007-05-31 Thread Paul Lalli
On May 31, 4:27 am, [EMAIL PROTECTED] (Alma) wrote: > I need to pass the result of prepare statement as an argument to the > subroutine. > > sub abc() The () there very specifically say "This subroutine takes no arguments". > { > my $self= shift; > my($id,$title) = @_; ... and y

Re: Passing arguments to subroutine

2007-05-31 Thread Jonathan Lang
Alma wrote: Hi All, I need to pass the result of prepare statement as an argument to the subroutine. -snip- abc is calling delete_file() . where it need to delete the file stored at the location mentioned in file_path. Its not giving me an error but its not deleting the files from the locatio

Passing arguments to subroutine

2007-05-31 Thread Alma
Hi All, I need to pass the result of prepare statement as an argument to the subroutine. sub abc() { my $self= shift; my($id,$title) = @_; my $sth1= $databasehandle->prepare("select file_path from xyz where id='$id' and title like '$title'"); my $res = $sth1->exec

Re: passing arguments with white spaces

2005-07-04 Thread 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

Re: passing arguments with white spaces

2005-07-04 Thread John Doe
lohit am Montag, 4. Juli 2005 09.51: > 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 "$arg\n"; > } > } > this would print > arg1

Re: passing arguments with white spaces

2005-07-04 Thread 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 "$arg\n"; } } this would print arg1 arg2 this is arg3 this is arg4 On 7/4/05, John Doe <[E

Re: passing arguments with white spaces

2005-07-04 Thread John Doe
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 retrie

passing arguments with white spaces

2005-07-04 Thread 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!!

RE: passing arguments to functions

2004-01-19 Thread Hanson, Rob
OTECTED] Sent: Monday, January 19, 2004 8:15 PM To: [EMAIL PROTECTED] Subject: passing arguments to functions Hi all Problem: I want to send 2 arguments to a subroutine in the form of arrays and want to use their result which is also in the form of an array. Explanation: suppose i have 2

passing arguments to functions

2004-01-19 Thread jassismara
Hi all Problem: I want to send 2 arguments to a subroutine in the form of arrays and want to use their result which is also in the form of an array. Explanation: suppose i have 2 arrays @a=`/bin/cat /some/file` ; # A file that has a list of users @b=`/bin/cat /another/file` ; # Another

Re: Launching shell scripts using PERL and passing arguments

2003-09-04 Thread segmentation fault
you could do something like open SCRIPT, "| /path/to/script" || die("$!"); select(SCRIPT); $|=1; print "argument\n"; select(STDOUT); close(SCRIPT); perldoc perlipc -- ___ Get your free email from http://www.hackermail.com Powered by Outblaze -- To u

Launching shell scripts using PERL and passing arguments

2003-09-04 Thread Rajesh Dorairajan
Hello All, I have a very basic question. I need to launch a Bourne shell script using PERL and automate the responses required by the script. I have shown the sample shell script below: #!/bin/sh echo "Welcome to my script" echo "Do you want to continue" read ans if [ $ans = "n" ] then exit

Re: passing arguments to a subroutine to try and match two fields in a text file

2003-01-17 Thread Rob Dixon
Le Blanc wrote: > I made some changes. Now I get an error message. > > The message says "Can't use string ("") as an ARRAY ref while "strict > refs" in use" > > Here is the code as it stands now, with changes. > > #!/usr/bin/perl -w > use strict; > use Data::Dumper; > use diagnostics -verbose; > >

RE: passing arguments to a subroutine to try and match two fields in a text file

2003-01-17 Thread Le Blanc, Kerry (Kerry)
I made some changes. Now I get an error message. The message says "Can't use string ("") as an ARRAY ref while "strict refs" in use" Here is the code as it stands now, with changes. #!/usr/bin/perl -w use strict; use Data::Dumper; use diagnostics -verbose; print "Enter the Part Number you w

Re: passing arguments to a subroutine to try and match two fields in a text file

2003-01-17 Thread Rob Dixon
[EMAIL PROTECTED] wrote: >> open (FH, './fai.txt') || die "Cannot open file: ($!)"; >> my @parts = ; >> my @rev = ; > > This stores two copies of the file in memory, do you need two copies? > It doesn't actually. The first assignment leaves you at end-of-file so subsequent reads fail. @parts wi

RE: passing arguments to a subroutine to try and match two fields in a text file

2003-01-17 Thread wiggins
See inline. On Fri, 17 Jan 2003 11:01:58 -0500, "Le Blanc, Kerry (Kerry)" <[EMAIL PROTECTED]> wrote: > I think I am getting close. With much help I have been able to tweek my original >code down quite a bit. For the most part, everything is worki

passing arguments to a subroutine to try and match two fields in a text file

2003-01-17 Thread Le Blanc, Kerry (Kerry)
I think I am getting close. With much help I have been able to tweek my original code down quite a bit. For the most part, everything is working as it should. What is stumping me right now is, how do I make sure that both the part number and the rev match before printing out the record. The part

Re: Passing Arguments into a Program

2002-04-12 Thread drieux
On Thursday, April 11, 2002, at 01:53 , Mike wrote: > If a program calls a perl script as follows: /tmp/perltest.pl abc def ghi > jkl mno > > Is there a variable which would contain the arguments? yes @ARGV - in your case you would be able to play something like my $count=1; f

Re: Passing Arguments into a Program

2002-04-12 Thread victor
@ARGV in your example $ARGV[0] will be abc $ARGV[1] will be def ...etc Tor. Mike wrote: > > If a program calls a perl script as follows: /tmp/perltest.pl abc def ghi > jkl mno > > Is there a variable which would contain the arguments? > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > F

Re: Passing Arguments into a Program

2002-04-12 Thread Mandar Rahurkar
@ARGV is the variable ur looking for ; here is how to assign args to vars; while(@ARGV) { $var1=shift(@ARGV); $var2=shift(@ARGV); } Adios Mandar On Thu, 11 Apr 2002, Mike wrote: > If a program calls a perl script as follows: /tmp/perltest.pl abc def ghi > jkl mno > > Is there a va

Passing Arguments into a Program

2002-04-12 Thread Mike
If a program calls a perl script as follows: /tmp/perltest.pl abc def ghi jkl mno Is there a variable which would contain the arguments? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: passing arguments

2001-07-10 Thread Paul
--- "P. Schaub" <[EMAIL PROTECTED]> wrote: > I am calling a perl script within another perl script. Have you looked into require() and do()? > What is the best way to pass arguments to the second one ? Depends on what you want, what it does, and how it's written. > Is it possible to pass arra

Re: passing arguments

2001-07-10 Thread Chas Owens
On 10 Jul 2001 20:24:45 +0200, P. Schaub wrote: > Hi List, > > I am calling a perl script within another perl script. > What is the best way to pass arguments to the second one ? > Is it possible to pass arrays and hashs (or at least refs) ? > So far I am calling the second script like > @result=

passing arguments

2001-07-10 Thread P. Schaub
Hi List, I am calling a perl script within another perl script. What is the best way to pass arguments to the second one ? Is it possible to pass arrays and hashs (or at least refs) ? So far I am calling the second script like @result=`script2.pl $arg1 $arg2 $arg3` but I guess this is quite ugly.

Passing Arguments to Perl Script

2001-07-09 Thread Mike Truong
Hi, How to pass arguments to a (method=post) CGI script and how to access them? Please give an example. Thanks in advance.