Re: return the list content

2018-06-14 Thread Paul Johnson
On Mon, Aug 18, 2014 at 06:07:59AM -0700, John SJ Anderson wrote: On Mon, Aug 18, 2014 at 1:38 AM, Paul Johnson wrote: > On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote: >> which one is the better way to return the list content? And if the >> method is an instance method? To expand

Re: return the list content

2014-09-12 Thread Charles DeRykus
On Wed, Sep 10, 2014 at 4:18 AM, Rob Dixon wrote: > On 09/09/2014 02:20, Ken Peng wrote: >> >> >>> The second option creates the same array and populates it, but then >>> copies it to another anonymous array, deletes the first array, and >>> returns a reference to the copy. >> >> >> Since this is

Re: return the list content

2014-09-10 Thread Rob Dixon
On 09/09/2014 02:20, Ken Peng wrote: The second option creates the same array and populates it, but then copies it to another anonymous array, deletes the first array, and returns a reference to the copy. Since this is a shadow copy, I don't think the first array will be deleted completely. I

Re: return the list content

2014-09-08 Thread Ken Peng
Since this is a shadow copy, I don't think the first array will be deleted completely. Isn't it? The second option creates the same array and populates it, but then copies it to another anonymous array, deletes the first array, and returns a reference to the copy. -- To unsubscribe, e-mail:

Re: return the list content

2014-09-08 Thread Rob Dixon
On 18/08/2014 09:17, Ken Peng wrote: sub myfunc { my @x=(1,2,3); return \@x; } # or, sub myfunc { my @x=(1,2,3); return [@x]; } which one is the better way to return the list content? And if the method is an instance method? The first version of the subroutine is the best choice

Re: returning arrays (was: Re: return the list content)

2014-09-08 Thread Shawn H Corey
On Tue, 09 Sep 2014 00:13:13 +0200 lee wrote: > Shawn H Corey writes: > > > On Mon, 18 Aug 2014 16:17:53 +0800 > > Ken Peng wrote: > > > >> sub myfunc { > >> my @x=(1,2,3); > >> return \@x; > >> } > >> > >> # or, > >> > >> sub myfunc { > >> my @x=(1,2,3); > >> return [@x]; > >> } > >

Re: returning arrays (was: Re: return the list content)

2014-09-08 Thread Jim Gibson
On Sep 8, 2014, at 3:13 PM, lee wrote: > Shawn H Corey writes: > >> On Mon, 18 Aug 2014 16:17:53 +0800 >> Ken Peng wrote: >> >>> sub myfunc { >>> my @x=(1,2,3); >>> return \@x; >>> } >>> >>> # or, >>> >>> sub myfunc { >>> my @x=(1,2,3); >>> return [@x]; >>> } >> >> # or >> >> sub myfu

returning arrays (was: Re: return the list content)

2014-09-08 Thread lee
Shawn H Corey writes: > On Mon, 18 Aug 2014 16:17:53 +0800 > Ken Peng wrote: > >> sub myfunc { >> my @x=(1,2,3); >> return \@x; >> } >> >> # or, >> >> sub myfunc { >> my @x=(1,2,3); >> return [@x]; >> } > > # or > > sub myfunc { > return [ 1, 2, 3 ]; > } Is there a difference to su

Re: return the list content

2014-08-18 Thread John SJ Anderson
On Mon, Aug 18, 2014 at 1:38 AM, Paul Johnson wrote: > On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote: >> which one is the better way to return the list content? And if the >> method is an instance method? > > Functionally, the two are identical. The first is returning a reference > to

Re: return the list content

2014-08-18 Thread Shawn H Corey
On Mon, 18 Aug 2014 16:17:53 +0800 Ken Peng wrote: > sub myfunc { > my @x=(1,2,3); > return \@x; > } > > # or, > > sub myfunc { > my @x=(1,2,3); > return [@x]; > } # or sub myfunc { return [ 1, 2, 3 ]; } -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail:

Re: return the list content

2014-08-18 Thread Paul Johnson
On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote: > Hello, > > sub myfunc { > my @x=(1,2,3); > return \@x; > } > > # or, > > sub myfunc { > my @x=(1,2,3); > return [@x]; > } > > which one is the better way to return the list content? And if the > method is an instance method? F

Re: return just a match from an array without changing the array

