Re: Subroutine return value

2025-05-14 Thread Jim Gibson via beginners
Put this line as the last line executed in your subroutine: return $sum; That makes it explicit as to what you want the subroutine to do. Don’t depend upon some obscure behavior of Perl to save a few keystrokes. Your program will be better for it. > On May 14, 2025, at 4:15

Subroutine return value

2025-05-14 Thread Daryl Lee
In “Learning Perl”, Pg. 116, is found this sentence: Whatever calculation is last performed in a subroutine is automatically also the return value. I have a subroutine that (almost) ends with this loop: foreach my $line (@lines) { $sum += evaluate($line); } What I want to return

Re: Perl Critic and subroutine signatures

2017-03-29 Thread SSC_perl
> On Mar 29, 2017, at 3:47 PM, Kevin Phair wrote: > > Something like > > [-Subroutines::ProhibitSubroutinePrototypes] Thanks. I ran across that myself on perlmaven.com right before I went to lunch. I was hoping to find a page on CPAN or even the Perl Critic web site that would list

Re: Perl Critic and subroutine signatures

2017-03-29 Thread Kevin Phair
: > Does anyone know how to keep Perl Critic from complaining about subroutine > signatures? I’m getting a massive amount of these types of warnings: > > Subroutine prototypes used at line... > > It also thinks that postfix dereferencing is a magic variable. Is this > because P

Re: Perl Critic and subroutine signatures

2017-03-29 Thread Uri Guttman
On 03/29/2017 01:32 PM, SSC_perl wrote: On Mar 29, 2017, at 10:19 AM, Uri Guttman <mailto:u...@stemsystems.com>> wrote: i would ask why are you using prototypes? I’m not using prototypes. I’m using subroutine signatures. Perl Critic only thinks they are prototypes. ok, i just

Re: Perl Critic and subroutine signatures

2017-03-29 Thread SSC_perl
> On Mar 29, 2017, at 10:19 AM, Uri Guttman wrote: > > i would ask why are you using prototypes? I’m not using prototypes. I’m using subroutine signatures. Perl Critic only thinks they are prototypes.

Re: Perl Critic and subroutine signatures

2017-03-29 Thread Uri Guttman
On 03/29/2017 01:16 PM, SSC_perl wrote: Does anyone know how to keep Perl Critic from complaining about subroutine signatures? I’m getting a massive amount of these types of warnings: Subroutine prototypes used at line... i would ask why are you using prototypes? they are rarely useful

Perl Critic and subroutine signatures

