RE: subroutine or subroutine

2002-06-07 Thread kevin christopher

Janek: 

Thank you for explaining the difference between calling 
subroutines with vs. without the ampersand.

I'm glad I'm on the beginners list.

Sincerely,

Kevin Christopher


-- Original Message --
From: Camilo Gonzalez [EMAIL PROTECTED]
Date:  Thu, 6 Jun 2002 08:23:33 -0500 

Janek,

Wouldn't it print:
foo:
foo:A B C

Also, I believe that you must declare the subroutine before you 
are allowed
to reference it without the . Am I right about that?

-Original Message-
From: Janek Schleicher [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 5:10 AM
To: [EMAIL PROTECTED]
Subject: Re: subroutine or subroutine


Kevin Christopher wrote at Wed, 05 Jun 2002 04:58:38 +0200:

 Yes, you can call subroutines either way, with or without 
the . The
only case when the
 subroutine must be prefixed with an ampersand is, I believe, 
when you're
assigning a reference
 variable, eg:
 
 $reference_x = \subroutine_y;
 
 But that's another story.
 

Oh, I'm afraid that's not the truth :-)

subroutine without any arguments calls the subroutine with the 
implicit @_
array,
while subroutine only calls subroutine() without any argument.

Look at this snippet:
@_ = qw(A B C);

print 'foo:'; foo; print \n;
print 'foo:'; foo; print \n;

sub foo {
   print @_;
}

It prints:
foo:
foo:ABC


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: subroutine or subroutine

2002-06-06 Thread Camilo Gonzalez

Janek,

Wouldn't it print:
foo:
foo:A B C

Also, I believe that you must declare the subroutine before you are allowed
to reference it without the . Am I right about that?

-Original Message-
From: Janek Schleicher [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 5:10 AM
To: [EMAIL PROTECTED]
Subject: Re: subroutine or subroutine


Kevin Christopher wrote at Wed, 05 Jun 2002 04:58:38 +0200:

 Yes, you can call subroutines either way, with or without the . The
only case when the
 subroutine must be prefixed with an ampersand is, I believe, when you're
assigning a reference
 variable, eg:
 
 $reference_x = \subroutine_y;
 
 But that's another story.
 

Oh, I'm afraid that's not the truth :-)

subroutine without any arguments calls the subroutine with the implicit @_
array,
while subroutine only calls subroutine() without any argument.

Look at this snippet:
@_ = qw(A B C);

print 'foo:'; foo; print \n;
print 'foo:'; foo; print \n;

sub foo {
   print @_;
}

It prints:
foo:
foo:ABC


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: subroutine or subroutine

2002-06-06 Thread Camilo Gonzalez

Bob,

