Re: naming subroutine reference parameter?

2005-09-07 Thread matija
Jeff Pan wrote:
my (%hash,@array);
sub_test(\%hash,[EMAIL PROTECTED]);

 has special meaning so it should be dropped when not needing
particular special behavior.
 
 
 I can't understand for this,can u give me some examples?

perldoc perlsub
--
NAME(LIST);   # Circumvent prototypes.
NAME; # Makes current @_ visible to called subroutine.

Use  only when you want described side effects.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




naming subroutine reference parameter?

2005-09-06 Thread Jayvee Vibar
How do you name subroutine reference parameter in perl?
Naming a local or pass by value is by simply using my ($param1, $param2) =
@_ ;
How about by reference? I think it would be harder if I'll be using $_[0],
$_[1] direct method.
Is it possible?

Thanks.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: naming subroutine reference parameter?

2005-09-06 Thread Jeff Pan

On Tue, 6 Sep 2005 16:12:35 +0800, Jayvee Vibar [EMAIL PROTECTED]
said:
 How do you name subroutine reference parameter in perl?
 Naming a local or pass by value is by simply using my ($param1, $param2)
 =
 @_ ;
 How about by reference? I think it would be harder if I'll be using
 $_[0],
 $_[1] direct method.
 Is it possible?
 
 Thanks.
 


Passing reference as parameter to subroutine is as easy as the normal
way.And,if u pass some types of parameter such as hash,array,or handle
to subroutine,using reference instead is more safer.
for example,such below code is right:

my (%hash,@array);
sub_test(\%hash,[EMAIL PROTECTED]);

sub sub_test{
my ($hash_ref,$array_ref)[EMAIL PROTECTED];
my %hash=%$hash_ref;
my @[EMAIL PROTECTED];
do something...
}
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - IMAP accessible web-mail


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: naming subroutine reference parameter?

2005-09-06 Thread Dave Gray
On 9/6/05, Jayvee Vibar [EMAIL PROTECTED] wrote:
 How do you name subroutine reference parameter in perl?
 Naming a local or pass by value is by simply using my ($param1, $param2) =
 @_ ;
 How about by reference? I think it would be harder if I'll be using $_[0],
 $_[1] direct method.
 Is it possible?

Those are two separate questions... you can name function parameters like so:

sub myfunc {
my %args = @_;
if ($args{debug}) { print debug!\n; }
# ...
}
myfunc(debug = 1, foo = 'bar');

And you can pass by reference by using, er, references.

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

sub nosoup {
my %args = @_;
if (defined $args{soupline}
  and ref $args{soupline} eq 'HASH') {
if (defined $args{nosoupfor}) {
delete $args{soupline}{$args{nosoupfor}};
}
return $args{soupline};
} else {
  return ();
}
}
my %soupline = (fred=1,dave=2);
print Dumper(\%soupline);
nosoup(soupline = \%soupline, nosoupfor = 'dave');
print Dumper(\%soupline);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: naming subroutine reference parameter?

2005-09-06 Thread Matija Papec
Jeff Pan wrote:

 Passing reference as parameter to subroutine is as easy as the normal
 way.And,if u pass some types of parameter such as hash,array,or handle
 to subroutine,using reference instead is more safer.
 for example,such below code is right:

It is, however it could be better.

 my (%hash,@array);
 sub_test(\%hash,[EMAIL PROTECTED]);

 has special meaning so it should be dropped when not needing
particular special behavior.

 sub sub_test{
 my ($hash_ref,$array_ref)[EMAIL PROTECTED];

ok.

 my %hash=%$hash_ref;
 my @[EMAIL PROTECTED];

This isn't needed actually and it only makes unnecessary overhead as
keys/values are copied, so you immediately lost benefit by passing by
reference.

It's better to access them directly like,
$hash_ref-{key}
$array_ref-[0]

 do something...
 }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: naming subroutine reference parameter?

2005-09-06 Thread Jeff Pan

  my (%hash,@array);
  sub_test(\%hash,[EMAIL PROTECTED]);
 
  has special meaning so it should be dropped when not needing
 particular special behavior.

I can't understand for this,can u give me some examples?


  my %hash=%$hash_ref;
  my @[EMAIL PROTECTED];
 
 This isn't needed actually and it only makes unnecessary overhead as
 keys/values are copied, so you immediately lost benefit by passing by
 reference.
 
 It's better to access them directly like,
 $hash_ref-{key}
 $array_ref-[0]
 
  do something...
  }

This point is great,thank u.
-- 
  Jeff Pan
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - I mean, what is it about a decent email service?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response