2014-03-08 Thread Janek Schleicher
Am 04.03.2014 00:35, schrieb shawn wilson: So, when I do this: my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0]; I get a full line and not just the capture: # ARIN WHOIS data and services are subject to the Terms of Use When I do this: my $src = (grep {s/.*(ARIN|APNIC).*(\n)?/$1/} @r

Re: return just a match from an array without changing the array

2014-03-04 Thread Dr.Ruud
On 2014-03-04 00:35, shawn wilson wrote: So, when I do this: my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0]; I get a full line and not just the capture: # ARIN WHOIS data and services are subject to the Terms of Use First understand what you coded: grep() is a filter: it only passes

Re: return just a match from an array without changing the array

2014-03-04 Thread Rob Dixon
On 03/03/2014 23:35, shawn wilson wrote: So, when I do this: my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0]; I get a full line and not just the capture: # ARIN WHOIS data and services are subject to the Terms of Use When I do this: my $src = (grep {s/.*(ARIN|APNIC).*(\n)?/$1/} @ret

Re: return just a match from an array without changing the array

2014-03-04 Thread shawn wilson
On Mar 4, 2014 9:46 AM, "Shawn H Corey" wrote: > > On Tue, 4 Mar 2014 09:24:53 -0500 > shawn wilson wrote: > > > my $src = (map {s/.*(ARIN|APNIC).*(?:\n)?/$1/r} @ret)[0]; > > You do realize this is process the whole array and then throwing out > all but the first? And it has the side effect of mo

Re: return just a match from an array without changing the array

2014-03-04 Thread Shawn H Corey
On Tue, 4 Mar 2014 09:24:53 -0500 shawn wilson wrote: > my $src = (map {s/.*(ARIN|APNIC).*(?:\n)?/$1/r} @ret)[0]; You do realize this is process the whole array and then throwing out all but the first? And it has the side effect of modifying the array? -- Don't stop where the ink does.

Re: return just a match from an array without changing the array

2014-03-04 Thread shawn wilson
It needs to be grep as a map would return the first line no matter what - not what I want. Also, this doesn't work: sub whois { my ($whois) = @_; my $sock = IO::Socket::INET->new( PeerAddr=>$whois, PeerPort=>'43', Timeout=>'60', ); return undef unless (defined($sock)); $soc

Re: return just a match from an array without changing the array

2014-03-03 Thread Shawn H Corey
On Mon, 3 Mar 2014 18:35:55 -0500 shawn wilson wrote: > So, when I do this: > my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0]; > I get a full line and not just the capture: > # ARIN WHOIS data and services are subject to the Terms of Use If you can't figure out what's wrong, neither wil

Re: return just a match from an array without changing the array

2014-03-03 Thread Ken Slater
I think you want to use 'map' instead of grep. HTH, Ken On Mon, Mar 3, 2014 at 6:35 PM, shawn wilson wrote: > So, when I do this: > my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0]; > I get a full line and not just the capture: > # ARIN WHOIS data and services are subject to the Terms o

Re: Return values more than 256?

2013-03-08 Thread Charles DeRykus
On Fri, Mar 8, 2013 at 2:49 AM, Dr.Ruud wrote: > On 2013-03-07 10:21, WFB wrote: > >> waitpid($pid, 0); >> close($trexe); >> my $tr_ret = ($?>>8); > > > Never postpone the reading of a global variable, > just snapshot it as early as possible. > > my $child = waitpid $pid, 0; > my $child_error

Re: Return values more than 256?

2013-03-08 Thread WFB
On 8 March 2013 11:49, Dr.Ruud wrote: > On 2013-03-07 10:21, WFB wrote: > > waitpid($pid, 0); >> close($trexe); >> my $tr_ret = ($?>>8); >> > > Never postpone the reading of a global variable, > just snapshot it as early as possible. > > my $child = waitpid $pid, 0; > my $child_error = $?;

Re: Return values more than 256?

2013-03-08 Thread Dr.Ruud
On 2013-03-07 10:21, WFB wrote: waitpid($pid, 0); close($trexe); my $tr_ret = ($?>>8); Never postpone the reading of a global variable, just snapshot it as early as possible. my $child = waitpid $pid, 0; my $child_error = $?; # snapshot a global $child == -1 and die "No child with pid

Re: Return values more than 256?

2013-03-07 Thread Brandon McCaig
On Thu, Mar 07, 2013 at 02:24:58PM -0800, John W. Krahn wrote: > Or, instead of the three argument open, use the list option and you > won't need quotes: > > my $pid = open my $trexe, '-|', $tr, $tr_params > or die "Could not start TestRunner. $!"; Good catch. :) I didn't think that o