Since this is a list for newbies, can you please be a bit more specific why
you are opposed to those things you list. I'm quite fond of using the foo
or foo(args) calling styles. Is this just a personal preference?

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 8:30 AM
To: 'Octavian Rasnita'; [EMAIL PROTECTED]
Subject: RE: subroutine or subroutine


 -Original Message-
 From: Octavian Rasnita [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, June 04, 2002 2:06 PM
 To: [EMAIL PROTECTED]
 Subject: subroutine or subroutine
 
 
 Hi all,
 
 I've seen some subroutines are ran without the  sign in front of the
 subroutine name, like:
 
 subroutine_name;
 instead of
 subroutine_name;
 
 Is it the same thing or there is a difference?

Janek gave you the difference, and it's fully documented in perldoc perlsub.

Note that the first is not allowed under use strict unless the sub has
been declared or defined above the usage, or imported.

Here are my recommendations for new code (others may want to debate these):

1. Always use strict;

2. Don't use prototypes.

3. Don't use the foo or foo(args) calling styles.

4. To call a sub with no arguments, use an empty set of
   parens: foo() (Exception: method calls can leave
   off the parens, e.g: $sth-execute; since there is
   no ambiguity with a method call).

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: subroutine or subroutine

2002-06-06 Thread Joel Hughes

No, the subroutinue body can occur before or after the invokation point with
or without the .

joel

-Original Message-
From: Camilo Gonzalez [mailto:[EMAIL PROTECTED]]
Sent: 06 June 2002 14:24
To: 'Janek Schleicher'; [EMAIL PROTECTED]
Subject: RE: subroutine or subroutine


Janek,

Wouldn't it print:
foo:
foo:A B C

Also, I believe that you must declare the subroutine before you are allowed
to reference it without the . Am I right about that?

-Original Message-
From: Janek Schleicher [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 5:10 AM
To: [EMAIL PROTECTED]
Subject: Re: subroutine or subroutine


Kevin Christopher wrote at Wed, 05 Jun 2002 04:58:38 +0200:

 Yes, you can call subroutines either way, with or without the . The
only case when the
 subroutine must be prefixed with an ampersand is, I believe, when you're
assigning a reference
 variable, eg:

 $reference_x = \subroutine_y;

 But that's another story.


Oh, I'm afraid that's not the truth :-)

subroutine without any arguments calls the subroutine with the implicit @_
array,
while subroutine only calls subroutine() without any argument.

Look at this snippet:
@_ = qw(A B C);

print 'foo:'; foo; print \n;
print 'foo:'; foo; print \n;

sub foo {
   print @_;
}

It prints:
foo:
foo:ABC


Greetings,
Janek

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Fwd: notBob clarifies the Bob was Re: subroutine or subroutine

2002-06-06 Thread drieux



Begin forwarded message:

 From: drieux [EMAIL PROTECTED]
 Date: Thu Jun 06, 2002  07:38:29  US/Pacific
 To: begin begin [EMAIL PROTECTED]
 Subject: notBob clarifies the Bob was Re: subroutine or subroutine


 On Thursday, June 6, 2002, at 06:31 , Camilo Gonzalez wrote:
 [..]
 Since this is a list for newbies, can you please be a bit more specific 
 why
 you are opposed to those things you list. I'm quite fond of using the 
 foo
 or foo(args) calling styles. Is this just a personal preference?

 [..]
 Bob Said:
 Here are my recommendations for new code (others may want to debate 
 these)
 :

 1. Always use strict;

 2. Don't use prototypes.

 3. Don't use the foo or foo(args) calling styles.

 4. To call a sub with no arguments, use an empty set of
parens: foo() (Exception: method calls can leave
off the parens, e.g: $sth-execute; since there is
no ambiguity with a method call).

 notBob says:

   1) the 'use strict' pragma helps pop out things
   like wacko ref cases as well as making sure
   that you do not have any wacko sub situations
   and will WHINE at you at compile time This
   while ANNOYING at compile time helps impose good habits,
   probably faster than making you stand at the chaulk board
   writing

   I will not write bad code x 1_000_000_000

   to impress upon the impressionable that good form is elegant.

   2) the 'prototype' approach gets harry and messy when you
   start certain types of software development - it was an
   interesting idea - but as you will note in the 3rd edition
   of programming perl it is not recommended.

   { Nikola probably has sanity issues that he is resolving
   with prototyping - but then again, most of us are all
   sublimating one or more issues in perl... }

   May I recommend Miss Happy's House of Dominitrix Delights
   if you have unresolved bondage needs as a simpler and more
   direct solution to prototyping perl functions.

   { I think 'use subs qw//;' is not as cool as it was either. }

   /* do not let me prevent you from learning the hard way. */

   3) the foo and foo(@arglist) models are 'old perl' - and it
   was so much nicer once we were allowed to go with

   foo();

   so that the 'oldGuys' felt more at home that this was
   a 'function' that was called with no args... Nothing like
   that annoying typo HELL of

   if ( $wombat  foo(@arglist) )

   which you had intended to have been the foo() bitwise
   added with $wombat - but got the logical anded. OYE!
   You find that one at Oh-Dark-Squat without a Whole Lot of
   Mountain Dew and.

 { hey crayon heads - did your colour coded perl IDE help in this case? }


 In short these are recommendations based upon life experience,
 our life, our experience - you are free to go with the flow or
 not - but if you see me 'weaving down the road' while walking,
 just accept the fact that I do that to make it harder on the
 amatuer snipers. If you see me running, all you need to
 do is be in front of me.

ciao
drieux

---



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: subroutine or subroutine

2002-06-06 Thread Janek Schleicher

Bob Showalter wrote at Wed, 05 Jun 2002 15:30:29 +0200:

 
 3. Don't use the foo or foo(args) calling styles.
 

Allthough I would miss it a little bit.
I find the foo style useful when implementing a little polymorphic subroutine.

Example:

sub foo {
  /NUMERIC/   _foo_numeric
  or  /WORD/  _foo_word
  or  otherwise _foo_crazy;
}

sub _foo_numeric {
  print Numbers: @_\n;
}

sub _foo_word {
  print Words: @_\n;
}

sub _foo_crazy {
  print Crazy: @_\n;
}

foo(NUMERIC = (4,5,6));
foo(WORD= (x,y,z));
foo(BIGJ  = (the greatest));

It's more practical than writing
_foo_numeric( @_ )
_foo_word   ( @_ )
_foo_crazy  ( @_ )
in the switch case. (In addition I reduce the redundances).

Allthough, there are better (and slower :-( ) 
ways to implement polymorphic in a real OO-style,
I often use the upper behaviour in CGI scripts.

Cheerio,
Janek

PS: I hope that won't become a religious dibute of using foo - style vs foo() style.
All I wanted was to declare that there are some really useful reasons for the foo 
style.
I want to underline Bob in saying: Don't use the foo style without special reason.
Especially don't use it mixed with the foo() style.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: subroutine or subroutine

2002-06-05 Thread kevin christopher

Yes, you can call subroutines either way, with or without the .
The only case when the subroutine must be prefixed with an
ampersand is, I believe, when you're assigning a reference
variable, eg:

$reference_x = \subroutine_y;

But that's another story.

Kevin


-- Original Message --
From: Octavian Rasnita [EMAIL PROTECTED]
Date:  Tue, 4 Jun 2002 21:06:19 +0300

Hi all,

I've seen some subroutines are ran without the  sign in front of the
subroutine name, like:

subroutine_name;
instead of
subroutine_name;

Is it the same thing or there is a difference?

Thank you.


Teddy,
[EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: subroutine or subroutine

2002-06-05 Thread Janek Schleicher

Kevin Christopher wrote at Wed, 05 Jun 2002 04:58:38 +0200:

 Yes, you can call subroutines either way, with or without the . The only case 
when the
 subroutine must be prefixed with an ampersand is, I believe, when you're assigning a 
reference
 variable, eg:
 
 $reference_x = \subroutine_y;
 
 But that's another story.
 

Oh, I'm afraid that's not the truth :-)

subroutine without any arguments calls the subroutine with the implicit @_ array,
while subroutine only calls subroutine() without any argument.

Look at this snippet:
@_ = qw(A B C);

print 'foo:'; foo; print \n;
print 'foo:'; foo; print \n;

sub foo {
   print @_;
}

It prints:
foo:
foo:ABC


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: subroutine or subroutine

2002-06-05 Thread Bob Showalter

 -Original Message-
 From: Octavian Rasnita [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, June 04, 2002 2:06 PM
 To: [EMAIL PROTECTED]
 Subject: subroutine or subroutine
 
 
 Hi all,
 
 I've seen some subroutines are ran without the  sign in front of the
 subroutine name, like:
 
 subroutine_name;
 instead of
 subroutine_name;
 
 Is it the same thing or there is a difference?

Janek gave you the difference, and it's fully documented in perldoc perlsub.

Note that the first is not allowed under use strict unless the sub has
been declared or defined above the usage, or imported.

Here are my recommendations for new code (others may want to debate these):

1. Always use strict;

2. Don't use prototypes.

3. Don't use the foo or foo(args) calling styles.

4. To call a sub with no arguments, use an empty set of
   parens: foo() (Exception: method calls can leave
   off the parens, e.g: $sth-execute; since there is
   no ambiguity with a method call).

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: subroutine or subroutine

2002-06-05 Thread Nikola Janceski

I'd suggest using prototypes if you are going to be passing more than
3 variable references, or 3 or more different types of varible references.
This is for your own sanity.

 -Original Message-
 From: Bob Showalter [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 05, 2002 9:30 AM
 To: 'Octavian Rasnita'; [EMAIL PROTECTED]
 Subject: RE: subroutine or subroutine
 
 Here are my recommendations for new code (others may want to 
 debate these):
 
 1. Always use strict;
 
 2. Don't use prototypes.
 
 3. Don't use the foo or foo(args) calling styles.
 
 4. To call a sub with no arguments, use an empty set of
parens: foo() (Exception: method calls can leave
off the parens, e.g: $sth-execute; since there is
no ambiguity with a method call).
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]