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
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
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 metho
> On May 5, 2017, at 6:06 PM, lee wrote:
>
>
> Hi,
>
> how can a sleeping program react to a key that was pressed without
> return being pressed?
>
See ‘perldoc -q "How can I read a single character from a file? From the
keyboard?”
Jim Gibson
jgib...@snowla
Shlomi Fish writes:
> On Sun, 14 May 2017 12:08:59 +0300
> Shlomi Fish wrote:
>
>> Hi lee,
>>
>> On Sat, 06 May 2017 02:06:19 +0100
>> lee wrote:
>>
>> > Hi,
>> >
>> > how can a sleeping program react to a key that was presse
On Sun, 14 May 2017 12:08:59 +0300
Shlomi Fish wrote:
> Hi lee,
>
> On Sat, 06 May 2017 02:06:19 +0100
> lee wrote:
>
> > Hi,
> >
> > how can a sleeping program react to a key that was pressed without
> > return being pressed?
> >
> >
Hi lee,
On Sat, 06 May 2017 02:06:19 +0100
lee wrote:
> Hi,
>
> how can a sleeping program react to a key that was pressed without
> return being pressed?
>
>
> perl -e 'use Term::ReadKey; my $ke = ReadKey(10); print "k: $ke\n";'
>
>
>
Hi,
how can a sleeping program react to a key that was pressed without
return being pressed?
perl -e 'use Term::ReadKey; my $ke = ReadKey(10); print "k: $ke\n";'
... shows that:
+ ReadKey() returns undef after the timeout
+ ReadKey() returns undef after the timeout e
> process in the fork does a webservice query which may take a few minutes to
> return results. What I want to do is forward the user to a "Searching for
> results" page which polls periodically for results. Eventually it will
> display the search results. How can I do this?
Hi,
Can anyone help me with this?
I have two scripts, the first one calls the exec command which then invokes the
second script. The second script then creates a fork process. The child
process in the fork does a webservice query which may take a few minutes to
return results.
What I want to
On Mon, Jan 5, 2015 at 3:20 PM, Harry Putnam wrote:
> When running shell commands from perl script with an open() instead of
> system() or exec how is the return value snagged.
>
> I guess, if it doesn't die, it worked but how to snag that information
> and at what point?
Harry:
On Mon, Jan 05, 2015 at 06:20:06PM -0500, Harry Putnam wrote:
> When running shell commands from perl script with an open() instead of
> system() or exec how is the return value snagged.
>
> I guess, if it doesn't die, it worked but how to snag that information
&g
When running shell commands from perl script with an open() instead of
system() or exec how is the return value snagged.
I guess, if it doesn't die, it worked but how to snag that information
and at what point?
--- 8< snip -- 8< snip -- 8', "$log"
erence to the copy.
>>
>>
>> Since this is a shadow copy, I don't think the first array will be
>> deleted completely. Isn't it?
>
>
> The second option is this
>
> sub myfunc {
>my @x=(1,2,3);
>return [@x];
> }
>
> And yes, t
etely. Isn't it?
The second option is this
sub myfunc {
my @x=(1,2,3);
return [@x];
}
And yes, the array @x is created, populated, and deleted completely
every time the subroutine is called.
In the first option
sub myfunc {
my @x=(1,2,3);
return \@x;
}
the array isn't del
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:
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
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;
> >> }
> >>
>
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,
>>&g
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];
>> }
>
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
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.
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 conte
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?
Thanks.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional
, Jun 9, 2014 at 12:25 PM, Mike wrote:
> Hello everyone. Can anyone point me in the direction of a module that will
> allow me to grab HTML fields and return them as a hash?
>
> Thanks.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional
http://mojolicio.us/perldoc/Mojo/DOM
not exactly what you want, but it is good to use.
On Mon, Jun 9, 2014 at 12:25 PM, Mike wrote:
> Hello everyone. Can anyone point me in the direction of a module that will
> allow me to grab HTML fields and return them as a hash?
>
> Thanks.
Hello everyone. Can anyone point me in the direction of a module that
will allow me to grab HTML fields and return them as a hash?
Thanks.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
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
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
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
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
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.
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',
);
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
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
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)[0];
I get just the match but it also alters
Harry Putnam writes:
Jesus... who wrote this illiterate crud?
> Harry Putnam writes:
>
> Sorry to have dropped out on this. I called away and now have other
^
got
> scripting to get done.
>
> But didn't want anyone to
Harry Putnam writes:
Sorry to have dropped out on this. I called away and now have other
scripting to get done.
But didn't want anyone to think I didn't appreciate the replies.
The walk thru of my (poor) could is very helpful...
Thanks
--
To unsubscribe, e-mail: beginners-unsubscr...@perl
On Wed, Aug 28, 2013 at 11:48:45AM -0400, Harry Putnam wrote:
> I know the format and scripting are probably pretty backwards but I
> seem to recall it being important to have a `return' line in a
> function.
>
> The code below was a script by itself but now I need to turn
On 28/08/2013 16:48, Harry Putnam wrote:
The code below was a script by itself but now I need to turn it into a
function inside a larger script... I've done something that sort of
works but fails on a specific file name that looks like `.#somefile'.
What does "fails" mean? Does it crash?, prod
I know the format and scripting are probably pretty backwards but I
seem to recall it being important to have a `return' line in a
function.
The code below was a script by itself but now I need to turn it into a
function inside a larger script... I've done something that sort of
works
o God.
---
From: Nathan Hilterbrand
To: beginners@perl.org
Sent: Thursday, 28 March 2013 8:54 PM
Subject: Re: Need clarification in using return value for modules
On 03/28/2013 11:17 AM, *Shaji Kalidasan* wrote:
> G
0.1;
sub foo() { print "Inside foo\n"; }
sub bar { print "Inside bar\n"; }
[/module]
#Please note that I am not using a return value (1 in this case) as the last
statement
[code]
use My::GoldenRock::Utilities 'bar';
print bar();
[/code]
[output]
Inside bar
1
[/output]
r { print "Inside bar\n"; }
[/module]
#Please note that I am not using a return value (1 in this case) as the last
statement
[code]
use My::GoldenRock::Utilities 'bar';
print bar();
[/code]
[output]
Inside bar
1
[/output]
From where is the number 1 coming in the output. Ear
id altogether since
there's an implicit waitpid when the pipe gets
closed. It gets a bit confusing but the pipe
close needs to be checked first and then
subsequently the child return as another poster
demonstrated:
close $trexe or warn $! ? "Error closing $tr pipe: $!"
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 = $?;
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
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
the return values
of our program. This return codes are all in an area from 55000
to 6. I use open to invoke our program and print the
output. Finally I use the $? variable and print the error code
in case of an error.
sub start_test_runner {
my ($tr = shift, $tr_params) = @_;
I don't
> > with different parameters.
> >
> > It works very well, but I have a problem with the return values
> > of our program. This return codes are all in an area from 55000
> > to 6. I use open to invoke our program and print the
> > output. Finally I use the $? vari
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
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 probl
.
It works very well, but I have a problem with the return values of our
program. This return codes are all in an area from 55000 to 6.
I use open to invoke our program and print the output. Finally I use the $?
variable and print the error code in case of an error.
sub start_test_runner {
my ($tr
On Sat, 5 Jan 2013 09:01:26 -0700
Elim Qiu wrote:
> perl shell is a good idear (I'm using ipython a lot. That's why I like
> to try perl shell), but it really has problems. See attached
> screenshot.
Ah. Yeah, that's a different animal to Perl.
This list can help you with problems with Perl, b
Hello:
On Sat, Jan 05, 2013 at 09:01:26AM -0700, Elim Qiu wrote:
> perl shell is a good idear (I'm using ipython a lot. That's why I like
> to try perl shell), but it really has problems. See attached
> screenshot.
I think you forgot to mention that you were using this psh. :)
That or I missed it
perl shell is a good idear (I'm using ipython a lot. That's why I like
to try perl shell), but it really has problems. See attached
screenshot.
On Sat, Jan 5, 2013 at 7:16 AM, David Precious wrote:
> On Fri, 4 Jan 2013 15:43:41 -0700
> Elim Qiu wrote:
>
>> It's on snow leopard, perl version 5.10
On Fri, 4 Jan 2013 15:43:41 -0700
Elim Qiu wrote:
> It's on snow leopard, perl version 5.10.0
>
>
>
> print 3 > 1, "\n";
>
> prints 1 and ignored "\n"
Includes the newline for me.
If I had to hazard a guess, I'd say perhaps when you ran it you
accidentally mistyped "." instead of "," (so yo
I'm getting both new lines to print.
[code]
use 5.10.0;
print "1: ";
print 3 > 1, "\n";
print "2: ";
print 3 == 3, "\n";
[/code]
[output]
>perl booltest.pl
1: 1
2: 1
>
[/output]
Richard Johnson
(708)253-8130
On Fri, Jan 4, 2013 at 5:43 PM, Elim Qiu wrote:
> It's on snow leopard, perl versi
It's on snow leopard, perl version 5.10.0
print 3 > 1, "\n";
prints 1 and ignored "\n"
print 3 == 3, "\n";
prints 1 and "\n"
There're some in consistency here.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn
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
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+)"\
>
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";
>
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;
--
To unsubscribe, e-mail: beginners-unsubscr...@
On Sun, Jul 29, 2012 at 11:19 PM, Andy Bach wrote:
> On Sun, Jul 29, 2012 at 10:01 AM, lina wrote:
>> Strangely, it only substituted once, but not for the later once.
>> Thanks ahead for your suggestions, I don't know why,
>
> Not exactly sure what you're up to - but you only open fh1 once - so
>
On Sun, Jul 29, 2012 at 10:01 AM, lina wrote:
> Strangely, it only substituted once, but not for the later once.
> Thanks ahead for your suggestions, I don't know why,
Not exactly sure what you're up to - but you only open fh1 once - so
the inner while in your sub is going to read until eof and c
Hi,
I have written something as following,
my $template_file="template";
my $h_data_file="h_data";
open my $fh1, '<', $template_file;
open my $fh2, '<', $h_data_file;
while(<$fh2>){
my ($h11,$h21,$h22,$h33)=split ' ', $_;
&substitute($h11,$h21,$h22,$h33);
say $h11,$h21
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/};
> > r
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 "";
> }
>
> 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
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 arg
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 s
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
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.
Thank you for your help.
#!/usr/bin/perl
use warnings;
use strict;
my %apcHash = (
M => { "sta
> From: sono-io
>
> > According to the RFC's, "Return-path" is reserved for use by the transport
> servers. It is likely your server is stripping out the suggestion you have
> put in
> there.
>
> But I can set it using SMTP, so does sendmail handl
Hi Bob,
Thanks for the reply.
> According to the RFC's, "Return-path" is reserved for use by the transport
> servers. It is likely your server is stripping out the suggestion you have
> put in there.
But I can set it using SMTP, so does sendmail ha
> From: sono-io
>
> Unfortunately, I can't switch to SMTP right now (long story) and so I
> need to find a way to get Mime::Lite to send the Return-Path. Does anyone
> know how to do this?
>
> If Mime::Lite can't do it, does anyone have anot
Unfortunately, I can't switch to SMTP right now (long story) and so I
need to find a way to get Mime::Lite to send the Return-Path. Does anyone know
how to do this?
If Mime::Lite can't do it, does anyone have another module they can
recommend?
The reason I
On Apr 23, 2012, at 5:06 PM, sono...@fannullone.us wrote:
> I'm trying to set the Return-Path in emails that I send out, but I'm not
> having any luck.
Apparently the culprit is sendmail, which is the default for
Mime::Lite. If I use SMTP instead, I'm able to
I'm trying to set the Return-Path in emails that I send out, but I'm
not having any luck. Here's the code I'm trying:
use strict;
use warnings;
use MIME::Lite;
my $msg = MIME::Lite->new (
From => 'sen...@example.c
In Google Mail it
BM> appeared as a new thread.
>> BM> sub test3
>> BM> {
>> BM> my @empty_array = ();
>>
>> BM> return @empty_array;
>> BM> }
>>
>> that is very different than the above two.
BM> The
my @empty_array = ();
>
> BM> return @empty_array;
> BM> }
>
> that is very different than the above two.
The point was to compare the results. It wasn't supposed to be the same. :-/
> have it by definition. the array is returned in scalar context and it
>
n the
thread.
BM> sub test1
BM> {
BM> return ();
BM> }
BM> sub test2
BM> {
BM> return;
BM> }
those two are the same. period. the parens are only to group an
expression if any. there is NO forming of a list by those parens.
BM> sub test3
BM>
From: terry peng
To: beginners
Sent: Thu, February 10, 2011 2:07:43 PM
Subject: about return
>hello,
>
>when in the case "return undef" I prefer just "return" coz in list context it
>will return an empty list.
>
>my $exist = ...
>if ($exist) {
>
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 accord
does "return ()" mean return an empty list, or just mean "return" since "()" is
optional in Perl?
thanks!
>>>>> "AW" == Alex Wang02 writes:
AW> Terry,
AW> Here is my understanding:
AW> You can try defined function to verify the return value in List
AW> context, you can find the return value is (undef) instead of undef
AW> once the condition is fa
Terry,
Here is my understanding:
You can try defined function to verify the return value in List context, you
can find the return value is (undef) instead of undef once the condition is
false. Because you are using @result=&yoursubName instead of
$result=&yoursubName.
Please correct
Thu, 10 Feb 2011 10:04:55 +0200 письмо от Shlomi Fish :
>
> In List context it will return an empty list. You may have meant in scalar
> context in which case:
>
>
Sorry , my typo.
I did mean the scalar context.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
On Thursday 10 Feb 2011 09:13:34 terry peng wrote:
> Wed, 9 Feb 2011 22:44:10 -0800 (PST) письмо от "C.DeRykus"
:
> > On Feb 9, 10:07 pm, terry.p...@mail.ru (terry peng) wrote:
> > > hello,
> > >
> > > when in the case "return undef" I pr
Wed, 9 Feb 2011 22:44:10 -0800 (PST) письмо от "C.DeRykus" :
> On Feb 9, 10:07 pm, terry.p...@mail.ru (terry peng) wrote:
> > hello,
> >
> > when in the case "return undef" I prefer just "return" coz in list context
> it will return
On Feb 9, 10:07 pm, terry.p...@mail.ru (terry peng) wrote:
> hello,
>
> when in the case "return undef" I prefer just "return" coz in list context it
> will return an empty list.
>
> my $exist = ...
> if ($exist) {
> return 1;
>
> } else {
>>>>> "PK" == Parag Kalra writes:
PK> Is this what you mean
PK> ($exist) ? return 1 : return undef
PK> I think even this should work
PK> ($exist) ? 1 : 0;
he wants an empty list in a list context when returning the false value
so neither
>
> return 1 if $exists ;
> return ;
>
> then it is easy to see what conditions will return what values. no need
> for if/else blocks or noisy ?: ops.
>
That's a good solution.
Thanks much. :)
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For a
>>>>> "tp" == terry peng writes:
tp> when in the case "return undef" I prefer just "return" coz in list
tp> context it will return an empty list.
tp> my $exist = ...
tp> if ($exist) {
tp> return 1;
tp> } else {
tp&
Is this what you mean
($exist) ? return 1 : return undef
I think even this should work
($exist) ? 1 : 0;
~Parag
2011/2/9 terry peng
>
> hello,
>
> when in the case "return undef" I prefer just "return" coz in list context
> it will return an empty lis
hello,
when in the case "return undef" I prefer just "return" coz in list context it
will return an empty list.
my $exist = ...
if ($exist) {
return 1;
} else {
return;
}
the code above can work, but having many lines.
So I want:
return $exist ? 1 : (...);
w
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 SU
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
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
>>>>> "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 c
1 - 100 of 711 matches
Mail list logo