Re: Return values more than 256?

2013-03-07 Thread John W. Krahn
Brandon McCaig wrote: On Thu, Mar 07, 2013 at 10:21:40AM +0100, WFB wrote: Hi, List, Hello, To test our software I use perl to start it several times. My perl script gather some information and start then the program with different parameters. It works very well, but I have a problem with t

Re: Return values more than 256?

2013-03-07 Thread WFB
On 7 March 2013 16:05, Brandon McCaig wrote: > On Thu, Mar 07, 2013 at 10:21:40AM +0100, WFB wrote: > > Hi, List, > > Hello, > > > To test our software I use perl to start it several times. My > > perl script gather some information and start then the program > > with different parameters. > > >

Re: Return values more than 256?

2013-03-07 Thread Brandon McCaig
On Thu, Mar 07, 2013 at 10:05:56AM -0500, Brandon McCaig wrote: > Apparently Windows supports 32-bit integers... The Web suggests > that if you want to get full 32-bit integers on Windows then you > should use the Win32::Process module instead of open. It's not > portable, but at least it will do w

Re: Return values more than 256?

2013-03-07 Thread Brandon McCaig
On Thu, Mar 07, 2013 at 10:21:40AM +0100, WFB wrote: > Hi, List, Hello, > To test our software I use perl to start it several times. My > perl script gather some information and start then the program > with different parameters. > > It works very well, but I have a problem with the return value

Re: return something

2012-11-21 Thread timothy adigun
Hi shawn, On Wed, Nov 21, 2012 at 11:48 PM, shawn wilson wrote: > how do i return something when i've got a long regex and one of the > captures is empty? > > $_ = '"435" "" "634"; > my ($one, $two, $three)= /^ >"(\d+)"\ >"(\d+)"\ >"(\d+)" > /x; > You can do like so: $_ = '"435

Re: return something

2012-11-21 Thread Shawn H Corey
On Wed, 21 Nov 2012 17:48:00 -0500 shawn wilson wrote: > how do i return something when i've got a long regex and one of the > captures is empty? > > $_ = '"435" "" "634"; > my ($one, $two, $three)= /^ >"(\d+)"\ >"(\d+)"\ >"(\d+)" > /x; > First, this contains a syntax error. Please

Re: return something

2012-11-21 Thread Danny Gratzer
Instead of + use *. * means 0 or more while + means 1 or more On Nov 21, 2012 4:51 PM, "shawn wilson" wrote: > how do i return something when i've got a long regex and one of the > captures is empty? > > $_ = '"435" "" "634"; > my ($one, $two, $three)= /^ >"(\d+)"\ >"(\d+)"\ >"(\d+)"

Re: return two varibles

