[25670] in Perl-Users-Digest
Perl-Users Digest, Issue: 7911 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 29 12:37:04 2005
Date: Tue, 29 Mar 2005 09:36:56 -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, 29 Mar 2005 Volume: 10 Number: 7911
Today's topics:
Re: FAQ 7.15 How do I create a static variable? <nobull@mail.com>
Re: FAQ 7.15 How do I create a static variable? <nobull@mail.com>
Re: FAQ 7.15 How do I create a static variable? <nobull@mail.com>
Re: FAQ 8.40 How do I avoid zombies on a Unix system? <dha@panix.com>
ftp nmap support in Net::FTP (bala)
Re: ftp nmap support in Net::FTP <mpapec@nohome.com>
Re: ftp nmap support in Net::FTP <spamtrap@dot-app.org>
Re: ftp nmap support in Net::FTP <spamtrap@dot-app.org>
Re: ftp nmap support in Net::FTP bbmk1234@yahoo.co.uk
Re: ftp nmap support in Net::FTP axel@white-eagle.invalid.uk
Re: ftp nmap support in Net::FTP <mpapec@foobar.com>
function privileges <bob@myhost.com>
Re: function privileges <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Getting the word to conventional programmers <cnelson@nycap.rr.com>
Re: Help for newbie <sverro@algonet.se>
Re: Help for newbie <jgibson@mail.arc.nasa.gov>
Re: Help for newbie <someone@example.com>
Re: Help for newbie <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 28 Mar 2005 11:56:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 7.15 How do I create a static variable?
Message-Id: <d28r2s$12u$1@sun3.bham.ac.uk>
PerlFAQ Server wrote:
>
> 7.15: How do I create a static variable?
>
> As with most things in Perl, TMTOWTDI. What is a "static variable" in
> other languages could be either a function-private variable (visible
> only within a single function, retaining its value between calls to that
> function), or a file-private variable (visible only to functions within
> the file it was declared in) in Perl.
>
> Here's code to implement a function-private variable:
>
> BEGIN {
> my $counter = 42;
> sub prev_counter { return --$counter }
> sub next_counter { return $counter++ }
> }
>
> Now prev_counter() and next_counter() share a private variable $counter
That does not match the description given in the previous paragraph "a
function-private variable (visible only within a _single_ function)".
Either the example or the preceeding paragraph needs to be changed in
order for them to be consistant. I think it's better to say "a small
number of functions" and leave it as an exercise for the reader to
realise that 1 is a small number.
> that was initialized at compile time.
The BEGIN is redundant unless these functions are to be called within
later BEGIN blocks. I think if you are going to include it you should
explain why it is there.
> To declare a file-private variable, you'll still use a my(), putting the
> declaration at the outer scope level at the top of the file. Assume this
> is in file Pax.pm:
>
> package Pax;
> my $started = scalar(localtime(time()));
>
> sub begun { return $started }
To be consistant with the first example that should allow for the
possibility that begun() is to be called withing a BEGIN {}.
my $started;
BEGIN { $started = scalar(localtime(time())) }
Anyhow the whole function-private v. file-private distinction is
artificial. Better just to refer to them as private persistant
variables and be done with it. And since once we remove the artifical
distiction the FAQ shows only one way the whole thing gets a lot simpler.
7.15: How do I create a static variable?
What is a "static variable" in other languages is termed
a "Persistent Private Variable" in Perl. See perlsub
for details.
Persistent private variables may be shared by a small number of
functions by declaring them within a block:
BEGIN {
my $counter = 42;
sub prev_counter { return --$counter }
sub next_counter { return $counter++ }
}
Unless prev_counter() or next_counter() are to be called from
within subsequent BEGIN blocks it is not necessary to make
the above block a BEGIN block. Usually a bare block will do.
Alternatively persistent private variables can be shared by the
whole of the rest of the file by putting the declaration at the
outer scope. Assume this is in file Pax.pm:
package Pax;
my $started;
BEGIN { $started = scalar(localtime(time())); }
sub begun { return $started }
When "use Pax" or "require Pax" loads this module, the variable
will beinitialized. It won't get garbage-collected the way most
variables going out of scope do, because the begun() function
references it. It is not called $Pax::started because its scope
is unrelated to the package. It is scoped to the file. You could
conceivably have several packages in the file all accessing the
private variable, but another file with the same package couldn't
get to it.
Again, the BEGIN block is usually not necessary. It would
usually be sufficient to initialise $started in the declaration.
Actually maybe this is too verbose for the FAQ and it would be better
just to say:
7.15: How do I create a static variable?
What is a "static variable" in other languages is termed
a "Persistent Private Variable" in Perl. See perlsub.
------------------------------
Date: Mon, 28 Mar 2005 21:31:28 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 7.15 How do I create a static variable?
Message-Id: <d29sok$hbg$1@sun3.bham.ac.uk>
brian d foy wrote:
> In article <d28r2s$12u$1@sun3.bham.ac.uk>, Brian McCauley
> <nobull@mail.com> wrote:
>
>
>>PerlFAQ Server wrote:
>
>
>>>7.15: How do I create a static variable?
>
>
>>> Here's code to implement a function-private variable:
>
>
>>> BEGIN {
>>> my $counter = 42;
>>> sub prev_counter { return --$counter }
>>> sub next_counter { return $counter++ }
>>> }
>
>
>>> Now prev_counter() and next_counter() share a private variable $counter
>
>
>>The BEGIN is redundant unless these functions are to be called within
>>later BEGIN blocks. I think if you are going to include it you should
>>explain why it is there.
>
>
> We could explain why it's there. It's certainly not redundant (since it
> doesn't repeat anything that already does the same thing):#
No, that's not the (only) definition of redundant. Something is
redundant if its removal would not make a significant difference.
> it's there to provide the scope
No, the block alone does that.
> and to make sure that stuff happens before runtime starts.
Which, typically is not necessary.
> That's the documented behavior of BEGIN, after all :)
Yes I know what BEGIN does. If you disagree with me
can you say why you think the variable needs to be
initializes at compile time?
>>> package Pax;
>>> my $started = scalar(localtime(time()));
>>>
>>> sub begun { return $started }
>>
>>To be consistant with the first example that should allow for the
>>possibility that begun() is to be called withing a BEGIN {}.
>
>
> That wouldn't create a file-scoped variable though,
What wouldn't? Did you actually look at the example in my post?
> and subroutines are already defined at compile time.
This is true but I can't understand why you think this is relevant.
> You don't need the BEGIN there
Can you now explain why if you think the first variable needed
to be initialized at compile time why you think the second one doesn't?
------------------------------
Date: Tue, 29 Mar 2005 08:42:27 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 7.15 How do I create a static variable?
Message-Id: <d2b42o$41j$1@sun3.bham.ac.uk>
brian d foy wrote:
> In article <d29sok$hbg$1@sun3.bham.ac.uk>, Brian McCauley
> <nobull@mail.com> wrote:
>
>>> [...] to make sure that stuff happens before runtime starts.
>>
>>Which, typically is not necessary.
>
>
> It is necessary if you want the "usual" behaviour of subroutines.
> People expect a subroutine definition to take place at compile time,
> and that they can put them anywhere they like. Without a BEGIN,
> I'd have to explain why this doesn't work as you say it should:
>
> foreach ( 1 .. 10 )
> {
> print "Counter is " . counter() . "\n";
> }
>
> {
> my $counter = 42;
> sub counter { return $counter++ }
> }
Yeah, I woke up in the middle of the night with that code in my head and
thought, "$EXPLETIVE, what did I say to brian".
> Again, BEGIN is not redundant, because the behavior is different
> without it. You have to remember that other people are going
> to put this stuff into their code, and you have to anticipate the
> mistakes they are going to make.
Yes, I essentially never put outermost scope procedural code (other than
trivial variable initializations) before subroutine definitions in a
source file. I forget that other people do.
> The BEGIN does that, and I'm leaving it in the answer.
I did not intend to suggest that you should not.
------------------------------
Date: Sat, 26 Mar 2005 21:04:59 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: FAQ 8.40 How do I avoid zombies on a Unix system?
Message-Id: <slrnd4bjjr.3qf.dha@panix2.panix.com>
On 2005-03-26, brian d foy <comdog@panix.com> wrote:
> In article <zBQ0e.11250$C7.8291@news-server.bigpond.net.au>, Peter Wyzl
><wyzelli@yahoo.com> wrote:
>
>> use Acme::Buffy; # No more Zombies for me...
>
> Buffy gets rid of zombies, but they always seem to come back, and
> in greater numbers. She certainly doesn't avoid them. :)
And really, although she has had to deal with them occasionally,zombies
aren't really part of her job description... :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
i like Sample A because it tastes great and is less typing.
- brian d foy in c.l.p.misc
------------------------------
Date: 25 Mar 2005 03:35:24 -0800
From: bbmk1234@yahoo.co.uk (bala)
Subject: ftp nmap support in Net::FTP
Message-Id: <629b670a.0503250335.73e0bbaf@posting.google.com>
Do you know why Net::FTP does not support nmap?
Is ther any other package that supports nmap ftp command for filename mapping.
Thanks.
------------------------------
Date: Fri, 25 Mar 2005 15:16:39 +0100
From: Matija Papec <mpapec@nohome.com>
Subject: Re: ftp nmap support in Net::FTP
Message-Id: <h47841trpd29hso6q7q1ui88cd5hdep62r@4ax.com>
On 25 Mar 2005 03:35:24 -0800, bbmk1234@yahoo.co.uk (bala) wrote:
>Do you know why Net::FTP does not support nmap?
>
>Is ther any other package that supports nmap ftp command for filename mapping.
I'm not sure what are you referring to, is there actually "nmap"
command in ftp RFC?
------------------------------
Date: Fri, 25 Mar 2005 12:18:04 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: ftp nmap support in Net::FTP
Message-Id: <O4SdnVg2849T2tnfRVn-oQ@adelphia.com>
Matija Papec wrote:
> I'm not sure what are you referring to, is there actually "nmap"
> command in ftp RFC?
No, but there is one listed in the man page for the command-line FTP client
that I have:
nmap [inpattern outpattern]
Set or unset the filename mapping mechanism. If no arguments
are specified, the filename mapping mechanism is unset. If
arguments are specified, remote filenames are mapped during
mput commands and put commands issued without a specified
remote target filename.
It sounds like it could be a handy feature for the Net::FTP module to have.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 25 Mar 2005 12:20:45 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: ftp nmap support in Net::FTP
Message-Id: <O4SdnVs284_w1dnfRVn-oQ@adelphia.com>
Matija Papec wrote:
> On 25 Mar 2005 03:35:24 -0800, bbmk1234@yahoo.co.uk (bala) wrote:
>
>>Is ther any other package that supports nmap ftp command for filename
>>mapping.
>
> I'm not sure what are you referring to, is there actually "nmap"
> command in ftp RFC?
Heh... I just noticed, the OP said "ftp command", not "FTP command". That
is, he's talking about a client, not the protocol. Case-sensitivity - it's
not just for PERL any more! :-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 26 Mar 2005 06:36:57 -0800
From: bbmk1234@yahoo.co.uk
Subject: Re: ftp nmap support in Net::FTP
Message-Id: <1111847817.572667.244550@o13g2000cwo.googlegroups.com>
Sherm Pendley wrote:
> Matija Papec wrote:
>
> > I'm not sure what are you referring to, is there actually "nmap"
> > command in ftp RFC?
>
> No, but there is one listed in the man page for the command-line FTP
client
> that I have:
>
> nmap [inpattern outpattern]
> Set or unset the filename mapping mechanism. If no arguments
> are specified, the filename mapping mechanism is unset. If
> arguments are specified, remote filenames are mapped during
> mput commands and put commands issued without a specified
> remote target filename.
>
> It sounds like it could be a handy feature for the Net::FTP module to
have.
>
> sherm--
>
> --
> Cocoa programming in Perl: http://camelbones.sourceforge.net
> Hire me! My resume: http://www.dot-app.org
You are spot on. Not sure why Graham Barr decided not to provide this
in Net::FTP.
------------------------------
Date: Sat, 26 Mar 2005 17:13:32 -0600
From: axel@white-eagle.invalid.uk
Subject: Re: ftp nmap support in Net::FTP
Message-Id: <d5WdnaZ079YBcdjfRVn-uw@adelphia.com>
bala <bbmk1234@yahoo.co.uk> wrote:
> Do you know why Net::FTP does not support nmap?
> Is ther any other package that supports nmap ftp command for filename mapping.
Why would you need it since s/// can do the same thing?
Axel
------------------------------
Date: Tue, 29 Mar 2005 12:21:06 +0200
From: Matija Papec <mpapec@foobar.com>
Subject: Re: ftp nmap support in Net::FTP
Message-Id: <1hu2ya95gfzde$.191b2yo2ztp9d$.dlg@40tude.net>
On Fri, 25 Mar 2005 12:20:45 -0500, Sherm Pendley wrote:
>>>Is ther any other package that supports nmap ftp command for filename
>>>mapping.
>>
>> I'm not sure what are you referring to, is there actually "nmap"
>> command in ftp RFC?
>
> Heh... I just noticed, the OP said "ftp command", not "FTP command". That
> is, he's talking about a client, not the protocol. Case-sensitivity - it's
> not just for PERL any more! :-)
:) true, although I'm not sure if OP intentionally wrote with small caps.
------------------------------
Date: Tue, 29 Mar 2005 02:55:11 +0000 (UTC)
From: Mr Bob <bob@myhost.com>
Subject: function privileges
Message-Id: <Xns962897DFDCBA8someonemicrosoftcom@203.109.252.31>
Hi, I'm wanting a user script to use Net::Ping to send an icmp packet but
can't because of privileges, is there anyway I can get around this?. I
guess an alternative is to use system("ping -c 1 $host"); or whatever, but
I'd rather not.
Thanks.
NB: Noob.
------------------------------
Date: Mon, 28 Mar 2005 20:54:10 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: function privileges
Message-Id: <jl3nh2xuhh.ln2@goaway.wombat.san-francisco.ca.us>
On 2005-03-29, Mr Bob <bob@myhost.com> wrote:
> Hi, I'm wanting a user script to use Net::Ping to send an icmp packet but
> can't because of privileges, is there anyway I can get around this?
Yes--it's in the docs for Net::Ping, in the paragraph that describes
what happens whe you specify icmp as the protocol.
> I guess an alternative is to use system("ping -c 1 $host"); or whatever, but
> I'd rather not.
Again, reading the Net::Ping docs, you can try to install and use
Net::Ping::External, if you don't want to use system().
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information
------------------------------
Date: 23 Mar 2005 05:01:51 -0800
From: "Christopher Nelson" <cnelson@nycap.rr.com>
Subject: Re: Getting the word to conventional programmers
Message-Id: <1111582911.184737.100490@z14g2000cwz.googlegroups.com>
Hey, Jeff Hobbs got the last word. ;-)
------------------------------
Date: Sat, 26 Mar 2005 01:21:09 +0100
From: Sverre Furberg <sverro@algonet.se>
Subject: Re: Help for newbie
Message-Id: <d22a51$e0c$1@yggdrasil.glocalnet.net>
Tad McClellan skrev:
> Use one of Randal's rules:
>
> use split() if you want to say what to throw out.
>
> use m//g in list context if you want to say what to keep.
>
> I'd go with the 2nd one here:
>
> my @words = /(\w+)/g;
Another newbie question:
Has the parentheses around '\w+' a special meaning in this particular case?
Sverre
------------------------------
Date: Fri, 25 Mar 2005 17:58:35 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Help for newbie
Message-Id: <250320051758350964%jgibson@mail.arc.nasa.gov>
In article <d22a51$e0c$1@yggdrasil.glocalnet.net>, Sverre Furberg
<sverro@algonet.se> wrote:
> Tad McClellan skrev:
> > Use one of Randal's rules:
> >
> > use split() if you want to say what to throw out.
> >
> > use m//g in list context if you want to say what to keep.
> >
> > I'd go with the 2nd one here:
> >
> > my @words = /(\w+)/g;
>
> Another newbie question:
> Has the parentheses around '\w+' a special meaning in this particular case?
The parentheses surrounding what is being captured and returned by the
match and assigned to the elements of @words. As a side-effect, the
contents of the original string that match the sub-pattern(s) inside
the parenthese are put into the variables $1, $2, etc., for as many
pairs of parentheses as are in the regular expression.
Since in this case the parentheses surround the entire pattern and the
/g modifier is being used, the parentheses could be left out. If,
however, you wanted to capture only the first letter in each word, you
could do
my @initials = /(\w)\w*/g;
See 'perldoc perlop' and search for "Regex".
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Sat, 26 Mar 2005 04:18:51 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help for newbie
Message-Id: <Lo51e.7450$x8.146@edtnps90>
Sverre Furberg wrote:
> Tad McClellan skrev:
>
>> Use one of Randal's rules:
>>
>> use split() if you want to say what to throw out.
>>
>> use m//g in list context if you want to say what to keep.
>>
>> I'd go with the 2nd one here:
>>
>> my @words = /(\w+)/g;
>
> Another newbie question:
> Has the parentheses around '\w+' a special meaning in this particular case?
Not in this particular case:
$ perl -le'$_ = q/abc&^%def ghi/; my @words = /(\w+)/g; print for @words'
abc
def
ghi
$ perl -le'$_ = q/abc&^%def ghi/; my @words = /\w+/g; print for @words'
abc
def
ghi
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 25 Mar 2005 23:51:03 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help for newbie
Message-Id: <slrnd49u27.1js.tadmc@magna.augustmail.com>
Sverre Furberg <sverro@algonet.se> wrote:
> Tad McClellan skrev:
>> my @words = /(\w+)/g;
>
> Another newbie question:
> Has the parentheses around '\w+' a special meaning in this particular case?
No.
my @words = /\w+/g;
would work the same.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 7911
***************************************