2017-03-29 Thread SSC_perl
Does anyone know how to keep Perl Critic from complaining about subroutine signatures? I’m getting a massive amount of these types of warnings: Subroutine prototypes used at line... It also thinks that postfix dereferencing is a magic variable. Is this because PC hasn’t been

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-02-25 Thread khalil zakaria Zemmoura
Naming multiple variables with the same name like you did ($args, %args) is a bad idea. because when you want to access the value of the hash %args ($args{FN}) you are accessing in reality what was shifted in the scalar $args and not the hash %args because perl use simbolic reference. here is a li

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-02-25 Thread ZEMMOURA Khalil Zakaria
On Sun, Jan 15, 2017 at 12:45:41PM -0800, al...@myfastmail.com wrote: > Hi > > On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote: > > I think, you can use this aproach > > If I use either of those > > > sub modrec { > - my %args = %{ shift @_ }; > +

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread Chas. Owens
On Sun, Jan 15, 2017, 16:19 wrote: Hi, On Sun, Jan 15, 2017, at 01:01 PM, Shawn H Corey wrote: > > Is there a different, recommended way? > > Nothing's wrong. perlcritic does not this valid method, that's all. > > TIMTOWTDI (There Is More Than One Way To Do It.) Hm, ok. As long as it's not wro

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread Rob Dixon
Hi Alan You are unpacking `@_` in a way, but perlcritic doesn't recognise doing it this way. I think you'd be better off without dereferencing the hash, and using a slice to assign your local variables. I would write your subroutine like this sub modrec {

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread alanj
Hi, On Sun, Jan 15, 2017, at 01:01 PM, Shawn H Corey wrote: > > Is there a different, recommended way? > > Nothing's wrong. perlcritic does not this valid method, that's all. > > TIMTOWTDI (There Is More Than One Way To Do It.) Hm, ok. As long as it's not wrong/broken in some weird way. I kep

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread Shawn H Corey
On Sun, 15 Jan 2017 12:09:53 -0800 al...@myfastmail.com wrote: > What's wrong with the way I'm unpacking the arguments passed to the > subroutine, > > my %args = %{ shift @_ }; > > Is there a different, recommended way? Nothing's wrong. perlcritic does

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread Илья Рассадин
Hi! You forgot arrow operator $args->{'FN'}, not $args{'FN'} 15.01.17 23:45, al...@myfastmail.com пишет: Hi On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote: I think, you can use this aproach If I use either of those sub modrec { - my %args = %{ shift

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread alanj
Hi On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote: > I think, you can use this aproach If I use either of those sub modrec { - my %args = %{ shift @_ }; + my ($args) = @_; 30 my $fn = $args{FN};

Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread Илья Рассадин
Hi! I think, you can use this aproach sub modrec { my ($args) = @_; # or my $args = shift @_; use what you like more my $fn = $args->{'FN'}; } 15.01.17 23:09, al...@myfastmail.com пишет: Hi, I have a simple script with a subroutine that I pass scalar &

script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread alanj
Hi, I have a simple script with a subroutine that I pass scalar & array arguments to, #!/usr/bin/perl use 5.01201; use strict; use warnings; my $this_fn = "input.txt"; my @this_dr = qw( /path/1 /path/2

Re: close dbh in the subroutine

2014-05-08 Thread David Precious
On Thu, 08 May 2014 16:54:32 +0400 Jeff Pang wrote: > Hi, > > I created a $dbh object in the main body, and pass it to a > subroutine, then close the $dbh in the subroutine, does it  influence > the $dbh in the main? Yes. It's a reference to the same DBI object. -- To

close dbh in the subroutine

2014-05-08 Thread Jeff Pang
Hi, I created a $dbh object in the main body, and pass it to a subroutine, then close the $dbh in the subroutine, does it  influence the $dbh in the main? $dbh = DBI->connect($data_source, $username, $auth, \%attr); my_func($dbh); $dbh->do(something); # will this broke? sub my_func {

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Karol Bujaček
my @animals = @$animals; # dereference my @digits = @$digits; # dereference The comment is inaccurate. Why would you want to copy the arrays? Because I don't want to change an array by my subroutine, as Shawn H Corey answered already. Well, this may or may not be eventual's intentio

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Shawn H Corey
On Sat, 07 Sep 2013 14:15:39 +0200 "Dr.Ruud" wrote: > On 07/09/2013 13:43, Karol Bujaček wrote: > > >print Dumper(@_);# just look how the @_ looks like > > Consider: print Dumper( \@_ ); > > > >my($animals, $digits) = @_; > > > >my @animals = @$animals; # dereference > >

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Dr.Ruud
On 07/09/2013 13:43, Karol Bujaček wrote: print Dumper(@_);# just look how the @_ looks like Consider: print Dumper( \@_ ); my($animals, $digits) = @_; my @animals = @$animals; # dereference my @digits = @$digits; # dereference The comment is inaccurate. Why would

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Karol Bujaček
On 09/07/2013 01:11 PM, eventual wrote: Hi, In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets and @digits = @numbers. Thanks my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); &study (@pets

Re: How do I pass arrays into a subroutine

2013-09-07 Thread *Shaji Kalidasan*
ot; Sent: Saturday, 7 September 2013 4:41 PM Subject: How do I pass arrays into a subroutine Hi,   In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets  and @digits = @numbers. Thanks   my @pets = ('dogs' , 'cats' , 'h

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Shlomi Fish
Hi Eventual, On Sat, 7 Sep 2013 04:11:06 -0700 (PDT) eventual wrote: > Hi, >   > In the example below, how do I pass @pets and @numbers into the subroutine so > that @animals = @pets  and > @digits = @numbers. Please look into references and pass the arrays as references. Se

How do I pass arrays into a subroutine

2013-09-07 Thread eventual
Hi,   In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets  and @digits = @numbers. Thanks   my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10);   &study (@pets , @numbers);   sub study {   my (

Re: subroutine

2012-08-17 Thread Chris Stinemetz
> In the above line, `shift` will return just the first element from the > @_ array. $y will therefore be undefined. The line should be rewritten > as: > my ( $x, $y ) = @_; > Thank you. I should have caught that. Chris

Re: subroutine

2012-08-17 Thread Alan Haggai Alavi
Hello Chris, > Can this subroutine be better written? > I am getting the following erros: > > Use of uninitialized value $y in subtraction (-) at form.pl line 52. > Use of uninitialized value $y in addition (+) at form.pl line 52. > > sub avg_az { > my($x, $y) = shift

subroutine

2012-08-17 Thread Chris Stinemetz
Hello List, Can this subroutine be better written? I am getting the following erros: Use of uninitialized value $y in subtraction (-) at form.pl line 52. Use of uninitialized value $y in addition (+) at form.pl line 52. sub avg_az { my($x, $y) = shift(@_); return abs($x-$y)<180 ? ($x+$y

Re: subroutine in seperate file, question

2012-08-11 Thread Rob Dixon
On 11/08/2012 12:43, Shawn H Corey wrote: No, @ISA is used only by Exporter.pm Exporter makes no use of @ISA at all. This array is a per-package variable used by Perl internally to implement object-oriented inheritance. It is very often used to make a package a subclass of Exporter, but that i

Re: subroutine in seperate file, question

2012-08-11 Thread Rajeev Prasad
Thank you. I am confused about how to send variables to this ext.pl and get values (scalars) back into main.pl another confusion is from web the cgi will run, i want to check cookies in external subroutine file and redirect to some website based on some condition, or gives some values back to

Re: subroutine in seperate file, question

2012-08-11 Thread Shawn H Corey
On Sat, 11 Aug 2012 02:49:56 -0400 shawn wilson wrote: > On Aug 10, 2012 11:41 PM, wrote: > > > > > I mean to ask, wether they will clash with the same loaded modules > loaded > > > in calling script? > > > > > > > No. they are loaded only once. > > > > Well, they will both be in ISA to look up

Re: subroutine in seperate file, question

2012-08-10 Thread shawn wilson
On Aug 10, 2012 11:41 PM, wrote: > > > I mean to ask, wether they will clash with the same loaded modules loaded > > in calling script? > > > > No. they are loaded only once. > Well, they will both be in ISA to look up separately but there is no conflict.

Re: subroutine in seperate file, question

2012-08-10 Thread pangj
> I mean to ask, wether they will clash with the same loaded modules loaded > in calling script? > No. they are loaded only once. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: subroutine in seperate file, question

2012-08-10 Thread Rajeev Prasad
I mean to ask, wether they will clash with the same loaded modules loaded in calling script? From: "pa...@riseup.net" To: Rajeev Prasad Cc: perl list Sent: Friday, August 10, 2012 9:05 PM Subject: Re: subroutine in seperate file, question Yes, t

Re: subroutine in seperate file, question

2012-08-10 Thread pangj
Yes, the modules in required file will be loaded. $ cat ext.pl use CGI; use DBI; 1; $ cat main.pl require 'ext.pl'; use Data::Dumper; print Dumper \%INC; Thus run perl main.pl to see what prints. > i want to keep a peice of code which uses CGI and DBIx module in a > seperate file, and want t

subroutine in seperate file, question

2012-08-10 Thread Rajeev Prasad
i want to keep a peice of code which uses CGI and DBIx module in a seperate file, and want to include it in all my scripts as follows:   require "/path/to/script/file";   I am not sure if the calling program is also using same modules CGI and DBIx what kind of unknown errors i might get? anyone k

Re: array ref as subroutine parameter

2012-07-12 Thread timothy adigun
Hi Chris, On Fri, Jul 13, 2012 at 3:28 AM, Shawn H Corey wrote: > On 12-07-12 10:25 PM, Chris Stinemetz wrote: > >> I have an anonymous array below and would like to know how to pass the >> first element to a subroutine as a parameter. >> >> push @data, [$srt,$

Re: array ref as subroutine parameter

2012-07-12 Thread Shawn H Corey
On 12-07-12 10:25 PM, Chris Stinemetz wrote: I have an anonymous array below and would like to know how to pass the first element to a subroutine as a parameter. push @data, [$srt,$srfc,$cfc,$cfcq,$cell,$icell,$isector,$sector]; call to subroutine: session_attempts($srt); Thank you in

array ref as subroutine parameter

2012-07-12 Thread Chris Stinemetz
I have an anonymous array below and would like to know how to pass the first element to a subroutine as a parameter. push @data, [$srt,$srfc,$cfc,$cfcq,$cell,$icell,$isector,$sector]; call to subroutine: session_attempts($srt); Thank you in advance, Chris

Re: subroutine returning data

2012-06-10 Thread Shlomi Fish
Hi all, On Tue, 05 Jun 2012 10:15:36 -0700 "John W. Krahn" wrote: > [ Please do not top-post your replies. Please remove non-relevant text > from your reply before posting. TIA ] > > don't insult and dismiss out of hand the findings of those who take the > > time to help you. > > If I insul

Re: Unfamiliar calling of a subroutine

2012-06-08 Thread sono-io
On Jun 7, 2012, at 10:19 PM, Brock wrote: > Finally to your last question, how is this different than just calling the > package::sub directly? With a method call the instance variable, in this case > $catalog, always gets passed as the first parameter to the method. Usually > people name it $s

Re: Unfamiliar calling of a subroutine

2012-06-07 Thread Brock
On 2012.06.07.20.21, sono...@fannullone.us wrote: > Would someone be so kind as to explain the following, or at least point > me to further reading? > > $item = > $main::global->{open}->{catalog}->SurfDB::split_line($main::global->{form}->{'itemid'}); > > The part I'm having trouble

Re: Unfamiliar calling of a subroutine

2012-06-07 Thread pangj
Would someone be so kind as to explain the following, or at least point me to further reading? $item = $main::global->{open}->{catalog}->SurfDB::split_line($main::global->{form}->{'itemid'}); That's Perl OO programming. You may want to read this book: http://shop.oreilly.com/produc

Unfamiliar calling of a subroutine

2012-06-07 Thread sono-io
Would someone be so kind as to explain the following, or at least point me to further reading? $item = $main::global->{open}->{catalog}->SurfDB::split_line($main::global->{form}->{'itemid'}); The part I'm having trouble understanding is "$main::global->{open}->{catalog}->". Wh

Re: subroutine returning data

2012-06-05 Thread John W. Krahn
[ Please do not top-post your replies. Please remove non-relevant text from your reply before posting. TIA ] Jack Maney wrote: ProTip: The top two results from Google state: PROTIP | Know Your Meme About PROTIP is a term often used in forums and comments to preface snarky, obvious, count

List behavior pro tips (was: Re: subroutine returning data)

2012-06-05 Thread John SJ Anderson
:08 AM, Jack Maney wrote: > ProTip: If you're going to ask for help, don't insult and dismiss out of hand > the findings of those who take the time to help you. > > -Original Message- > From: John W. Krahn [mailto:jwkr...@shaw.ca] > Sent: Tuesday, June 05, 201

RE: subroutine returning data

2012-06-05 Thread Jack Maney
ProTip: If you're going to ask for help, don't insult and dismiss out of hand the findings of those who take the time to help you. -Original Message- From: John W. Krahn [mailto:jwkr...@shaw.ca] Sent: Tuesday, June 05, 2012 2:18 AM To: Perl Beginners Subject: Re: subroutine

Re: subroutine returning data

2012-06-05 Thread John W. Krahn
Shlomi Fish wrote: On Mon, 04 Jun 2012 14:19:27 -0700 "John W. Krahn" wrote: Chris Stinemetz wrote: I have a subroutine that I want to "return 1" only if the value of %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. One way to do it: sub

Re: subroutine returning data

2012-06-04 Thread Shlomi Fish
Hello John, On Mon, 04 Jun 2012 14:19:27 -0700 "John W. Krahn" wrote: > Chris Stinemetz wrote: > > I have a subroutine that I want to "return 1" only if the value of > > %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences

Re: subroutine returning data

2012-06-04 Thread John W. Krahn
Chris Stinemetz wrote: I have a subroutine that I want to "return 1" only if the value of %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. One way to do it: sub site_offAir { return values %{ $href->{ $_[ 0 ] } } == grep( $_ eq 'ND', v

Re: subroutine returning data

2012-06-04 Thread Chris Stinemetz
Thank you everyone. Your help has been very helpful.. Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: subroutine returning data

2012-06-04 Thread Shawn H Corey
On 12-06-04 02:01 PM, Bill Stephenson wrote: The "values %{$href->{$_[0]}}" code is pretty ugly but I get it now. And it make sense to break out of the loop as soon as you don't pass the test. sub site_offAir { my $site_id = shift @_; for my $activity_code ( values %{ $activity_of->{$sit

Re: subroutine returning data

2012-06-04 Thread Bill Stephenson
0 PM, Chris Stinemetz wrote: >> I have a subroutine that I want to "return 1" only if the value of >> %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. >> >> Any suggestions is greatly appreciated. >> >> Thank you, >> >

Re: subroutine returning data

2012-06-04 Thread Shawn H Corey
On 12-06-04 12:30 PM, Chris Stinemetz wrote: I have a subroutine that I want to "return 1" only if the value of %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. Any suggestions is greatly appreciated. Thank you, Chris sub site_offAir { for

Re: subroutine returning data

2012-06-04 Thread Bill Stephenson
On Jun 4, 2012, at 11:30 AM, Chris Stinemetz wrote: > I have a subroutine that I want to "return 1" only if the value of > %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. > > Any suggestions is greatly appreciated. > Chris, I don't k

Re: subroutine returning data

2012-06-04 Thread Paul Johnson
On Mon, Jun 04, 2012 at 11:30:30AM -0500, Chris Stinemetz wrote: > I have a subroutine that I want to "return 1" only if the value of > %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. > > Any suggestions is greatly appreciated. > > T

subroutine returning data

2012-06-04 Thread Chris Stinemetz
I have a subroutine that I want to "return 1" only if the value of %{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences. Any suggestions is greatly appreciated. Thank you, Chris sub site_offAir { for (values %{$href->{$_[0]}}) { return 1 if $_ eq 

Re: & and subroutine

2012-04-19 Thread Paul.G
Thanks for everyone's assistance, I think I have my answer. I will be looking closer at the comments. cheers From: Michael Rasmussen To: beginners@perl.org Sent: Tuesday, 17 April 2012 11:01 PM Subject: Re: & and subroutine And for what it

Re: & and subroutine

2012-04-17 Thread Uri Guttman
ng a subroutine, or it is not required, or it doesn't matter? It's good practice not to use it unless you understand exactly why you would need to use it. Could someone please expand on this as I seem to always have to do this. If I 'use strict' and 'use warnings' I get

Re: & and subroutine

2012-04-17 Thread Uri Guttman
On 04/17/2012 07:03 AM, 'lesleyb' wrote: On Mon, Apr 16, 2012 at 04:20:35PM +0200, Paul Johnson wrote: On Mon, Apr 16, 2012 at 06:53:53AM -0700, Paul.G wrote: Hi All Have a question, is it good coding practice to use a& when calling a subroutine, or it is not required, or it

Re: & and subroutine

2012-04-17 Thread Ken Slater
> >> Perl tells you that it has no idea what you mean when you use the >> bareword mysub. >> >> >> Now you have two options to solve it. >> >> 1. &mysub; >> >> Using the sigil & you tell Perl that mysub is a subroutine. >> >> 2

Re: & and subroutine

2012-04-17 Thread Gary Stainburn
On Tuesday 17 April 2012 15:13:40 Manfred Lotz wrote: > You have > sub mysub() { > > instead of > > sub mysub { > > which is the correct way. Thank you. I can't believe how many years I've been getting that one wrong. Gary -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional

Re: & and subroutine

2012-04-17 Thread Manfred Lotz
lation errors. > > > > > > Perl tells you that it has no idea what you mean when you use the > > bareword mysub. > > > > > > Now you have two options to solve it. > > > > 1. &mysub; > > > > Using the sigil & you tell Perl that

Re: & and subroutine

2012-04-17 Thread Gary Stainburn
t;mysub" not allowed while "strict subs" in use at ./testsub.pl > line 6. Execution of ./testsub.pl aborted due to compilation errors. > > > Perl tells you that it has no idea what you mean when you use the > bareword mysub. > > > Now you have two options to

Re: & and subroutine

2012-04-17 Thread Michael Rasmussen
And for what it's worth. 113. Call subroutines with parentheses but without a leading & That's from Damian Conway's Perl Best Practices A quick reference to the 256 guidelines is found at http://refcards.com/docs/vromansj/perl-best-practices/refguide.pdf And a bit of luck, the entire chapter on s

Re: & and subroutine

2012-04-17 Thread Michael Rasmussen
On Tue, Apr 17, 2012 at 02:30:59PM +0200, Manfred Lotz wrote: > > Could someone please expand on this as I seem to always have to do > > this. If I 'use strict' and 'use warnings' I get errors if I don't. > > > > One example is this: > > #! /usr/bin/perl > > use strict; > use warnings; > > mys

Re: & and subroutine

2012-04-17 Thread Shawn H Corey
Have a question, is it good coding practice to use a& when > > > calling a subroutine, or it is not required, or it doesn't matter? > > > > It's good practice not to use it unless you understand exactly why > > you would need to use it. > > Co

Re: & and subroutine

2012-04-17 Thread Manfred Lotz
On Tue, 17 Apr 2012 12:27:32 +0100 Gary Stainburn wrote: > On Monday 16 April 2012 15:20:35 Paul Johnson wrote: > > On Mon, Apr 16, 2012 at 06:53:53AM -0700, Paul.G wrote: > > > Hi All > > > > > > Have a question, is it good coding practice to use a & w

Re: & and subroutine

2012-04-17 Thread Gary Stainburn
On Monday 16 April 2012 15:20:35 Paul Johnson wrote: > On Mon, Apr 16, 2012 at 06:53:53AM -0700, Paul.G wrote: > > Hi All > > > > Have a question, is it good coding practice to use a & when calling a > > subroutine, or it is not required, or it doesn't matter?

Re: & and subroutine

2012-04-17 Thread 'lesleyb'
On Mon, Apr 16, 2012 at 04:20:35PM +0200, Paul Johnson wrote: > On Mon, Apr 16, 2012 at 06:53:53AM -0700, Paul.G wrote: > > Hi All > > > > Have a question, is it good coding practice to use a & when calling a > > subroutine, or it is not required, or it doesn&#x

Re: & and subroutine

2012-04-16 Thread Paul Johnson
On Mon, Apr 16, 2012 at 06:53:53AM -0700, Paul.G wrote: > Hi All > > Have a question, is it good coding practice to use a & when calling a > subroutine, or it is not required, or it doesn't matter? It's good practice not to use it unless you understand exactly wh

& and subroutine

2012-04-16 Thread Paul.G
Hi All Have a question, is it good coding practice to use a & when calling a subroutine, or it is not required, or it doesn't matter? eg: sub name { some code here, returning a single value return 0; } &name(); cheers

Re: subroutine call

2011-12-05 Thread Shlomi Fish
Hi Ganesh, On Mon, 5 Dec 2011 14:16:29 +0530 ganesh vignesh wrote: > stop mail to me The instructions at the bottom of every E-mail read: [QUOTE] To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ [/QUOTE] Ple

Re: subroutine call

2011-12-05 Thread Shlomi Fish
Hello, John. On Sun, 04 Dec 2011 12:46:40 -0800 "John W. Krahn" wrote: > > You should assign $marketInfo{$mkt} to a variable, or alternatively do: > > > > my ($start, $end) = @{$marketInfo{$mkt}}{qw(start end)}; > > > >> my $end = $marketInfo{$mkt}->{"end"}; > >> if( $cell>=

Re: subroutine call

2011-12-04 Thread John W. Krahn
subroutine call is made I get the following compilation error: Global symbol "$cell" requires explicit package name at ./evdo.pl line 279. Global symbol "$cell" requires explicit package name at ./evdo.pl line 279. I understand lexical scope, but am having a hard time figuring

Re: subroutine call

2011-12-04 Thread Dr.Ruud
On 2011-12-04 18:12, Shlomi Fish wrote: Chris wrote: my $cell = substr($market,0,index($market,"_")); print "$_ <", substr( $_, 0, index $_, "_" ), ">\n" for qw/ foo1 foo2_bar foo3_bar_baz /; foo1 foo2_bar foo3_bar_baz This can be more idiomatically (and more briefly) done us

Re: subroutine call

2011-12-04 Thread Shlomi Fish
ow when this subroutine call is made I get the following compilation error: > > Global symbol "$cell" requires explicit package name at ./evdo.pl line 279. > Global symbol "$cell" requires explicit package name at ./evdo.pl line 279. > > I understand lexical scope

Re: subroutine call

2011-12-04 Thread Uri Guttman
On 12/04/2011 08:40 AM, Chris Stinemetz wrote: I have a program that I am working on improveing. The fist step I have taken is converting it in using the strict pragma. Now when this subroutine call is made I get the following compilation error: Global symbol "$cell" requires explic

subroutine call

2011-12-04 Thread Chris Stinemetz
I have a program that I am working on improveing. The fist step I have taken is converting it in using the strict pragma. Now when this subroutine call is made I get the following compilation error: Global symbol "$cell" requires explicit package name at ./evdo.pl line 279. Global sym

Re: timings of perl subroutine with a program

2011-11-07 Thread a b
Thanks a ton!! Hats off to you for encouragement On Fri, Nov 4, 2011 at 5:05 PM, Shlomi Fish wrote: > Hi "a b", > > On Fri, 4 Nov 2011 15:18:00 +0530 > a b wrote: > > > apologize!! > > > > Can you help me to understand how async I/O can help me > > > > What's wrong with the resources in the UR

Re: timings of perl subroutine with a program

2011-11-04 Thread Shlomi Fish
Hi "a b", On Fri, 4 Nov 2011 15:18:00 +0530 a b wrote: > apologize!! > > Can you help me to understand how async I/O can help me > What's wrong with the resources in the URL I pointed you to? There's also http://en.wikipedia.org/wiki/Asynchronous_I/O which may be of interest. "The Gods help

Re: timings of perl subroutine with a program

2011-11-04 Thread a b
apologize!! Can you help me to understand how async I/O can help me Regards a b On Thu, Nov 3, 2011 at 9:06 PM, Shlomi Fish wrote: > Hello a b, > > please reply to the list as I specifically request in my signature. > (Wretched > gmail.com.) I'm CCing the list. > > On Thu, 3 Nov 2011 16:15:11

Re: timings of perl subroutine with a program

2011-11-03 Thread Shlomi Fish
Hello a b, please reply to the list as I specifically request in my signature. (Wretched gmail.com.) I'm CCing the list. On Thu, 3 Nov 2011 16:15:11 +0530 a b wrote: > Thanks Shlomi!! > > I am not sure about async I/O? > > any pointers about this one. It is new to me so far > See the links

Re: timings of perl subroutine with a program

2011-11-03 Thread Shlomi Fish
On Thu, 3 Nov 2011 06:49:36 +0100 timothy adigun <2teezp...@gmail.com> wrote: > Hi a b, > > a b wrote: > > > Hi all, > > > > i need to track down how much time each function is taking and anlyze if > > threads can help > > > > do we have any such function?? > > > > **You can use ** use Benchma

Re: timings of perl subroutine with a program

2011-11-02 Thread timothy adigun
Hi a b, a b wrote: > Hi all, > > i need to track down how much time each function is taking and anlyze if > threads can help > > do we have any such function?? > **You can use ** use Benchmark qw(:all) **. >From your CLI you can do: perldoc benchmark, or if you not like reading from the command

timings of perl subroutine with a program

2011-11-02 Thread a b
Hi all, i need to track down how much time each function is taking and anlyze if threads can help do we have any such function??

Re: Exit subroutine on filehandle error

2011-07-29 Thread Paul Johnson
On Fri, Jul 29, 2011 at 04:05:26PM +0200, Dr.Ruud wrote: > On 2011-07-28 00:45, C.DeRykus wrote: > > > open( ... ) or warn "..." and return; > > Here you are assuming that warn always returns true. It actually > does, even if the device that it write to is full, but I don't think > that is

Re: Exit subroutine on filehandle error

2011-07-29 Thread Dr.Ruud
On 2011-07-28 00:45, C.DeRykus wrote: open( ... ) or warn "..." and return; Here you are assuming that warn always returns true. It actually does, even if the device that it write to is full, but I don't think that is documented ... -- Ruud -- To unsubscribe, e-mail: beginners-uns

Re: Exit subroutine on filehandle error

2011-07-28 Thread Kevin Spencer
On Wed, Jul 27, 2011 at 9:30 AM, Rob Dixon wrote: > What exactly is wrong with "or do {...}"? > > I believe it is the best option simply because is is comparable to the > common "open ... or die $!" idiom. The do is there only so that a > warning can be issued as well as the return There's nothin

Re: Exit subroutine on filehandle error

2011-07-27 Thread C.DeRykus
On Jul 27, 9:30 am, rob.di...@gmx.com (Rob Dixon) wrote: > ... > > Well, one thing I dislike about it is that it is using "or do {...}" > > instead of > > an "if ( ) { ... }". And I did mention something similar. > > What exactly is wrong with "or do {...}"? > > I believe it is the best option sim

Re: Exit subroutine on filehandle error

2011-07-27 Thread Rob Dixon
On 27/07/2011 08:51, Shlomi Fish wrote: On Tue, 26 Jul 2011 16:58:47 +0100 Rob Dixon wrote: On 26/07/2011 16:39, Nikolaus Brandt wrote: On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: Another option would be to use eval { ... } and $@ to trap exceptions: Thank you all for the

Re: Exit subroutine on filehandle error

2011-07-27 Thread timothy adigun
Hello Nikolaus Brand, You can try these: 1. ) Instead of "die" in your code use "warn", then return from the subroutine, 2.) Intstead of hard coding the path and file in your program i.e ["$basedir/$userdir/$outfile" ], ask the user to input the path and file, as

Re: Exit subroutine on filehandle error

2011-07-27 Thread Shlomi Fish
Hi Rob, On Tue, 26 Jul 2011 16:58:47 +0100 Rob Dixon wrote: > On 26/07/2011 16:39, Nikolaus Brandt wrote: > > On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: > >> > >> Another option would be to use eval { ... } and $@ to trap exceptions: > > > > Thank you all for the replies. > > >

Re: Exit subroutine on filehandle error

2011-07-26 Thread Rob Dixon
On 26/07/2011 16:39, Nikolaus Brandt wrote: On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: Another option would be to use eval { ... } and $@ to trap exceptions: Thank you all for the replies. I used the above mentioned eval-$@ solution which was absolutely working fine. I t

Re: Exit subroutine on filehandle error

2011-07-26 Thread Nikolaus Brandt
Hi, On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: > Hi Nikolaus, > > On Tue, 26 Jul 2011 11:32:19 +0200 > Nikolaus Brandt wrote: > > > Hi, > > > > I'm currently writing a script which contains a subroutine to write > > dat

Re: Exit subroutine on filehandle error

2011-07-26 Thread John W. Krahn
Nikolaus Brandt wrote: Hi, Hello, I'm currently writing a script which contains a subroutine to write data to files. Currently I use open $fh, '>', "$basedir/$userdir/$outfile" or die "Can't write: $!\n"; which has the disadvantage, that the w

Re: Exit subroutine on filehandle error

2011-07-26 Thread Miquel Ruiz
El 26/07/2011 12:01, Shlomi Fish escribió: Another option would be to use eval { ... } and $@ to trap exceptions: http://perl-begin.org/tutorials/perl-for-newbies/part4/#page--exceptions--DIR Important to remember that "open" won't raise an exception if you are not using the "autodie" pragma

Re: Exit subroutine on filehandle error

2011-07-26 Thread Shlomi Fish
Hi Nikolaus, On Tue, 26 Jul 2011 11:32:19 +0200 Nikolaus Brandt wrote: > Hi, > > I'm currently writing a script which contains a subroutine to write > data to files. > Currently I use > open $fh, '>', "$basedir/$userdir/$outfile" or die "Can

  1   2   3   4   5   6   7   8   9   10   >