[24680] in Perl-Users-Digest
Perl-Users Digest, Issue: 6842 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 6 14:10:48 2004
Date: Fri, 6 Aug 2004 11:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 6 Aug 2004 Volume: 10 Number: 6842
Today's topics:
Re: Kqueue interface module implementation (U. A. R. Ruirarchzatrea)
Re: mkdir() fails to apply correct permissions <me@privacy.net>
Re: mkdir() fails to apply correct permissions (Randall Perry)
Re: mkdir() fails to apply correct permissions <noreply@gunnar.cc>
Re: modifying @ISA <nobull@mail.com>
need to replace one segment of an IP <kreiss3@optonline.net>
Re: need to replace one segment of an IP <gifford@umich.edu>
Re: need to replace one segment of an IP <jgibson@mail.arc.nasa.gov>
Re: need to replace one segment of an IP <nobull@mail.com>
Re: perl <sbryce@scottbryce.com>
Set ENV on different session (Matti)
Re: Set ENV on different session <Juha.Laiho@iki.fi>
Re: Set ENV on different session <gifford@umich.edu>
transforming german characters <me@example.com>
Re: using nested foreach loops <paul@beckingham.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Aug 2004 10:38:00 -0700
From: millueradfa@yahoo.com (U. A. R. Ruirarchzatrea)
Subject: Re: Kqueue interface module implementation
Message-Id: <efa550f7.0408060938.2600dca@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7brhq4cvm.fsf@mail.sysarch.com>...
> >>>>> "UARR" == U A R Ruirarchzatrea <millueradfa@yahoo.com> writes:
>
> UARR> Uri Guttman <uri@stemsystems.com> wrote in message news:<x73c33bigg.fsf@mail.sysarch.com>...
> i don't think you got what i meant. wrap libevent in perl and then stem
> and poe and others can use libevent which already wraps kqueue and
> several other things. for the amount of work to just wrap kqueue in
> perl, you get several event interfaces in perl by wrapping libevent.
>
> focus your effort where it will do the most good and libevent is that
> for you.
>
> uri
I think that doing a libevent wrapper is a good idea, however, there
still needs to be a direct interface to Kqueue for various reasons,
especially if a Perl programmer wants to be able to write the event
loop in Perl. It should be a purely trivial task to wrap Kqueue in a
wrapper for an XS expert, I see no reason not to.
Furthermore, it does not seem that libevent supports all of Kqueue
features.
------------------------------
Date: Fri, 6 Aug 2004 22:20:31 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: mkdir() fails to apply correct permissions
Message-Id: <2nh4blFp3u7U1@uni-berlin.de>
"Randall Perry" <rgp@systame.com> wrote in message
news:fac8f6c0.0408051143.67e07f5f@posting.google.com...
> I've got a perl script, run by root, with the following command:
> mkdir("cgi-bin", 0770) || die "Couldn't create cgi-bin dir.\n";
>
> The directory is created ok, but the perms are 0750 . Is this a perl
> bug? I'm using 5.8.4.
Not a bug, just a problem with you reading the documentation.
$ perldoc -f mkdir
mkdir FILENAME,MASK
mkdir FILENAME
Creates the directory specified by FILENAME, with permissions
specified by MASK (as modified by "umask"). If it succeeds it
returns true, otherwise it returns false and sets $! (errno). If
omitted, MASK defaults to 0777.
In general, it is better to create directories with permissive
MASK, and let the user modify that with their "umask", than it
is to supply a restrictive MASK and give the user no way to be
more permissive. The exceptions to this rule are when the file
or directory should be kept private (mail files, for instance).
The perlfunc(1) entry on "umask" discusses the choice of MASK in
more detail.
------------------------------
Date: 6 Aug 2004 07:51:37 -0700
From: rgp@systame.com (Randall Perry)
Subject: Re: mkdir() fails to apply correct permissions
Message-Id: <fac8f6c0.0408060651.3892e6da@posting.google.com>
Thanks guys.
------------------------------
Date: Fri, 06 Aug 2004 16:56:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: mkdir() fails to apply correct permissions
Message-Id: <2nhkgeF120feU1@uni-berlin.de>
Randall Perry wrote:
> I've got a perl script, run by root, with the following command:
> mkdir("cgi-bin", 0770) || die "Couldn't create cgi-bin dir.\n";
>
> The directory is created ok, but the perms are 0750 .
As others have explained, your stated permissions are modified by
umask. To have the resulting permissions equal your stated
permissions, you can add
umask 0;
to your script somewhere before the mkdir statement. Another
possibility is to set the permissions with chmod() instead.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 06 Aug 2004 18:19:15 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: modifying @ISA
Message-Id: <cf0eb1$16e$1@sun3.bham.ac.uk>
Gibbering Poster wrote:
> Hey .. i'm playing around with the silly idea (yah I know) of writing a
> roguelike in Perl, and had a quick question about dynamic multiple
> inheritance.
>
> I have a main IO Handler object called Handler. When the game is started,
> it checks your OS, and returns you an object of class Handler::Win or
> Handler::Linux depending on what $^O contains. So far, so good.
No, but I'll explain why later.
> The main Handler super-object contains methods to return objects like
> player, map, etc for the child handler, so he can know how to paint the
> screen and such.
>
> I've decided that I'd like to be able to subclass the handler on levels
> other than the OS. I'd like to have:
>
> Handler::DungeonMovement
> Handler::PlayerCreation
> Handler::Inventory
> Handler::Prompt
> etc....
>
> What I was thinking I would do is morph the object as I needed to change the
> handler object. For instance, When the game starts, the win32 handler adds
> Handler::PlayerCreation to its @ISA list so that one can choose
No, you have got the wrong end of the stick.
@ISA describes (static) interhitance relationships between _classes_ not
_objects_. You should mess with it like this. If you have an object
that wants to morph from one class into a one of it's child classes you
can simply re-bless it although this can mke for rather incoprehensible
code.
In fact the only time you would usually have anything other than a
totally static @ISA is in cases like of your Handler::Linux and
Handler::Win32 as the OS is not going to change withing the lifetime of
the process.
Your basic Handler object should simply be of class Handler. Subclasses
should inherit from that.
i.e.
@Handler::DungeonMovement::ISA = qw( Handler );
# etc...
but the classes Handler::Linux and Handler::Win32 are not decendants of
Handler in the class hierachy - they are alternate parents!
> Here's some code that demonstrates a constuctor for the main super Handler
> class that will create the proper OS handler, then TRY to immediatly throw
> them into 'movement' mode, by trying to twiddle @ISA:
>
> sub new ($$) {
Constructors in Perl are conventionaly called as class methods. Methods
don't have prototypes in Perl.
> my ($handler, $mode) = @_;
>
> if ($^O =~ /win/i) {
> $handler = Handler::Win -> new;
> } else {
> $handler = Handler::Unix -> new;
> }
> if ($mode eq 'movement') {
> push @$handler::ISA => 'Movement';
> }
> return $handler;
> }
>
> I KNOW that push line is ridiculously wrong syntactically,
The syntax is not nearly as ridiculous as the semantics.
The Handler class should tune it's @ISA at compile time.
package Handler;
BEGIN {
if ($^O =~ /win/i) {
# May want to require Handler::Win;
@ISA = qw ( Handler::Win );
} else {
# May want to require Handler::Unix;
$handler = Handler::Unix -> new;
}
}
sub os_specific_init {
# Nothing!
}
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->os_specific_init;
$self;
}
package Handler::Win;
sub os_specific_init {
my $self = shift;
# Do windows specific bit.
}
Or somesuch approach. As ever TIMTOWTDI.
Do not pass $mode as an argument to Handle->new.
Instead just call Handler::DungeonMovement->new.
This method call will in fact resolve as subroutine call
Handle::new('Handler::DungeonMovement') which will construct a
Handler::DungeonMovement object.
------------------------------
Date: Fri, 06 Aug 2004 12:05:50 -0400
From: kreiss <kreiss3@optonline.net>
Subject: need to replace one segment of an IP
Message-Id: <pan.2004.08.06.16.05.49.197000@optonline.net>
for an admin script, I would like to replace the fourth octet of
an IP, ie: 192.168.0.10 would become 192.168.0.20.
there must be an easy way to do this with a scalar that I am just too
dense to find myself. any help would be appreciated.
------------------------------
Date: 06 Aug 2004 12:43:46 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: need to replace one segment of an IP
Message-Id: <qszvffw43p9.fsf@rygar.gpcc.itd.umich.edu>
kreiss <kreiss3@optonline.net> writes:
> for an admin script, I would like to replace the fourth octet of
> an IP, ie: 192.168.0.10 would become 192.168.0.20.
>
> there must be an easy way to do this with a scalar that I am just too
> dense to find myself. any help would be appreciated.
If you have the IP address as a string in $ip and the last octet in a
variable called $hostnum, you could simply do
$ip =~ s/\d+$/$hostnum/;
-----ScottG.
------------------------------
Date: Fri, 06 Aug 2004 10:06:29 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: need to replace one segment of an IP
Message-Id: <060820041006293394%jgibson@mail.arc.nasa.gov>
In article <pan.2004.08.06.16.05.49.197000@optonline.net>, kreiss
<kreiss3@optonline.net> wrote:
> for an admin script, I would like to replace the fourth octet of
> an IP, ie: 192.168.0.10 would become 192.168.0.20.
>
> there must be an easy way to do this with a scalar that I am just too
> dense to find myself. any help would be appreciated.
Are your IP address in string format?
If so:
my $string = "192.168.0.10";
my $newhost = '20';
$string =~ s/\d+$/$newhost/;
If they are in 32-bit binary, you can unpack them, modify the fourth
byte, and repack them.
------------------------------
Date: Fri, 06 Aug 2004 18:37:16 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: need to replace one segment of an IP
Message-Id: <cf0fcp$1o5$1@sun3.bham.ac.uk>
kreiss wrote:
> for an admin script, I would like to replace the fourth octet of
> an IP, ie: 192.168.0.10 would become 192.168.0.20.
>
> there must be an easy way to do this with a scalar that I am just too
> dense to find myself. any help would be appreciated.
Your problem is that you've not analysed your problem. The description
you've given is totally inadequate for anyone to figure out what you
actually want to do. Before you can implement anything in any language
you need first to be able to describe what it is you want to do.
Random shot in the dark: You want to add 10 to the last element any
dotted quad in a string.
s/(\d+\.\d+\.\d+\.)(\d+)/$1.($2+10)/eg;
I've assumed here that we don't care what happen to longer dotted
sequences of digits.
------------------------------
Date: Fri, 06 Aug 2004 08:45:55 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: perl
Message-Id: <10h76d4tcjlmv24@corp.supernews.com>
sahmed it pro wrote:
> help me for statring perl code understanding
> and how to run perl prog. in my system.
It would help to know what system you have.
------------------------------
Date: 6 Aug 2004 03:36:28 -0700
From: xmrf@yahoo.de (Matti)
Subject: Set ENV on different session
Message-Id: <a4b6eb66.0408060236.3ef40f2e@posting.google.com>
Hello,
I need to set an Environment Variable which will be used by a script
started in a different session (not child process of the script which
has set the Env). So I need something like "exporting" the environment
setting I performed in my perl script. Is this somehow possible?
Thanks,
AndyW.
------------------------------
Date: Fri, 06 Aug 2004 13:42:03 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Set ENV on different session
Message-Id: <cf01km$86t$1@ichaos.ichaos-int>
xmrf@yahoo.de (Matti) said:
>I need to set an Environment Variable which will be used by a script
>started in a different session (not child process of the script which
>has set the Env). So I need something like "exporting" the environment
>setting I performed in my perl script. Is this somehow possible?
You cannot force such changes upon an unrelated process (without
co-operation of the said process). What you could do is to arrange some
form or IPC (interprocess communication) between the two processes; the
simplest form being to have the first process write a file with the
desired settings, and making the other process to check for the file
existence and read it at the appropriate point in execution.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: 06 Aug 2004 11:05:13 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: Set ENV on different session
Message-Id: <qszoelo5mty.fsf@rygar.gpcc.itd.umich.edu>
xmrf@yahoo.de (Matti) writes:
> I need to set an Environment Variable which will be used by a script
> started in a different session (not child process of the script
> which has set the Env). So I need something like "exporting" the
> environment setting I performed in my perl script. Is this somehow
> possible?
A common way to do this is to simply print the environment variables
that should be set, and let a shell handle the environment. For
example, with a Bourne-like shell, you could do something like:
`perl -le'print "export test=hi"'`
to set the variable "test" to "hi". To make this less annoying, you
can use shell functions which will handle calling the script and
putting all of the quotes in the right place.
You could do the same thing from within another program, but you'd
have to parse the output of the script and set the environment
variables yourself.
-----ScottG.
------------------------------
Date: Fri, 06 Aug 2004 13:22:36 -0400
From: steve_f <me@example.com>
Subject: transforming german characters
Message-Id: <lve7h0tevn6db5l3l7elov9l6l8e26ld70@4ax.com>
I want to transform special German characters to obtain the following
variations:
groß bräu
gross bräu
gross braeu
there are two sets -
set one:
ß = ss = \xDF
set two:
Ä = Ae = \xC4
Ö = Oe = \xD6
Ü = Ue = \xDC
ä = ae = \xE4
ö = oe = \xF6
ü = ue = \xFC
basically, the rules are transform ß independently
and with set two, they are either all on or off together.
I wrote the follow which works well, but looks
pretty bad I think. so again this is a style question...
can anyone suggest a cleaner approach? TIA
sub transform_characters {
my @input = @_;
my @output;
for my $string (@input) {
push @output, $string;
if ($string =~ /\xDF/) {
$string =~ s/\xDF/ss/g;
push @output, $string;
if (test_for_character($string)) {
$string = swap_all($string);
push @output, $string;
}
next;
}
if (test_for_character($string)) {
$string = swap_all($string);
push @output, $string;
}
}
return @output;
}
sub test_for_character {
my $string = shift;
if ($string =~ /\xC4/ ||
$string =~ /\xD6/ ||
$string =~ /\xDC/ ||
$string =~ /\xE4/ ||
$string =~ /\xF6/ ||
$string =~ /\xFC/) {
return 1
} else {
return 0
}
}
sub swap_all {
my $string = shift;
$string =~ s/\xC4/Ae/g;
$string =~ s/\xD6/Oe/g;
$string =~ s/\xDC/Ue/g;
$string =~ s/\xE4/ae/g;
$string =~ s/\xF6/oe/g;
$string =~ s/\xFC/ue/g;
return $string;
}
------------------------------
Date: Fri, 06 Aug 2004 14:00:59 GMT
From: Paul Beckingham <paul@beckingham.net>
Subject: Re: using nested foreach loops
Message-Id: <vaMQc.215793$%_6.107825@attbi_s01>
Kirk Russell wrote:
> foreach xx ( 2.25 2.5 2.75)
> foreach crnr ( TT SS FF)
> fopen model
> set crnr1=crnr
> fclose
> end
> then take model and do analysis
> end
This is not Perl. You have your algorithm already, but now you need to
learn Perl. Try learn.perl.org.
------------------------------
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 6842
***************************************