2012-06-07 Thread Chris Nehren
On Thu, Jun 07, 2012 at 16:59:58 -0400 , Shawn H Corey wrote: > On 12-06-07 04:48 PM, Chris Stinemetz wrote: > >sub getMarketCells { > > my $val = shift; > > foreach my $k ( keys %apcHash ) { > > my($start, $end) = @{$apcHash{$k}}{qw/start end/}; > > return($start, $end) if $val eq $k;

Re: return two varibles

2012-06-07 Thread Robert Wohlfarth
On Thu, Jun 7, 2012 at 3:48 PM, Chris Stinemetz wrote: > sub getMarketCells { > my $val = shift; > foreach my $k ( keys %apcHash ) { >my($start, $end) = @{$apcHash{$k}}{qw/start end/}; >return($start, $end) if $val eq $k; > } > return ""; > } > Completely unrelated to your question...

Re: return two varibles

2012-06-07 Thread Chris Stinemetz
> You may be returning two values, but you're only catching one. > > Try > > my( $start, $end ) = getMarketCells( $apc ); > > > chrs, > john. You are correct. Thank you very much! Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@per

Re: return two varibles

2012-06-07 Thread Shawn H Corey
On 12-06-07 04:48 PM, Chris Stinemetz wrote: sub getMarketCells { my $val = shift; foreach my $k ( keys %apcHash ) { my($start, $end) = @{$apcHash{$k}}{qw/start end/}; return($start, $end) if $val eq $k; } return ""; return; } A return with any argument will return

Re: return two varibles

2012-06-07 Thread Jim Gibson
On Jun 7, 2012, at 1:48 PM, Chris Stinemetz wrote: > Not sure what I am doing wrong but my subroutine is only returning the > value on varible. I would like it to return both $end and $start for > the correct parameter I am passing. If you want to return two or more values from a subroutine, the

Re: return two varibles

2012-06-07 Thread John SJ Anderson
On Thursday, June 7, 2012 at 4:48 PM, Chris Stinemetz wrote: > my $test = getMarketCells($apc); > You may be returning two values, but you're only catching one. Try my( $start, $end ) = getMarketCells( $apc ); chrs, john. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For addi

Re: return ()

2011-02-10 Thread Uri Guttman
> "BM" == Brandon McCaig writes: BM> On Thu, Feb 10, 2011 at 10:20 PM, Uri Guttman wrote: >> this is all well documented. and i posted an explanation earlier in the >> thread. BM> I didn't realize this was an existing thread. In Google Mail it BM> appeared as a new thread. >>

Re: return ()

2011-02-10 Thread Brandon McCaig
On Thu, Feb 10, 2011 at 10:20 PM, Uri Guttman wrote: > this is all well documented. and i posted an explanation earlier in the > thread. I didn't realize this was an existing thread. In Google Mail it appeared as a new thread. >  BM> sub test3 >  BM> { >  BM>     my @empty_array = (); > >  BM>  

Re: return ()

2011-02-10 Thread Uri Guttman
> "BM" == Brandon McCaig writes: BM> I would have guessed an empty list, but the best way to find out is to BM> check. :) According to my tests, it's returning according to context: this is all well documented. and i posted an explanation earlier in the thread. BM> sub test1 BM> {

Re: return ()

2011-02-10 Thread Brandon McCaig
2011/2/10 terry peng : > does "return ()" mean return an empty list, or just mean "return" since "()" > is optional in Perl? I would have guessed an empty list, but the best way to find out is to check. :) According to my tests, it's returning according to context: #!/usr/bin/env perl use stric

Re: Return value from function

2011-01-13 Thread John Delacour
At 02:34 -0500 13/01/2011, shawn wilson wrote: I dig what you're saying about always using return. However I don't (have never used / seen) a case where a sub returns last expression. An example maybe? #!/usr/local/bin/perl use strict; use feature qw(say); say &SUB(); sub SUB { my $word = "

Re: Return value from function

2011-01-13 Thread Dr.Ruud
On 2011-01-13 08:18, John W. Krahn wrote: If you want to return a false value it is usually better to use return with no value: return; I prefer subs to normally return a single scalar, which can be a direct value like undef, or a reference to a more complex data structure, etc. If you all

Re: Return value from function

2011-01-13 Thread Dr.Ruud
On 2011-01-12 22:23, Parag Kalra wrote: On shell, successful command returns exit status of 0. As a best practice what status value shall a Perl function return. A function can return other kinds of values too. Going by the fact that Perl function returns the value of last command in it, I

Re: Return value from function

2011-01-12 Thread Uri Guttman
> "sw" == shawn wilson writes: sw> I dig what you're saying about always using return. However I sw> don't (have never used / seen) a case where a sub returns last sw> expression. An example maybe? the classic case which is used in the constant pragma is: sub FOO() { 'foo' }

Re: Return value from function

