[32324] in Perl-Users-Digest
Perl-Users Digest, Issue: 3591 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 17 18:09:29 2012
Date: Tue, 17 Jan 2012 15:09:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 17 Jan 2012 Volume: 11 Number: 3591
Today's topics:
find it, cut it out, find next <oldyork90@yahoo.com>
Re: find it, cut it out, find next <NoSpamPleaseButThisIsValid3@gmx.net>
Re: find it, cut it out, find next <willem@toad.stack.nl>
Re: find it, cut it out, find next <derykus@gmail.com>
How to remove STDIN in perl CGI <hslee911@yahoo.com>
Re: How to remove STDIN in perl CGI <ben@morrow.me.uk>
Re: Searching Complex Array Values <jimsgibson@gmail.com>
ssh tullen <nospam@lisse.NA>
ssh tullen <nospam@lisse.NA>
Re: ssh tullen <hjp-usenet2@hjp.at>
Re: ssh tunnel <nospam@lisse.NA>
Re: ssh tunnel <peter@makholm.net>
Re: ssh tunnel <ben@morrow.me.uk>
Re: Unicode-AGE of a character? <brian.d.foy@gmail.com>
When is @_ undefined? (Seymour J.)
Re: When is @_ undefined? <willem@toad.stack.nl>
Re: When is @_ undefined? <ben@morrow.me.uk>
Re: When is @_ undefined? (Tony Mountifield)
Re: When is @_ undefined? <ben@morrow.me.uk>
Re: When is @_ undefined? <rweikusat@mssgmbh.com>
Re: When is @_ undefined? <kaz@kylheku.com>
Re: When is @_ undefined? <ben@morrow.me.uk>
Re: When is @_ undefined? <rweikusat@mssgmbh.com>
Re: When is @_ undefined? (Tim McDaniel)
Re: When is @_ undefined? <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 15 Jan 2012 19:53:18 -0800 (PST)
From: oldyork90 <oldyork90@yahoo.com>
Subject: find it, cut it out, find next
Message-Id: <e7bcb860-5129-403b-91ac-1a2a009af478@p42g2000vbt.googlegroups.com>
I have a string that contains numbers and ranges of numbers, like
'1 2 4-6 8 20 - 23' which translates as "include numbers 1, 2, 4, 5,
6, 8, 20, 21, 22, 23'
I can find the range "objects" with
while ($s =~ /(\d+ *- *\d+)/g) {
# work with $1
}
Is there a way to trim up this string during the loop so that when
it's done, the range "objects" are gone and I'm left with the discreet
list of digits. It would look like this when complete '1 2 8'
I can trim it up later with s/(\d+ *- *\d+)//g, but was wondering if
this could be a one step thing. Seems like it would be a common
operation... find it, cut it out, find the next. I don't want
anything complex... just wondering.
Thank you.
------------------------------
Date: Mon, 16 Jan 2012 10:34:43 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: find it, cut it out, find next
Message-Id: <4f13ef34$0$7608$9b4e6d93@newsspool1.arcor-online.net>
Am 16.01.2012 04:53, schrieb oldyork90:
> I have a string that contains numbers and ranges of numbers, like
>
> '1 2 4-6 8 20 - 23' which translates as "include numbers 1, 2, 4, 5,
> 6, 8, 20, 21, 22, 23'
>
> I can find the range "objects" with
>
> while ($s =~ /(\d+ *- *\d+)/g) {
> # work with $1
> }
>
> Is there a way to trim up this string during the loop so that when
> it's done, the range "objects" are gone and I'm left with the discreet
> list of digits. It would look like this when complete '1 2 8'
Sure, just get rid of the /g (you have the while loop):
perl -E'
$s="1 2 4-6 8 20 - 23";
while($s =~ s/(\d+) *- *(\d+)//) {
say "work with range $1 to $2"
}
say "rest=$s"
'
- Wolf
------------------------------
Date: Mon, 16 Jan 2012 15:49:43 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: find it, cut it out, find next
Message-Id: <slrnjh8hon.2p0e.willem@toad.stack.nl>
oldyork90 wrote:
) I have a string that contains numbers and ranges of numbers, like
)
) '1 2 4-6 8 20 - 23' which translates as "include numbers 1, 2, 4, 5,
) 6, 8, 20, 21, 22, 23'
)
) I can find the range "objects" with
)
) while ($s =~ /(\d+ *- *\d+)/g) {
) # work with $1
) }
)
) Is there a way to trim up this string during the loop so that when
) it's done, the range "objects" are gone and I'm left with the discreet
) list of digits. It would look like this when complete '1 2 8'
This sounds a hell of a lot like an X-Y problem.
Do you really want to do one thing with the ranges, and something different
with the single numbers? Or do you want to do the same thing with each
included number, but you've already figured out that you can first do the
while loop you wrote above, and then a simple loop?
Maybe you can get an idea from this piece of code, whatever you want to do:
$s =~ s/(\d+) *- *(\d+)/join(' ',($1 .. $2))/ge;
) I can trim it up later with s/(\d+ *- *\d+)//g, but was wondering if
) this could be a one step thing. Seems like it would be a common
) operation... find it, cut it out, find the next. I don't want
) anything complex... just wondering.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Mon, 16 Jan 2012 16:08:17 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: find it, cut it out, find next
Message-Id: <48027ddf-7b05-449c-b648-bee27d76be71@k6g2000vbz.googlegroups.com>
On Jan 15, 7:53=A0pm, oldyork90 <oldyor...@yahoo.com> wrote:
> I have a string that contains numbers and ranges of numbers, like
>
> '1 2 4-6 8 20 - 23' =A0which translates as "include numbers 1, 2, 4, 5,
> 6, 8, 20, 21, 22, 23'
>
> I can find the range "objects" with
>
> while ($s =3D~ /(\d+ *- *\d+)/g) {
> =A0 # work with $1
>
> }
>
> Is there a way to trim up this string during the loop so that when
> it's done, the range "objects" are gone and I'm left with the discreet
> list of digits. =A0It would look like this when complete '1 2 8'
>
> I can trim it up later with s/(\d+ *- *\d+)//g, but was wondering if
> this could be a one step thing. =A0Seems like it would be a common
> operation... find it, cut it out, find the next. =A0I don't want
> anything complex... just wondering.
$re =3Dqr/(\d\s* (-) \s*\d+ | \d+) /x;
while ($s=3D~/$re/g ) {
$p=3D$1;
$s=3D~s/$p// if defined $2;
}
--
Charles DeRykus
------------------------------
Date: Tue, 17 Jan 2012 04:05:20 -0800 (PST)
From: James <hslee911@yahoo.com>
Subject: How to remove STDIN in perl CGI
Message-Id: <c68b9c02-d59d-45fe-9380-58f345c34a6c@f1g2000yqi.googlegroups.com>
How to remove STDIN string in perl CGI (post method) once it is
processed? Is it possible?
The goal is, if the browser is refreshed, the STDIN string no longer
affects the outcome.
TIA
James
------------------------------
Date: Tue, 17 Jan 2012 13:42:21 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to remove STDIN in perl CGI
Message-Id: <teagu8-tcp1.ln1@anubis.morrow.me.uk>
Quoth James <hslee911@yahoo.com>:
> How to remove STDIN string in perl CGI (post method) once it is
> processed? Is it possible?
> The goal is, if the browser is refreshed, the STDIN string no longer
> affects the outcome.
You need to explain a bit more clearly exactly what you want. If you
post a *short* program which demonstrates the problem you are having,
and explain in detail what it's doing wrong, you are much more likely to
get useful help.
I suspect what you want is a POST returning a 302 redirect, so that a
refresh will just redo the GET, but it's impossible to be sure.
Ben
------------------------------
Date: Tue, 17 Jan 2012 11:00:02 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Searching Complex Array Values
Message-Id: <170120121100027068%jimsgibson@gmail.com>
In article
<8fa546c3-4dcb-45ad-a9df-d60771f2c40d@3g2000pbg.googlegroups.com>,
Pradeep Patra <smilesonisamal@gmail.com> wrote:
> Hi all,
> I have a complex array reference. I want to search the
> 'name'="v1" and if it matches then search for "ctrs" and then 'C-data'
> get the value of "success"?
>
> $VAR1 = [
{contents of $VAR1 snipped}
> ];
>
> I am trying to retrieve as following But it doesn't work. Am I missing
> anything in dereferencing I guess. A sample source code will help.
>
> my $a = $VAR1[0]; ---> To get "inst"
Are you using 'use strict;' and 'use warnings:'? If you did, then you
would get the following error message from Perl for the above line:
"Global symbol "@VAR1" requires explicit package name at pradeep.pl
line 66.
pradeep.pl had compilation errors."
$VAR1 is a reference to an array, not an array, so the above line needs
to be changed to:
my $a = $VAR1->[0];
> my $b = $a->{'A-data'};
$a is now a reference to a hash whose keys are 'timestamp' and 'inst'.
If you are looking for a hash element with key 'A-data', you are going
to have to go down two more levels:
my $b = $a->{inst}-=>[0]->{'A-data'};
> print "A is $a";
> print "B is $b";
$a is a reference to a hash, and $b is a reference to an array, so it
does little good to print them. You might want to use the Data::Dumper
module to print the contents of the data structures pointed to by $a
and $b.
> if ($b->{'name'} eq 'v1') {
> print "PASS";
>
> }
>
> Is there a efficient way of searching this kind then it will be
> useful?
I would worry more about your logic at this point than efficiency. It
is really hard to tell what you are trying to do.
If you want more help, please post a complete program that demonstrates
what you are trying to do and describe why it does not match your
expectations. Please also keep your lines to a reasonable number of
columns.
Thanks.
--
Jim Gibson
------------------------------
Date: Mon, 16 Jan 2012 09:59:07 +0200
From: Dr Eberhard Lisse <nospam@lisse.NA>
Subject: ssh tullen
Message-Id: <9ni3miF24kU1@mid.individual.net>
Hi,
I have a PostgreSQL database behind a firewall which I can access from a
fixed IP address but obviously not while on the road where I must issue
something like:
ssh -N -C user@host.domain.DOMAIN -L 5433/localhost/5432
and then run my script to generate the report.
I can in a slightly different context using Net::SSH issue commands
to the remote host, but I have been unable to figure out how to open a
tunnel from within the perl script (preferably with a module, but that's
not really the issue), then do my usual thing, and then close the tunnel
again.
Is this a unique problem? Or can someone point me to a code fragment
that does something like this...
el
------------------------------
Date: Mon, 16 Jan 2012 09:59:58 +0200
From: Dr Eberhard Lisse <nospam@lisse.NA>
Subject: ssh tullen
Message-Id: <9ni3nuF24kU2@mid.individual.net>
Hi,
I have a PostgreSQL database behind a firewall which I can access
from a fixed IP address but obviously not while on the road where I
must issue something like:
ssh -N -C user@host.domain.DOMAIN -L 5433/localhost/5432
(using publik/private key combination) and then run my script to
generate the report.
I can in a slightly different context using Net::SSH issue commands
to the remote host, but I have been unable to figure out how to open
a tunnel from within the perl script (preferably with a module, but
that's not really the issue), then do my usual thing, and then close
the tunnel again.
Is this a unique problem? Or can someone point me to a code
fragment that does something like this...
el
------------------------------
Date: Mon, 16 Jan 2012 12:46:59 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: ssh tullen
Message-Id: <slrnjh83hj.u80.hjp-usenet2@hrunkner.hjp.at>
On 2012-01-16 07:59, Dr Eberhard Lisse <nospam@lisse.NA> wrote:
> I have a PostgreSQL database behind a firewall which I can access from a
> fixed IP address but obviously not while on the road where I must issue
> something like:
>
> ssh -N -C user@host.domain.DOMAIN -L 5433/localhost/5432
>
> and then run my script to generate the report.
>
> I can in a slightly different context using Net::SSH issue commands
> to the remote host, but I have been unable to figure out how to open a
> tunnel from within the perl script (preferably with a module, but that's
> not really the issue), then do my usual thing, and then close the tunnel
> again.
maybe I misunderstand the problem, but have you tried simply starting
ssh in the background (with open or fork/exec) at the start of your
script and killing it at the end?
hp
--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Bill Code on asrg@irtf.org
------------------------------
Date: Tue, 17 Jan 2012 06:30:48 +0200
From: Dr Eberhard W Lisse <nospam@lisse.NA>
Subject: Re: ssh tunnel
Message-Id: <4F14F978.9090805@lisse.NA>
Haven't been able to successfully do that.
Have you got a working code fragment?
el
On 2012-01-16 13:46 , Peter J. Holzer wrote:
> On 2012-01-16 07:59, Dr Eberhard Lisse <nospam@lisse.NA> wrote:
>> I have a PostgreSQL database behind a firewall which I
>> can access from a fixed IP address but obviously not
>> while on the road where I must issue something like:
>>
>> ssh -N -C user@host.domain.DOMAIN -L
>> 5433/localhost/5432
>>
>> and then run my script to generate the report.
>>
>> I can in a slightly different context using Net::SSH
>> issue commands to the remote host, but I have been unable
>> to figure out how to open a tunnel from within the perl
>> script (preferably with a module, but that's not really
>> the issue), then do my usual thing, and then close the
>> tunnel again.
>
> maybe I misunderstand the problem, but have you tried
> simply starting ssh in the background (with open or
> fork/exec) at the start of your script and killing it at
> the end?
>
> hp
>
--
If you want to email me, replace nospam with el
------------------------------
Date: Tue, 17 Jan 2012 11:17:18 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: ssh tunnel
Message-Id: <87ipkazl8x.fsf@vps1.hacking.dk>
Dr Eberhard W Lisse <nospam@lisse.NA> writes:
>> maybe I misunderstand the problem, but have you tried
>> simply starting ssh in the background (with open or
>> fork/exec) at the start of your script and killing it at
>> the end?
>
> Haven't been able to successfully do that.
What did you try? How did it fail?
> Have you got a working code fragment?
I have written a lot of code which rather naïvely uses IPC::Open3 to run
ssh as a background process. It should work for opening a tunnel.
The problems I don't usual handle is that the initial connection often
asks whether to accept the host key. In this scenario the process just
hangs. If you just accept the hostkey by hand it works correctly.
//Makholm
------------------------------
Date: Tue, 17 Jan 2012 11:46:00 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: ssh tunnel
Message-Id: <ok3gu8-15o1.ln1@anubis.morrow.me.uk>
Quoth Peter Makholm <peter@makholm.net>:
>
> I have written a lot of code which rather naïvely uses IPC::Open3 to run
> ssh as a background process. It should work for opening a tunnel.
>
> The problems I don't usual handle is that the initial connection often
> asks whether to accept the host key. In this scenario the process just
> hangs. If you just accept the hostkey by hand it works correctly.
Try system("ssh -f -L... ... sleep 10") instead of open3. It's important
with -f to use 'sleep 10' rather than -N, otherwise the ssh process will
never exit. (It doesn't seem to be very easy to find its pid to kill it
manually.)
You can also use -oBatchMode=yes, if you'd rather it failed than prompted.
Ben
------------------------------
Date: Mon, 16 Jan 2012 10:52:54 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: Unicode-AGE of a character?
Message-Id: <160120121052540961%brian.d.foy@gmail.com>
In article <slrnjgnnos.4ik.nospam-abuse@panda.math.berkeley.edu>, Ilya
Zakharevich <nospam-abuse@ilyaz.org> wrote:
> I looked through the docs I could find, and can't find any way to
> determine the "Unicode AGE" of a particular codepoint except for:
>
> a) running /\p{Present_in: FOO}/ for all forseeable values of FOO;
Tom C. and I talked about this for a bit. You're stuck with testing
each of the age properties until you find the earliest that matches.
Or, you can go through all characters, determin their age, and create
your own properties.
I had to do this when we were tracking down some font issues for
Programming Perl. It turned out that all the problems were related to
Unicode 5 characters.
------------------------------
Date: Tue, 17 Jan 2012 10:06:05 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: When is @_ undefined?
Message-Id: <4f158e5d$6$fuzhry+tra$mr2ice@news.patriot.net>
I'm getting the message
Use of uninitialized value within @_ in join or string at
H:\UTILITY/unobfuscate.cmd line 1266.
The code prior to that line seems to be working correctly. The code in
question, up to line 1266, is
sub doURI {
my ($URI, $rawhost, $NumericDomain, $rawPath, $rawQuery, $refURI,
$refHost) = @_;
my $host = uc $rawhost;
my $path = uc $rawPath;
msg("\ndoURI(", join(', ',@_),")\n");
I can chage the code to save @_ in a local variable, but first I'd
like to understand why the value was changed. Thanks.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Tue, 17 Jan 2012 16:12:32 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: When is @_ undefined?
Message-Id: <slrnjhb7fg.11o1.willem@toad.stack.nl>
Shmuel Metz wrote:
) I'm getting the message
)
) Use of uninitialized value within @_ in join or string at
) H:\UTILITY/unobfuscate.cmd line 1266.
)
) The code prior to that line seems to be working correctly. The code in
) question, up to line 1266, is
)
) sub doURI {
) my ($URI, $rawhost, $NumericDomain, $rawPath, $rawQuery, $refURI,
) $refHost) = @_;
) my $host = uc $rawhost;
) my $path = uc $rawPath;
)
) msg("\ndoURI(", join(', ',@_),")\n");
)
) I can chage the code to save @_ in a local variable, but first I'd
) like to understand why the value was changed. Thanks.
I guess you called 'doUri' with too few arguments, or with an undef argument.
Why do you say the value was changed? The error message does not indicate that.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Tue, 17 Jan 2012 16:23:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: When is @_ undefined?
Message-Id: <msjgu8-hor1.ln1@anubis.morrow.me.uk>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> I'm getting the message
>
> Use of uninitialized value within @_ in join or string at
> H:\UTILITY/unobfuscate.cmd line 1266.
>
> The code prior to that line seems to be working correctly. The code in
> question, up to line 1266, is
>
> sub doURI {
> my ($URI, $rawhost, $NumericDomain, $rawPath, $rawQuery, $refURI,
> $refHost) = @_;
> my $host = uc $rawhost;
> my $path = uc $rawPath;
This may seem like a silly question, but what do you get if you add
defined $_[$_] or warn "\$_[$_] undefined!"
for 0..$#_;
at this point?
Ben
------------------------------
Date: Tue, 17 Jan 2012 16:57:25 +0000 (UTC)
From: tony@mountifield.org (Tony Mountifield)
Subject: Re: When is @_ undefined?
Message-Id: <jf499l$88v$1@softins.clara.co.uk>
In article <4f158e5d$6$fuzhry+tra$mr2ice@news.patriot.net>,
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid> wrote:
> I'm getting the message
>
> Use of uninitialized value within @_ in join or string at
> H:\UTILITY/unobfuscate.cmd line 1266.
>
> The code prior to that line seems to be working correctly. The code in
> question, up to line 1266, is
>
> sub doURI {
> my ($URI, $rawhost, $NumericDomain, $rawPath, $rawQuery, $refURI,
> $refHost) = @_;
> my $host = uc $rawhost;
> my $path = uc $rawPath;
>
> msg("\ndoURI(", join(', ',@_),")\n");
>
> I can chage the code to save @_ in a local variable, but first I'd
> like to understand why the value was changed. Thanks.
When you call doURI, are any of the arguments themselves undefined or absent?
You might also want to define doURI with a prototype:
sub doURI($$$$$$$) {
...etc...
}
That will enable perl to warn you if you pass the wrong number of arguments.
Cheers
Tony
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
------------------------------
Date: Tue, 17 Jan 2012 19:08:27 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: When is @_ undefined?
Message-Id: <bitgu8-vct1.ln1@anubis.morrow.me.uk>
Quoth tony@mountifield.org (Tony Mountifield):
>
> You might also want to define doURI with a prototype:
>
> sub doURI($$$$$$$) {
That's not a good idea. Prototypes are generally confusing: in this
case, a call like
doURI one(), two(), three(), ...;
will call one, two, three in scalar context, which is not what someone
reading that line would expect.
Prototypes are very useful for making functions that look like builtins,
and are used analogously to the builtin so people get the idea; in other
situations they should be avoided. An obvious example would be something
like
sub hpush (\%@) {
my ($href, @new) = @_;
%$href = (%$href, @new);
}
where it's obvious (from the name) that this is analogous to push, so
it's not surprising
hpush %h, one => 2;
treats its first argument specially. (I'm not considering the question
of whether or not that particular function is a good idea; just whether
or not it should have a prototype.) Another example would be Scalar::
Util::refaddr, which has a ($) prototype since it's used exactly like
ref().
If you want to check your arguments, do so at runtime. (Perl 5 is a
dynamic language; that means most consistency checks get delayed to
runtime.)
sub doURI {
@_ == 7 or croak "doURI needs 7 arguments";
(Of course, missing an argument isn't the same as passing undef...)
Ben
------------------------------
Date: Tue, 17 Jan 2012 19:39:39 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: When is @_ undefined?
Message-Id: <87zkdm3ypw.fsf@sapphire.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth tony@mountifield.org (Tony Mountifield):
>>
>> You might also want to define doURI with a prototype:
>>
>> sub doURI($$$$$$$) {
>
> That's not a good idea. Prototypes are generally confusing: in this
> case, a call like
>
> doURI one(), two(), three(), ...;
>
> will call one, two, three in scalar context, which is not what someone
> reading that line would expect.
>
> Prototypes are very useful for making functions that look like builtins,
> and are used analogously to the builtin so people get the idea; in other
> situations they should be avoided. An obvious example would be something
> like
>
> sub hpush (\%@) {
> my ($href, @new) = @_;
> %$href = (%$href, @new);
> }
>
> where it's obvious (from the name) that this is analogous to push,
That's obvious to you and you only because you wrote it. And you can't
have it both ways: Either, prototypes are bad because they can (among
other things) enforce scalar context in a situation when the language
defaults to list context. Then, they are always bad and not bad when
someone else uses them to accomplish something different (call
checking at compile time) and good when you use them to enforce scalar
context.
------------------------------
Date: Tue, 17 Jan 2012 19:58:49 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: When is @_ undefined?
Message-Id: <20120117115112.511@kylheku.com>
On 2012-01-17, Ben Morrow <ben@morrow.me.uk> wrote:
> If you want to check your arguments, do so at runtime. (Perl 5 is a
> dynamic language; that means most consistency checks get delayed to
> runtime.)
>
> sub doURI {
> @_ == 7 or croak "doURI needs 7 arguments";
"Delayed to run time" is quite different from "deferred to the programmer".
The latter is not general principle in dynamic languages.
------------------------------
Date: Tue, 17 Jan 2012 21:37:39 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: When is @_ undefined?
Message-Id: <3a6hu8-bcv1.ln1@anubis.morrow.me.uk>
Quoth Kaz Kylheku <kaz@kylheku.com>:
> On 2012-01-17, Ben Morrow <ben@morrow.me.uk> wrote:
> > If you want to check your arguments, do so at runtime. (Perl 5 is a
> > dynamic language; that means most consistency checks get delayed to
> > runtime.)
> >
> > sub doURI {
> > @_ == 7 or croak "doURI needs 7 arguments";
>
>
> "Delayed to run time" is quite different from "deferred to the programmer".
>
> The latter is not general principle in dynamic languages.
...no...? I don't understand what you're trying to say. AFAICS the
principle differences between
sub doURI ($$$$$$$) {
and
sub doURI {
@_ == 7 or croak "doURI needs 7 arguments";
are whether the check happens at compile- or runtime, whether it has any
weird effects on the contexts of the arguments, and whether the
programmer has any control over the error message. In both cases the
programmer has to realise this sub needs to be called with 7 arguments,
and decide to enforce that.
If you are saying you would rather be able to write
sub doURI ($one, $two, $three) {
and get the behaviour of
sub doURI {
@_ == 3 or croak "doURI needs 3 arguments";
my ($one, $two, $three) = @_;
then I agree: that's a known deficiency in Perl 5. Some people are
working quite hard to solve it without breaking anything (as usual, this
is *much* harder than it sounds); see Method::Signatures and the other
modules referenced from that module's SEE ALSO section.
Ben
------------------------------
Date: Tue, 17 Jan 2012 22:18:48 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: When is @_ undefined?
Message-Id: <87mx9m3rcn.fsf@sapphire.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Kaz Kylheku <kaz@kylheku.com>:
>> On 2012-01-17, Ben Morrow <ben@morrow.me.uk> wrote:
>> > If you want to check your arguments, do so at runtime. (Perl 5 is a
>> > dynamic language; that means most consistency checks get delayed to
>> > runtime.)
>> >
>> > sub doURI {
>> > @_ == 7 or croak "doURI needs 7 arguments";
>>
>>
>> "Delayed to run time" is quite different from "deferred to the programmer".
>>
>> The latter is not general principle in dynamic languages.
>
> ...no...? I don't understand what you're trying to say. AFAICS the
> principle differences between
>
> sub doURI ($$$$$$$) {
>
> and
>
> sub doURI {
> @_ == 7 or croak "doURI needs 7 arguments";
>
> are whether the check happens at compile- or runtime, whether it has any
> weird effects on the contexts of the arguments, and whether the
> programmer has any control over the error message.
The main difference is that the runtime check needs to be coded
explicitly.
------------------------------
Date: Tue, 17 Jan 2012 22:33:02 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: When is @_ undefined?
Message-Id: <jf4sut$3a4$1@reader1.panix.com>
In article <87mx9m3rcn.fsf@sapphire.mobileactivedefense.com>,
Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>Ben Morrow <ben@morrow.me.uk> writes:
>
>> Quoth Kaz Kylheku <kaz@kylheku.com>:
>>> On 2012-01-17, Ben Morrow <ben@morrow.me.uk> wrote:
>>> > If you want to check your arguments, do so at runtime. (Perl 5 is a
>>> > dynamic language; that means most consistency checks get delayed to
>>> > runtime.)
>>> >
>>> > sub doURI {
>>> > @_ == 7 or croak "doURI needs 7 arguments";
>>>
>>>
>>> "Delayed to run time" is quite different from "deferred to the programmer".
>>>
>>> The latter is not general principle in dynamic languages.
>>
>> ...no...? I don't understand what you're trying to say. AFAICS the
>> principle differences between
>>
>> sub doURI ($$$$$$$) {
>>
>> and
>>
>> sub doURI {
>> @_ == 7 or croak "doURI needs 7 arguments";
>>
>> are whether the check happens at compile- or runtime, whether it
>> has any weird effects on the contexts of the arguments, and whether
>> the programmer has any control over the error message.
>
>The main difference is that the runtime check needs to be coded
>explicitly.
Hm, that's an interesting ambiguity in "needs" in English. If you
mean "the runtime check needs to be coded explicitly; in contrast, a
non-runtime check doesn't need to be coded explicitly", then I
consider "($$$$$$$)" to be an explicit coding, though it's obviously
much shorter, much easier, and has a much more uniform error message.
If you mean "because of Perl 5's design, you need to code the runtime
check explicitly or you're in danger", I think I agree.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Tue, 17 Jan 2012 22:51:25 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: When is @_ undefined?
Message-Id: <87aa5m3pua.fsf@sapphire.mobileactivedefense.com>
tmcd@panix.com (Tim McDaniel) writes:
> Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>>Ben Morrow <ben@morrow.me.uk> writes:
[...]
>>> ...no...? I don't understand what you're trying to say. AFAICS the
>>> principle differences between
>>>
>>> sub doURI ($$$$$$$) {
>>>
>>> and
>>>
>>> sub doURI {
>>> @_ == 7 or croak "doURI needs 7 arguments";
>>>
>>> are whether the check happens at compile- or runtime, whether it
>>> has any weird effects on the contexts of the arguments, and whether
>>> the programmer has any control over the error message.
>>
>>The main difference is that the runtime check needs to be coded
>>explicitly.
>
> Hm, that's an interesting ambiguity in "needs" in English. If you
> mean "the runtime check needs to be coded explicitly; in contrast, a
> non-runtime check doesn't need to be coded explicitly", then I
> consider "($$$$$$$)" to be an explicit coding,
But it isn't. It's a declaration which modifies the behaviour of the
compiler based on stating an intent ('When calling this subroutine,
seven parameters have to be supplied and they are supposed to be
evaluated in scalar context'). In contrast to this, the second example
is a piece of executable code which represents one (of many) ways how
the intent 'ensure that there are seven arguments' can be
implemented. Another would be
die('Thou shalt not treat me in such ways !!1')
unless @_ == 7;
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3591
***************************************