[17351] in Perl-Users-Digest
Perl-Users Digest, Issue: 4773 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 31 09:05:21 2000
Date: Tue, 31 Oct 2000 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973001107-v9-i4773@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 31 Oct 2000 Volume: 9 Number: 4773
Today's topics:
Re: + or - (Martien Verbruggen)
Re: Alternate solution to (split)[2..-1] problem <elephant@squirrelgroup.com>
Re: Auth DBI (IP Address) (Michel Dalle)
Re: Auth DBI (IP Address) <flavell@mail.cern.ch>
Classnames in variables <Juergen.Lind@iteratec.de>
Re: Classnames in variables nobull@mail.com
Re: Classnames in variables (Martien Verbruggen)
Re: Classnames in variables <Juergen.Lind@iteratec.de>
Re: Classnames in variables (Martien Verbruggen)
complex regex <celliot@tartarus.uwa.edu.au>
Re: complex regex (Martien Verbruggen)
Re: Converting long integers to hex and vice versa <sb@muccpu1.muc.sdm.de>
Re: OT: Re: Is there a more perlish way to write this? (Anno Siegel)
Re: Q on returning hashes from subroutines <Juergen.Lind@iteratec.de>
Re: read string from kybd <uackermann@orga.com>
Re: read string from kybd (Martien Verbruggen)
Re: share variable between process <wiltam@singnet.com.sg>
Re: share variable between process (Martien Verbruggen)
Re: share variable between process (Martien Verbruggen)
RE: Stultiloquent Queries (was: even or odd?) (H. Merijn Brand)
Re: Using 'format' and 'write' multiple times? (Gwyn Judd)
Re: Win32::IpHelp rereidy@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 31 Oct 2000 22:17:39 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: + or -
Message-Id: <slrn8vtaij.ac5.mgjv@martien.heliotrope.home>
On Tue, 31 Oct 2000 10:17:27 -0000,
James Boulter <jbou@bunker79.fsnet.co.uk> wrote:
> Dear all,
>
> I would like to convert a variable with a number like -14 to 14. How can
> this be done.
Specific:
$variable = 14 if $variable == -14;
$variable =~ s/^-14$/14/;
If you really are asking about getting the positive counterpart of a
negative number (absolute value as that is called:
$variable = abs $variable;
or, if you don't want to use operators that were made for this task:
$variable = -$variable if $variable < 0;
$variable =~ s/^-//;
substr($variable, 0, 1) = '' if $variable =~ /^-/;
$variable = substr $variable, 1 if substr($variable, 0, 1) eq '-';
Or if what you really want is to swap the sign:
$variable = -$variable;
$variable *= -1;
Of course, in this case, you can also just use -$variable instead of
$variable.
You would probably benefit quite substantially from reading some of the
documentation that comes with Perl. You might benefit even more from
buying a decent book about Perl.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Tue, 31 Oct 2000 14:47:51 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: Alternate solution to (split)[2..-1] problem
Message-Id: <8tmev8$2qb$1@nntp.Stanford.EDU>
Ren Maddox wrote ..
>It occurred to me that a perhaps simple solution would be to provide
>some way to index the last element of a list. The obvious solution
>presented itself: a bare "#". It would only work within an index and
>would also refer to the list being indexed. So the expression desired
>in the subject becomes:
>
>print (split)[2..#]
one of the suggestions in that previous thread that you mentioned was to
use $# to represent the last element .. that would definitely be
preferred over a bare '#'
but I think that good points were made to simply use '-1' and to have
evaluation order turn that into the index of the final element of the
list BEFORE evaluating the '..' operator
the main pro that I can remember is that this '-1' has an existing
meaning and would be very DWIMy
the main con was that there was a potential for breaking existing
programs that rely on '0..-1' to evaluate to an empty list
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Tue, 31 Oct 2000 12:13:19 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Auth DBI (IP Address)
Message-Id: <8tmd4g$liq$1@news.mch.sbs.de>
In article <8tk0l1$h3v$1@nnrp1.deja.com>, Tom Tom <thomas1280@my-deja.com> wrote:
>I'm hosting a site using Apache, Perl and mySQL.
>I want to log all access to the restricted areas of the site
>by username, IP and time.
[snip]
Probably a stupid question, but why not extract that information
from your standard access logfiles ?
For the rest, I don't know what $REQUESTERS_IP_ADDR is
supposed to contain, but $ENV{'REMOTE_ADDR'} should
show the IP address. Since I've never written handlers for
Apache, your mileage may vary :)
Michel.
------------------------------
Date: Tue, 31 Oct 2000 13:42:20 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Auth DBI (IP Address)
Message-Id: <Pine.GHP.4.21.0010311340430.21195-100000@hpplus03.cern.ch>
On Tue, 31 Oct 2000, Michel Dalle wrote:
> supposed to contain, but $ENV{'REMOTE_ADDR'} should
> show the IP address.
Of whatever entity is making the HTTP connection to the server, yes
(i.e in general it could be a proxy quite remote from the actual
client).
Of course, we both know that this is off-topic for this group...
cheers
------------------------------
Date: Tue, 31 Oct 2000 12:10:07 +0100
From: =?iso-8859-1?Q?J=FCrgen?= Lind <Juergen.Lind@iteratec.de>
Subject: Classnames in variables
Message-Id: <39FEA88F.725C1BA5@iteratec.de>
Hi,
I have a problem with implementing the "Strategy" pattern: in order
to tighten the code that selects the strategy to be used in a
particular context, I tried the following code (adapted from the perl
cookbook) for a conditional object creation:
my %SpecTypes = (
'xml' => "XMLSpec",
'xq' => "XMLQuerySpec",
'do' => "DataobjectSpec",
'if' => "InterfaceSpec",
'td' => "TableDataSpec",
'qo' => "QueryDataobjectSpec",
'de' => "DataentitySpec",
'sql' => "SQLSpec",
'tt' => "TOPLinkSpec"
);
if( $SpecTypes{$goaltype} ){
no strict 'refs';
my $spec = ($SpecTypes{$goaltype} . "::" . "new" ) -> ("'dd' => $dd");
$spec->go( $metaspec, $goaltype );
}
else{
print "unknown specification type\n";
}
When executing this code, however, I get the following error message
from the class created
"Can't call method "SUPER::new" without a package or object reference
at..."
Any suggestion?
Regards
Jürgen
------------------------------
Date: 31 Oct 2000 12:37:20 +0000
From: nobull@mail.com
Subject: Re: Classnames in variables
Message-Id: <u91ywxtce7.fsf@wcl-l.bham.ac.uk>
Jürgen Lind <Juergen.Lind@iteratec.de> writes:
> no strict 'refs';
> my $spec = ($SpecTypes{$goaltype} . "::" . "new" ) -> ("'dd' => $dd");
You are fogetting that the first argument to a class method is the
class name. If you use method call syntax CLASS->method(args) this is
handled automatically but using subroutine call syntax you must
explicily say CLASS::method('CLASS',args).
no strict 'refs';
my $spec = ($SpecTypes{$goaltype} . "::" . "new" ) ->
($SpecTypes{$goaltype},"'dd' => $dd");
Of course it would be a lot cleaner just to say:
my $spec = $SpecTypes{$goaltype}->new("'dd' => $dd");
BTW the fact that you are passing "'dd' => $dd" as a string is
probably either a mistake or a sign of poor design elsewhere.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 31 Oct 2000 23:48:16 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Classnames in variables
Message-Id: <slrn8vtfsg.ac5.mgjv@martien.heliotrope.home>
On Tue, 31 Oct 2000 12:10:07 +0100,
Jürgen Lind <Juergen.Lind@iteratec.de> wrote:
> Hi,
>
> I have a problem with implementing the "Strategy" pattern: in order
> to tighten the code that selects the strategy to be used in a
> particular context, I tried the following code (adapted from the perl
> cookbook) for a conditional object creation:
Where is this in the Cookbook? I couldn't find it. Or are you referring
to the code on pp 423-425? While that works for many things, in this
case it probably isn't necessary to do that.
> my %SpecTypes = (
> 'xml' => "XMLSpec",
> 'xq' => "XMLQuerySpec",
> 'do' => "DataobjectSpec",
> 'if' => "InterfaceSpec",
> 'td' => "TableDataSpec",
> 'qo' => "QueryDataobjectSpec",
> 'de' => "DataentitySpec",
> 'sql' => "SQLSpec",
> 'tt' => "TOPLinkSpec"
> );
>
> if( $SpecTypes{$goaltype} ){
>
> no strict 'refs';
> my $spec = ($SpecTypes{$goaltype} . "::" . "new" ) -> ("'dd' => $dd");
>
> $spec->go( $metaspec, $goaltype );
> }
> else{
> print "unknown specification type\n";
> }
>
> When executing this code, however, I get the following error message
> from the class created
> "Can't call method "SUPER::new" without a package or object reference
> at..."
The at bit is quite important. Where does this error occur? You don't
have a SUPER there. But let me make a guess as to what's going wrong:
Normally the new method gets called as a class method, i.e. as in:
XMLSpec->new(%arguments);
Otherwise you should probably call it as
XMLSpec::new('XMLSpec', %argumants);
Most new() methods I've seen require the class or an object as the first
argument.
I would probably solve that problem by havign a factory class (Banana) or
something like that:
#!/usr/local/bin/perl -wl
use strict;
package Generic;
sub new
{
my $proto = shift;
my $class = ref $proto || $proto;
print $class;
bless {}, $class;
}
package Foo;
@Foo::ISA = qw(Generic);
package Bar;
@Bar::ISA = qw(Generic);
package Baz;
@Baz::ISA = qw(Generic);
package Banana;
my %Spec = (
bar => 'Bar',
baz => 'Baz',
foo => 'Foo',
);
sub new
{
my $proto = shift;
my $class = ref $proto || shift;
return unless $class;
die "$class is not valid" unless exists $Spec{$class};
$Spec{$class}->new();
}
package main;
my $baz = Banana->new('baz');
my $bar = Banana->new('bar');
my $foo = Banana->new('foo');
my $foobar = Banana->new('foobar');
Alternatively, you can do it directly, as you are doing with something
like:
package main;
my %Spec = (
bar => 'Bar',
baz => 'Baz',
foo => 'Foo',
);
my $type = 'bar';
if ($Spec{$type})
{
my $spec = $Spec{$type}->new(argl => 2);
$spec->go(qw/arguments go here/);
}
But I definitely prefer the approach where a factory class is
responsible for instantiating the correct real class. I've included a
common subclass for all real classes in my example, to indicate that
they all implement the same interface, or set of functions that you need
to call. In your real classes that isn't necessarily needed, as long as
they all have the necessary methods defined.
But there really is no need to not use strict 'ref'.
Martien
--
Martien Verbruggen |
Interactive Media Division | life ain't fair, but the root
Commercial Dynamics Pty. Ltd. | password helps. -- BOFH
NSW, Australia |
------------------------------
Date: Tue, 31 Oct 2000 14:07:31 +0100
From: =?iso-8859-1?Q?J=FCrgen?= Lind <Juergen.Lind@iteratec.de>
Subject: Re: Classnames in variables
Message-Id: <39FEC413.49EECD7B@iteratec.de>
nobull@mail.com wrote:
> Jürgen Lind <Juergen.Lind@iteratec.de> writes:
>
> > no strict 'refs';
> > my $spec = ($SpecTypes{$goaltype} . "::" . "new" ) -> ("'dd' => $dd");
>
> You are fogetting that the first argument to a class method is the
> class name. If you use method call syntax CLASS->method(args) this is
> handled automatically but using subroutine call syntax you must
> explicily say CLASS::method('CLASS',args).
>
> no strict 'refs';
> my $spec = ($SpecTypes{$goaltype} . "::" . "new" ) ->
> ($SpecTypes{$goaltype},"'dd' => $dd");
>
Yupp, I just found out minutes before your reply. But thanks anyway...
>
> Of course it would be a lot cleaner just to say:
>
> my $spec = $SpecTypes{$goaltype}->new("'dd' => $dd");
>
Now that I see it I'm trying to recall why I hadn't try that... Probably
because I thought that
there would be no chance to call the "new" method on a String (thats what
$SpecTypes{$goaltype}
is after all).
>
> BTW the fact that you are passing "'dd' => $dd" as a string is
> probably either a mistake or a sign of poor design elsewhere.
>
Mistake, should've been two parameters...
Thanks at lot...
Jürgen
------------------------------
Date: Wed, 1 Nov 2000 00:47:50 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Classnames in variables
Message-Id: <slrn8vtjc6.ac5.mgjv@martien.heliotrope.home>
On Tue, 31 Oct 2000 14:07:31 +0100,
Jürgen Lind <Juergen.Lind@iteratec.de> wrote:
> nobull@mail.com wrote:
> >
> > Of course it would be a lot cleaner just to say:
> >
> > my $spec = $SpecTypes{$goaltype}->new("'dd' => $dd");
> >
>
> Now that I see it I'm trying to recall why I hadn't try that...
> Probably because I thought that there would be no chance to call the
> "new" method on a String (thats what $SpecTypes{$goaltype} is after
> all).
This is documented in perlop:
[snip]
The Arrow Operator
[snip]
Otherwise, the right side is a method name or a simple
scalar variable containing either the method name or a
subroutine reference, and the left side must be either an
object (a blessed reference) or a class name (that is, a
package name). See the perlobj manpage.
[snip]
Martien
--
Martien Verbruggen | Since light travels faster than
Interactive Media Division | sound, isn't that why some people
Commercial Dynamics Pty. Ltd. | appear bright until you hear them
NSW, Australia | speak?
------------------------------
Date: Tue, 31 Oct 2000 19:43:16 +0800
From: "Cam" <celliot@tartarus.uwa.edu.au>
Subject: complex regex
Message-Id: <39feb0b5$0$25562@echo-01.iinet.net.au>
If I am searching a file for 3 different keywords and want to do something
upon finding these keywords, how should I proceed?
I dont want to have to parse the string 3 seperate times which is the only
way I can see how to do it.
ie.
if I find $var1 then do BLAH1
if I find $var2 then do BLAH2
if I find $var3 then do BLAH3
these can occur in any order and more than once. Thus I want to search
through the string and upon finding each of these (in order) manipulate the
string..
Is this possible or do I have to loop through 3 times (once for each
keyword) ???
--
cheers
cam
-------------------------------
------------------------------
Date: Wed, 1 Nov 2000 00:02:17 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: complex regex
Message-Id: <slrn8vtgmp.ac5.mgjv@martien.heliotrope.home>
On Tue, 31 Oct 2000 19:43:16 +0800,
Cam <celliot@tartarus.uwa.edu.au> wrote:
> If I am searching a file for 3 different keywords and want to do something
> upon finding these keywords, how should I proceed?
> I dont want to have to parse the string 3 seperate times which is the only
> way I can see how to do it.
[snip]
> these can occur in any order and more than once. Thus I want to search
> through the string and upon finding each of these (in order) manipulate the
> string..
>
> Is this possible or do I have to loop through 3 times (once for each
> keyword) ???
There are specific examples that will work fine with only three words.
This, however, is a nice scalable solution:
#!/usr/local/bin/perl -wl
use strict;
$_ = 'This is a string with a few words that I will be looking for.';
sub do_will { print 'do_will' }
sub do_string { print 'do_string' }
sub do_words { print 'do_words' }
my %dispatch = (
'string' => \&do_string,
'words' => \&do_words,
'will' => \&do_will,
);
my $re_words = join '|', keys %dispatch;
&{$dispatch{$1}} while (/($re_words)/og);
However, you say that you want to modify the string? You can't do that
in this example. The best you could do is modify a copy. If you really
mean that you want to replace that word with something else, then you
could make do something like:
#!/usr/local/bin/perl -wl
use strict;
$_ = 'This is a string with a few words that I will be looking for.';
sub do_will { 'do_will' }
sub do_string { 'do_string' }
sub do_words { 'do_words' }
my %dispatch = (
'string' => \&do_string,
'words' => \&do_words,
'will' => \&do_will,
);
my $re_words = join '|', keys %dispatch;
s/($re_words)/&{$dispatch{$1}}/eog;
If you need to do something more complex, then you should probably give
us a bit more information about what exactly it is that you want to do.
Martien
--
Martien Verbruggen | Since light travels faster than
Interactive Media Division | sound, isn't that why some people
Commercial Dynamics Pty. Ltd. | appear bright until you hear them
NSW, Australia | speak?
------------------------------
Date: 31 Oct 2000 13:18:31 GMT
From: Steffen Beyer <sb@muccpu1.muc.sdm.de>
Subject: Re: Converting long integers to hex and vice versa
Message-Id: <8tmgr7$q29$1@solti3.sdm.de>
In article <39FDEA65.6AB712C5@am1.ericsson.se>, William Cardwell <EUSWMCL@am1.ericsson.se> wrote:
> I have 20 digit integers like this: $n="06625632382998574462" and need
> to convert to 16 digit hex code similar to:
> $h="5D574FA1C71D357E" (this isn't the equiv. to above integer)
> ... and vice versa.
> I have spent a while studying Math::BigInt, but because of my
> inexperience with object oriented programming I am having trouble. Or
> perhaps there's another way. I just have to convert, not do any
> computation.
> Would anyone be so kind as to show me the code?
> Thanks so much.
> Will Cardwell
test.pl:
-------------------- cut here -------------------- cut here --------------------
#!perl
use Bit::Vector;
$v = Bit::Vector->new_Dec(80,"06625632382998574462");
print $v->to_Hex(), "\n";
-------------------- cut here -------------------- cut here --------------------
[sb@muccpu1]~>perl test.pl
00005BF2F98C58F4757E
Hope this helps! :-)
Best regards,
--
Steffen Beyer <sb@engelschall.com>
http://www.engelschall.com/u/sb/whoami/ (Who am I)
http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)
------------------------------
Date: 31 Oct 2000 13:40:01 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: OT: Re: Is there a more perlish way to write this?
Message-Id: <8tmi3h$guu$1@lublin.zrz.tu-berlin.de>
Tim Hammerquist <tim@degree.ath.cx> wrote in comp.lang.perl.misc:
[...]
>That's how I would do it in Perl. However, elsewhere in this thread was
>posted the Perl 6 proposition:
>
> if (30 <= $n < 40) {...}
>
>I can't resist... Python already does this:
>
> if 30 <= n < 40:
> ...
>
>A question to anyone developing/proposing this in Perl 6: If this syntax
>were implemented in Perl6, would $n be evaluated once or twice? Once
>would make more sense to me, and would allow more ways to do it.
Evaluating the middle operand twice would be a serious bug. Just
keep in mind that it can be any expression, especially one with a
side effect:
if ( 30 <= tr/a// < 40 ) { ...
Presumably this is supposed to process $_ if it contains 30 to 40 a's,
but if tr/// was evaluated twice, the second result would always be 0.
Anno
------------------------------
Date: Tue, 31 Oct 2000 12:16:11 +0100
From: =?iso-8859-1?Q?J=FCrgen?= Lind <Juergen.Lind@iteratec.de>
Subject: Re: Q on returning hashes from subroutines
Message-Id: <39FEA9FB.E6573D48@iteratec.de>
>
> Of course it would probably be better to modify $map->mappings() to
> return a hashref rather than a flattened hash. For details see the
> manual section I refer to above.
I tried that in it works just fine... Thanks a lot...
>
> This is a plain text only newsgroup.
>
sorry for that...
regards
Jürgen
------------------------------
Date: Tue, 31 Oct 2000 12:58:32 +0100
From: Ulrich Ackermann <uackermann@orga.com>
Subject: Re: read string from kybd
Message-Id: <39FEB3E8.99FE2BD1@orga.com>
Michael Guenther wrote:
>
> Have you ever tried the STDIN Filehandle
>
> $var = STDIN;
> or
> $var = <STDIN>;
>
> one of these should work on a Unix box for sure
> waits until \n
unless you have not played with the $/ variable ;-)
Ulrich
--
Ulrich Ackermann
ORGA Kartensysteme GmbH (SY-PEAT-STA)
Tel.:+49.5254.991-925
mailto:uackermann@orga.com
------------------------------
Date: Wed, 1 Nov 2000 00:37:36 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: read string from kybd
Message-Id: <slrn8vtip0.ac5.mgjv@martien.heliotrope.home>
[In the future, please post your reply _after_ the suitably trimmed text
you reply to. This makes your messages easier to read, and conforms to
the accepted posting style on this group, and Usenet in general]
On Tue, 31 Oct 2000 10:30:43 +0100,
Michael Guenther <MiGuenther@lucent.com> wrote:
[reordered post]
> P.Eftevik wrote in message <39FE8BE4.1346E15E@autra.noXX>...
> >I'm looking for a getstr() or something that reads a string from
> >keyboard.
> >getc() takes only single chatacter, and read() seems to want fixed
> >length.
> >Is there a trick for me here ?
>
> Have you ever tried the STDIN Filehandle
>
> $var = STDIN;
> or
> $var = <STDIN>;
>
> one of these should work on a Unix box for sure
> waits until \n
Have you ever tried any of the following? Or the documentation?
# Magic Perl
$var = igllypigglypoobiewoobiegimmethatlinenow;
# PolitePerl Scripting engine
$var = please_read_a_line_from_keyboard;
# AOL Perl
$var = gimmegimmegimmethatline_metoo;
# Microsoft Perl
$var = wait_for_newline_while_busy_looping_and_store_keys;
# Perl for the Impatient
$var = why_the_fsck_does_perl_not_have_line_oriented_input?;
# Web Enabled Perl (WEP)
$var = http://localhost/keyboard/until_newline
# JavaPerl
Create a class for your keyboard (KeyBoard)
Create a class for the newline (NewLine)
Create a public static class main
Create an interface for your keystroke classes (KeyStroke)
Create a class for each key (Key)
Create a class for a line (Line)
Instantiate Line and KeyBoard class in main
Fill line with Key out of KeyBoard, on events KeyStroke
if KeyStroke isa NewLine, exit
# HeisenPerl
You cannot determine both the line and the line end with infinite
precision.
# Quantum Dynamics Perl
Put the keyboard in a box, and close the lid. When you open the box, you
will either have a newline or not. Replace cat.
# Superstring Perl
Expand the keyboard to 11 dimensions. Fold 6 of them into a loop.
What's left is the line you want.
# Monkey Perl
Put an infinite number of monkeys at your keyboard. Within an infinite
amount of time one of them will produce a line. Put an infinite amount
of monkeys in the computer. Within an infinite amount of time one of
them will be able to read that line.
# Pencil Perl
Where is that damn sharpener?
# Shorthand Perl
$var = %$#((*@))!;
# Documented method in perlfunc
$var = readline(*STDIN);
# Documented method in perlop, and the method that gets used in almost
# every single piece of Perl code available
$var = <STDIN>;
Two of the above work. On Unix, and on other platforms. The rest are all
scheduled for Perl 6, unless they throw my RFC out.
Martien
--
Martien Verbruggen |
Interactive Media Division | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd. | crops where there ain't no crops.
NSW, Australia |
------------------------------
Date: Tue, 31 Oct 2000 19:25:11 +0800
From: Wilson Tam <wiltam@singnet.com.sg>
Subject: Re: share variable between process
Message-Id: <39FEAC17.B8B224A5@singnet.com.sg>
Forget to add some info.. :-P
I tried to do 'echo 1073741824 > /proc/sys/kernel/shmmax' but the 'make
test' on IPC-Shareable still fail, saying "Munged shared memory... not
enough"...
Does anyone know how to make the Shareable module works? or should I
just ignore the error message? Or are there any other way I can share
variable between process?
Thanks.
Wilson Tam wrote:
>
> Hi,
>
> Does anyone know now to create a variable which can be shared between
> different perl process. I have downloaded the IPC-Shareable-0.52 but
> can't install on my linux machine running 2.2.15. 'make test' failed.
>
> Or does anyone know how to increase the SHMMAX size on Linux?
>
> Thanks.
> Wilson
------------------------------
Date: Tue, 31 Oct 2000 23:15:39 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: share variable between process
Message-Id: <slrn8vtdvb.ac5.mgjv@martien.heliotrope.home>
On Tue, 31 Oct 2000 18:51:23 +0800,
Wilson Tam <wiltam@singnet.com.sg> wrote:
> Hi,
>
> Does anyone know now to create a variable which can be shared between
> different perl process. I have downloaded the IPC-Shareable-0.52 but
> can't install on my linux machine running 2.2.15. 'make test' failed.
The shmget, shmctl, shmread, and shmwrite functions are available as
perl builtins. So are the semget, semop and semctl functions.
> Or does anyone know how to increase the SHMMAX size on Linux?
Or? IPC::Shareable uses shared memory segments, unless I'm quite severly
mistaken. It'll run into the same limitations you run into with the bare
calls.
AFAIK there is no way to change it in Linux without recompiling the
kernel. But you would be better off asking this in a Linux group.
Check /usr/src/linux/include/asm/shmparam.h. On my system (kernel
2.2.16) it's set to 0x2000000, which is 32 MB.
Do you need more than that? I can show you that I can get the 32 MB:
#!/usr/local/bin/perl -wl
# Get 32MB of shared memory, store a 2 MB string halfway through, and
# read the second half of that string out again
use strict;
use IPC::SysV qw(IPC_PRIVATE S_IRWXU);
my $var;
my $shm = shmget(IPC_PRIVATE, 0x2000000, S_IRWXU) or die $!;
shmwrite($shm, "x" x 0x800000, 0x1000000, 0x800000) or die $!;
shmread ($shm, $var, 0x1000000 + 0x400000, 0x100000) or die $!;
die "Wrong read" if length $var != $var =~ tr/x//;
Asking for a single byte more than 32 M results in an invalid argument
error. I can however ask for 4 of these segments with no problem.
I know that the IPC::Shareable README says that the error that you get
during the test is most probably related to SHMMAX being too small, but
I doubt tat sincerely in this case. I get the same error. I've just been
too busy to track it down. A quick trace on what t/10av.t does shows
that it allocates a 64 kb segment, which should hardly overflow either
SHMMAX or SHMALL. I suspect the problem lies somewhere else. But I don't
know where, and I don't have the time to track it down. If you want to
use it, you could send a message to the maintainer.
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
NSW, Australia | being a damn fool about it.
------------------------------
Date: Wed, 1 Nov 2000 00:07:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: share variable between process
Message-Id: <slrn8vth19.ac5.mgjv@martien.heliotrope.home>
[In the future, please post your reply _after_ the suitably trimmed text
you reply to. It makes messages easier to read, and is the accepted
convention on this newsgroup, and Usenet in general]
On Tue, 31 Oct 2000 19:25:11 +0800,
Wilson Tam <wiltam@singnet.com.sg> wrote:
> Wilson Tam wrote:
> >
> > Does anyone know now to create a variable which can be shared between
> > different perl process. I have downloaded the IPC-Shareable-0.52 but
> > can't install on my linux machine running 2.2.15. 'make test' failed.
>
> Does anyone know how to make the Shareable module works? or should I
> just ignore the error message? Or are there any other way I can share
> variable between process?
Is there anything wrong with the builtins that I talked about in the
other post?
A quick search on CPAN (search.cpan.org) revealed IPC::SharedCache and
IPC::ShareLite. There is also a IPC::Cache, but that has a reasonably
small version number, so that doesn't look very mature.
You might be able to find more if you do a search yourself.
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Tue, 31 Oct 00 13:14:51 +0100
From: h.m.brand@hccnet.nl (H. Merijn Brand)
Subject: RE: Stultiloquent Queries (was: even or odd?)
Message-Id: <8FDE8FF35Merijn@192.0.1.90>
tchrist@perl.com (Tom Christiansen) wrote in <39fdf794$1@cs.colorado.edu>:
>In article <MPG.14679202611391ef98ae7e@nntp.hpl.hp.com>,
>>> sub is_even { abs int shift =~ /[60284]$/ }
>>> sub is_odd { abs int shift =~ /[53197]$/ }
>>
>>Unnecessary use of abs().
>
>True enough.
>
>But I did need to do it on the first version. Think about it.
>I'm doing a parity count down to 0. You need to make sure
>you're above it to get down to it.
>
>>As for int(), is even or odd defined for other than integers?
>
>No, certainly not. Nor "fred23" either. I didn't wish to
>clutter up the examples with *too* much boundary checks. :-)
Wouldn't it have been nice to `hide' the real answer to this ultimate
stupid questi0n like (using one of these brilliant examples):
sub is_even { length ('x' x abs int shift) % 2 == 0 }
sub is_odd { length ('x' x abs int shift) % 2 == 1 }
--
H.Merijn Brand
using perl5.005.03 and 5.6.0 on HP-UX 10.20, HP-UX 11.00, AIX 4.2, AIX 4.3,
DEC OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.022 and/or DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
------------------------------
Date: Tue, 31 Oct 2000 11:30:55 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Using 'format' and 'write' multiple times?
Message-Id: <slrn8vtbbc.rit.tjla@thislove.dyndns.org>
I was shocked! How could R.Joseph <streaking_pyro@my-deja.com>
say such a terrible thing:
>That was just psuedo-code to show what was happening - if it helps,
>PRETEND there is something very very important in thoose varibles that
>will get printed.
Okay, I'll PRETEND there is some real data in there and you can PRETEND
that you answered my question without getting offended for no reason.
>The real code is much longer than that...I was just trying to show the
>general flow and structure of things to see if some nice person could
>help me - not make fun of me.
Well the "general flow and structure" looks okay. If you actually expect
anyone to be able to assist, you will need to post something that we can
actually run and that actually exhibits the behaviour. Why don't you
trim what you have down to a reasonable level and post that? And ease up
on the attitude.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Beauty seldom recommends one woman to another.
------------------------------
Date: Tue, 31 Oct 2000 12:18:49 GMT
From: rereidy@my-deja.com
Subject: Re: Win32::IpHelp
Message-Id: <8tmdb6$h8q$1@nnrp1.deja.com>
Thanks for the response, but...
Yes, there is text on this page that describes the module, but the link
to download the module gives a page with this message: 'The requested
URL /~aminer/Perl/zip/iphelp-1_02.zip was not found on this server.'
Still searching...
rr
In article <39FE3022.B1AC517B@patriot.net>,
H C <carvdawg@patriot.net> wrote:
> http://www.generation.net/~aminer/Perl/
>
> It's there, I just checked...
>
> rereidy@my-deja.com wrote:
>
> > Hi everyone,
> >
> > I am looking for this module (referenced in 'Perl for System
> > Administrators), but I cannot find it on
> > http://www.generation.net/~aminer/Perl. I also cannot find it on
CPAN
> > or ActiveState.
> >
> > Does anyone have any idea where I can find this module?
> >
> > Thanks for your time.
> >
> > Ron Reidy
> > Oracle DBA
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> --
> Q: Why is Batman better than Bill Gates?
> A: Batman was able to beat the Penguin.
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4773
**************************************