2011-01-12 Thread shawn wilson
On Jan 13, 2011 2:24 AM, "Uri Guttman" wrote: > > > "sw" == shawn wilson writes: > > >> subs in perl ALWAYS return something, either the value from return or > >> the last evaluated expression. > > sw> What do you mean by this? > > sw> sub nothing { > sw> my $something = 5; > sw> if ( $

Re: Return value from function

2011-01-12 Thread Uri Guttman
> "sw" == shawn wilson writes: >> subs in perl ALWAYS return something, either the value from return or >> the last evaluated expression. sw> What do you mean by this? sw> sub nothing { sw> my $something = 5; sw> if ( $something == 5) {} sw> } sw> ... will return 'undef' an

Re: Return value from function

2011-01-12 Thread John W. Krahn
Octavian Rasnita wrote: From: "Parag Kalra" On shell, successful command returns exit status of 0. As a best practice what status value shall a Perl function return. Going by the fact that Perl function returns the value of last command in it, I think function should return non-zero for a su

Re: Return value from function

2011-01-12 Thread shawn wilson
> subs in perl ALWAYS return something, either the value from return or > the last evaluated expression. What do you mean by this? sub nothing { my $something = 5; if ( $something == 5) {} } ... will return 'undef' and not 5 or anything else, right?

Re: Return value from function

2011-01-12 Thread Uri Guttman
> "OR" == Octavian Rasnita writes: OR> Perl doesn't use functions, but subroutines or methods, so they don't don't say that. subs and functions are just synonyms. it is how you use the sub that changes its meaning. OR> need to return something if you don't want them to return something.

Re: Return value from function

2011-01-12 Thread Octavian Rasnita
From: "Parag Kalra" Hi, On shell, successful command returns exit status of 0. As a best practice what status value shall a Perl function return. Going by the fact that Perl function returns the value of last command in it, I think function should return non-zero for a success. Cheers, Parag

Re: Return value from function

2011-01-12 Thread Uri Guttman
> "PK" == Parag Kalra writes: PK> Hi, PK> On shell, successful command returns exit status of 0. PK> As a best practice what status value shall a Perl function return. a shell command is NOT a function call. comparing them is useless. PK> Going by the fact that Perl function return

Re: Return value = 0

2010-05-26 Thread Shlomi Fish
On Wednesday 26 May 2010 18:16:18 Brandon McCaig wrote: > On Wed, May 26, 2010 at 9:43 AM, Andros Zuna wrote: > > But how could I test if the command executes if the return value changes? > > ...is there a unix command or other way that generates random/different > > return values?? > > The follo

Re: Return value = 0

2010-05-26 Thread Brandon McCaig
On Wed, May 26, 2010 at 9:43 AM, Andros Zuna wrote: > But how could I test if the command executes if the return value changes? > ...is there a unix command or other way that generates random/different > return values?? > The following C program will return a pseudo-random value every time it's r

Re: Return value = 0

2010-05-26 Thread Brian
On May 26, 2010, at 9:43 AM, Andros Zuna wrote: > Ok, I see, so the code should look somehow like this: > > #! > /usr/bin/perl > > use > warnings; > use > strict; > > > $command = "ls > -l"; ^^ Strongly suggest you use full paths here. > > while (system($command) != 0) > { >my > $c++ >

Re: Return value = 0

2010-05-26 Thread Andros Zuna
Ok, I see, so the code should look somehow like this: #! /usr/bin/perl use warnings; use strict; $command = "ls -l"; while (system($command) != 0) { my $c++ } But how could I test if the command executes if the return value changes? ...is there a unix command or other way that generates

Re: Return value = 0

2010-05-26 Thread Brian
On May 26, 2010, at 9:03 AM, Andros Zuna wrote: > Hi, > I did some few changes: > > #! > /usr/bin/perl > > # use > warnings; > # use > strict; > > > $command = `ls > -l`; > Looks like you're using backticks. Backticks actually causes perl to execute the command inside them and return the o

Re: Return value = 0

2010-05-26 Thread Andros Zuna
Hi, I did some few changes: #! /usr/bin/perl # use warnings; # use strict; $command = `ls -l`; if (system($command) == 0) { } elsif(system($command) != 0) { print "Failed to execute: $?\n"; my $c++ } But I'm still not getting it right, this is my error output: root@/user$ ./script.

RE: Return value = 0

2010-05-26 Thread Bob McConnell
while (system($command) != 0) { } Bob McConnell -Original Message- From: Andros Zuna [mailto:andros.z...@gmail.com] Sent: Wednesday, May 26, 2010 8:57 AM To: Chaitanya Yanamadala Cc: beginners@perl.org Subject: Re: Return value = 0 Hi, Thank you for the tip Chaitanya

Re: Return value = 0

2010-05-26 Thread Shlomi Fish
On Wednesday 26 May 2010 15:49:37 Andros Zuna wrote: > Hi! > I am trying to write a perl code that will retry the same command over > and over again until the return value is 0. > This is what I got for now: > > #! /usr/bin/perl > use warnings; > use strict; > > $command = 'ls -l'; > > if (syste

Re: Return value = 0

2010-05-26 Thread Andros Zuna
Hi, Thank you for the tip Chaitanya, but I still don't thik my script is working correct!? 2010/5/26 Chaitanya Yanamadala > u should give it as > $command=`ls -la`; > > > use the key on the top of TAB button with shift.. > * > Chaitanya > > "A man can get discouraged many times but he is not a

Re: Return value = 0

2010-05-26 Thread Chaitanya Yanamadala
u should give it as $command=`ls -la`; use the key on the top of TAB button with shift.. * Chaitanya "A man can get discouraged many times but he is not a failure until he stops trying..." "The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was

Re: return {}->{'name'};

2009-12-03 Thread Dermot
2009/12/3 Peter Scott : > On Mon, 30 Nov 2009 14:36:44 +, Dermot wrote: Does it have a name? > > It's called the Orcish Maneuver ("or-cache").  See: "Effective Perl > Programming", Hall with Schwartz. Thank you. Interesting there's a edition published in 1998 by Hall/Schwartz and an edition

Re: return {}->{'name'};

2009-12-03 Thread Peter Scott
On Mon, 30 Nov 2009 14:36:44 +, Dermot wrote: > sub get_cached_val_or_lookup { > my $val = shift; > return $cache{$val} ||= do { Could be more effective in 5.10 with return $cache{$val} //= do { to avoid repeating the fetch for values that are false. > One more question If I can.

Re: return {}->{'name'};

2009-11-30 Thread Randal L. Schwartz
> "Dermot" == Dermot writes: Dermot> One more question If I can. Chas pointed me to Dermot> http://perldesignpatterns.com/?PerlDesignPatterns some time ago. I Dermot> suspect that the above is a form of design pattern. Does it have a Dermot> name? Is there a reference to it at Dermot> http:/

Re: return {}->{'name'};

2009-11-30 Thread Dermot
2009/11/24 Randal L. Schwartz : >> "Dermot" == Dermot   writes: > > > ... > > Dermot> I guess the question is: Will the declaration of our %cache within a > Dermot> function-orientated sub-routine render it always uninitialized? > > I believe what you are seeing is that %cache is per-child, so

Re: return {}->{'name'};

2009-11-24 Thread Randal L. Schwartz
> "Dermot" == Dermot writes: Dermot> It' is perl, v5.6.2, on a modperl 1, ... Dermot> I guess the question is: Will the declaration of our %cache within a Dermot> function-orientated sub-routine render it always uninitialized? I believe what you are seeing is that %cache is per-child, so

Re: return {}->{'name'};

2009-11-24 Thread Dermot
2009/11/18 Randal L. Schwartz : > > I prefer a pattern that looks more like this: > > sub expensive_to_calculate { > >  my $self = shift; >  my $input = shift; # cache on this scalar > >  our %cache_for_expensive_to_calculate; >  return $cache_for_expensive_to_calculate{$input} ||= do { >    expens

Re: return {}->{'name'};

2009-11-17 Thread Randal L. Schwartz
> "Steve" == Steve Bertrand writes: Steve> Out of curiosity, if it's gone this far, is it fair for me to recommend Steve> reading Mr. Dominus' Memoizing chapter in Higher-Order Perl Steve> (http://hop.perl.plover.com/)? Yes, and as a simple verison of that, see Memoize in the CPAN. -- Rand

Re: return {}->{'name'};

2009-11-17 Thread Steve Bertrand
Randal L. Schwartz wrote: > I prefer a pattern that looks more like this: > > sub expensive_to_calculate { > > my $self = shift; > my $input = shift; # cache on this scalar > > our %cache_for_expensive_to_calculate; > return $cache_for_expensive_to_calculate{$input} ||= do { > expens

Re: return {}->{'name'};

2009-11-17 Thread Randal L. Schwartz
I prefer a pattern that looks more like this: sub expensive_to_calculate { my $self = shift; my $input = shift; # cache on this scalar our %cache_for_expensive_to_calculate; return $cache_for_expensive_to_calculate{$input} ||= do { expensive calculation here; more things based o

Re: return {}->{'name'};

2009-11-17 Thread Dr.Ruud
Ming Qian wrote: I encounter some code as follows, and can not understand. Would someone help me? use constant 'cache_result' => {}; sub abc { ... return cache_result->{$self->name}; } What does this mean? perl -e' use constant cache_result => {};

Re: return {}->{'name'};

2009-11-14 Thread Uri Guttman
> "JP" == Jeff Pang writes: JP> On Nov 15, 2009, Uri Guttman wrote: > "PK" == Parag Kalra writes: >> and yes, that is declaring a constant. you can tell it is a hash as it >> is initialized to a hash reference. it makes little sense to me why you >> would declare such a beast

Re: Re: return {}->{'name'};

2009-11-14 Thread Jeff Pang
On Nov 15, 2009, Uri Guttman wrote: > "PK" == Parag Kalra writes: >and yes, that is declaring a constant. you can tell it is a hash as it >is initialized to a hash reference. it makes little sense to me why you >would declare such a beast as the reference can have its contents >altered a

Re: return {}->{'name'};

2009-11-14 Thread Ming Qian
Thanks Uri and Parag. After reading your comments and taking a coffee, I understand it. :) Thanks, Bruce. On Sun, Nov 15, 2009 at 12:18 AM, Uri Guttman wrote: > > "PK" == Parag Kalra writes: > > first off, as a newbie here, please learn to bottom post. reading is > done top down so put

Re: return {}->{'name'};

2009-11-14 Thread Uri Guttman
> "PK" == Parag Kalra writes: first off, as a newbie here, please learn to bottom post. reading is done top down so put your comments BELOW the quoted and edited post you are commenting about. PK> Even I am a beginer but let me throw some pointers. Experienced PK> users kindly correct me

Re: return {}->{'name'};

2009-11-14 Thread Parag Kalra
Hmmm. Even I am a beginer but let me throw some pointers. Experienced users kindly correct me if I am wrong First line is declaring a constant. What I could not get is that what constant are we trying to declare i.e a variable, hash or a reference. Read more - perldoc constant And then t

Re: Return available address book fields

2008-11-29 Thread Chas. Owens
On Sat, Nov 29, 2008 at 11:32, John J. Foster <[EMAIL PROTECTED]> wrote: > Hi again, > > Is it possible to modify the following script to return a list of > available fields? I'm trying to query my address at fastmail.fm and > would like to display as much info as possible. snip Replace i

Re: Return available address book fields

2008-11-29 Thread John J. Foster
OK - let's try the script this time! http://bsdconsulting.no/tools/mutt-ldap.pl On Sat, Nov 29, 2008 at 09:32:32AM -0700, John J. Foster wrote: > Hi again, > > Is it possible to modify the following script to return a list of > available fields? I'm trying to query my address at fastmail.fm and

Re: return sorted hashes from subroutines

2008-08-29 Thread Rob Dixon
Rob Dixon wrote: > > You can pass single hashes to and from subroutines as a simple list. So you > successfully passed in %db_del, for instance, but if you need to keep two or > more hashes separate you must pass them by reference. I should also have mentioned that a hash won't stay sorted, so yo

Re: return sorted hashes from subroutines

2008-08-29 Thread Rob Dixon
Pedro Soto wrote: > Hi, > I am trying to write script to retrieve info from a file that looks like: > > col1 col2col3 > A5 10 > A5 10 > A5 11 > A6 8 > A7 9 > B5 8 > B6 9 > what

Re: return sorted hashes from subroutines

2008-08-29 Thread Amit Saxena
On Fri, Aug 29, 2008 at 5:10 PM, Pedro Soto <[EMAIL PROTECTED]> wrote: > Hi, > I am trying to write script to retrieve info from a file that looks like: > > col1 col2col3 > A5 10 > A5 10 > A5 11 > A6 8 > A7 9 >

Re: return sorted hashes from subroutines

2008-08-29 Thread Xavier Mas
El Friday 29 August 2008 13:40:04 Pedro Soto va escriure: > Hi, > I am trying to write script to retrieve info from a file that looks like: > > col1 col2col3 > A5 10 > A5 10 > A5 11 > A6 8 > A7 9 > B5

Re: Return number of keys in a hash of hash? Looping through "sub hash"?

2008-01-24 Thread pzimmermann
On Jan 24, 10:12 am, [EMAIL PROTECTED] (Tom Phoenix) wrote: > On Jan 24, 2008 9:07 AM, <[EMAIL PROTECTED]> wrote: > > > I'd like to get the number of keys in hash of hashes. I know that I > > can do something like $count = keys( %myHash ), but how would I go > > about finding the number of keys i

Re: Return number of keys in a hash of hash? Looping through "sub hash"?

2008-01-24 Thread Tom Phoenix
On Jan 24, 2008 9:07 AM, <[EMAIL PROTECTED]> wrote: > I'd like to get the number of keys in hash of hashes. I know that I > can do something like $count = keys( %myHash ), but how would I go > about finding the number of keys in a sub-hash? my $count = keys %{ $sub_hash_reference }; You can

Re: Return value from subroutine

2007-04-18 Thread yitzle
The hash was not suggested because of efficiency. I suggested a hash because they require less coding and make your life so much easier. Less coding, less room for errors, nicer code, etc. Not to mention that filling a hash from a textfile is trivial, so you can move the associations into a file.

Re: Return value from subroutine

2007-04-18 Thread Rob Dixon
Johnson, Reginald (GTI) wrote: I don't see what I'm doing wrong here. I just want to compare the value of $_ and return the indicated string if there is a match. #!/usr/bin/perl use strict; use warnings; my $temp_proc; my $mnt_proc = "AVI"; $temp_proc = convert_mnt_proc($mnt_proc); #

RE: Return value from subroutine

2007-04-18 Thread Johnson, Reginald \(GTI\)
EMAIL PROTECTED] On Behalf Of yitzle Sent: Wednesday, April 18, 2007 10:24 AM To: Johnson, Reginald (GTI) Cc: beginners@perl.org Subject: Re: Return value from subroutine > return = "Audit Volume"; You have return = "thingy"; You want return &q

Re: Return value from subroutine

2007-04-18 Thread Tom Phoenix
On 4/18/07, Johnson, Reginald (GTI) <[EMAIL PROTECTED]> wrote: if ($_ eq /AVI/) { return = "Audit Volume"; } Perl's return operator isn't a variable you assign to. Maybe you want this? return "Audit Volume"; #

Re: Return value from subroutine

2007-04-18 Thread Jeff Pang
2007/4/18, Johnson, Reginald (GTI) <[EMAIL PROTECTED]>: if ($_ eq /AVI/) { Above is not right. Maybe '$_ =~ /AVI/' or ' $_ eq "AVI" '? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Return value from subroutine

2007-04-18 Thread yitzle
return = "Audit Volume"; You have return = "thingy"; You want return "thingy"; if ($_ eq /AVI/) { return = "Audit Volume"; } elsif (/BKP/) {

Re: return 1

2006-12-08 Thread JupiterHost.Net
Derek B. Smith wrote: Why is return 1 coded at the end of many programs. For example: I know it means true but what does this do and why? thank you derek #!/usr/bin/perl #use strict; my $user_name = qq(dsmithxx); my $user_password = qq(); my $sql_server = qq(x); my ($dbh,$drh,$stmt);

Re: return 1

2006-12-08 Thread Derek B. Smith
--- Jay Savage <[EMAIL PROTECTED]> wrote: > On 12/8/06, Derek B. Smith > <[EMAIL PROTECTED]> wrote: > > Why is return 1 coded at the end of many programs. > For > > example: > > > > I know it means true but what does this do and > why? > > Derek, > > For historical reasons, the final statement o

Re: return 1

2006-12-08 Thread Jay Savage
On 12/8/06, Derek B. Smith <[EMAIL PROTECTED]> wrote: Why is return 1 coded at the end of many programs. For example: I know it means true but what does this do and why? Derek, For historical reasons, the final statement of any script that is imported with use or require (and possibly do?) mu

Re: return 1

2006-12-08 Thread Jeff Pang
> >Why is return 1 coded at the end of many programs. For >example: > >I know it means true but what does this do and why? This is because it's mostly 'require' d by other scripts then you may need to add '1' at the end. If this script is required by other scripts,but its last statement doesn't

Re: return values evaluating to true

2006-01-25 Thread Bob Showalter
radhika wrote: Hi, I have a snippet of code as below. Even when I return 0 or '', why does @blocks evaluate to true? If rows returned are 0, then if(@blocks) should evaluate to false, correct? ... sub do_something { my @row = @_; return @row if(@row); return ''; } @blocks

Re: return values evaluating to true

2006-01-25 Thread Chas Owens
On 1/25/06, radhika <[EMAIL PROTECTED]> wrote: > Hi, > I have a snippet of code as below. > Even when I return 0 or '', why does @blocks evaluate to true? > If rows returned are 0, then if(@blocks) should evaluate to false, correct? > Thanks, > Radhika > --- > use strict; > use diagnostics; > my @b

Re: return code

2005-02-28 Thread John W. Krahn
[EMAIL PROTECTED] wrote: ok so $? states CHILD_ERROR or last status returned by the last ` ` command. $! states yields the current value of errno in shell if I say it will give me a true or false value. cat /tmp/foo if [ $? -eq 0 ] then echo yes command succeeded else echo no. fi In

Re: return code

2005-02-28 Thread DBSMITH
ers PMSubject

Re: return code

2005-02-28 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote: $exit_value = $? >> 8 $signal_num = $? & 127; $dumped_core = $? & 128; ok this helps, thanks! But, in my small block of code I am using $? >> 8 as so system ("cat /tmp/used"); # /tmp/used does not exist so this should return 0 for false in Perl and 1 fal

Re: return code

2005-02-28 Thread DBSMITH
cc 02/28/2005 11:38 Perl Beginners AM

  1   2   >