[18597] in Perl-Users-Digest
Perl-Users Digest, Issue: 765 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 25 18:10:41 2001
Date: Wed, 25 Apr 2001 15:10:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <988236619-v10-i765@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 25 Apr 2001 Volume: 10 Number: 765
Today's topics:
Re: Help for scrpit line.. nobull@mail.com
Re: Help for scrpit line.. (Craig Berry)
Re: Help for scrpit line.. (Abigail)
Re: Help for scrpit line.. (Abigail)
Re: Help for scrpit line.. (Anno Siegel)
Re: How do I find the OS? <djberge@uswest.com>
Re: How to use Perl subroutines/submodules from other s <goldbb2@earthlink.net>
Re: Idiom: the expression of a copied & substituted str <mischief@velma.motion.net>
Re: Idiom: the expression of a copied & substituted str <ren@tivoli.com>
Re: Idiom: the expression of a copied & substituted str <ren@tivoli.com>
Re: Idiom: the expression of a copied & substituted str <ren@tivoli.com>
Re: Idiom: the expression of a copied & substituted str (Anno Siegel)
Re: idiotic behaviour of the symboltable ( how to call <murat.uenalan@gmx.de>
Re: Lvalue <jonni@ifm.liu.se>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Apr 2001 20:00:42 +0100
From: nobull@mail.com
Subject: Re: Help for scrpit line..
Message-Id: <u9d7a0kdnp.fsf@wcl-l.bham.ac.uk>
lckun <lckun@chollian.net> writes upside down and untrimmed. In other
words he is being rude. And because he's being so rude I'm not
prepared to catch, gut, clean and cook his fish for him.
> If I will change one minute instead of an hour in the script, what
> should i modify it?
The number. Change it from the number of days in an hour to the
number of days in a minuite (sic).
This doesn't really have anything to do with Perl now does it?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 25 Apr 2001 20:52:38 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Help for scrpit line..
Message-Id: <teee8mmmin8471@corp.supernews.com>
nobull@mail.com wrote:
: lckun <lckun@chollian.net> writes upside down and untrimmed. In other
: words he is being rude. And because he's being so rude I'm not
: prepared to catch, gut, clean and cook his fish for him.
:
: > If I will change one minute instead of an hour in the script, what
: > should i modify it?
:
: The number. Change it from the number of days in an hour to the
: number of days in a minuite (sic).
How about 60/60/24/60? :)
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: Wed, 25 Apr 2001 20:55:46 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Help for scrpit line..
Message-Id: <slrn9eeeei.5et.abigail@tsathoggua.rlyeh.net>
lee changkun (lckun@informatik.uni-rostock.de) wrote on MMDCCXCIV
September MCMXCIII in <URL:news:3AE6845A.36A08AB2@informatik.uni-rostock.de>:
^^
^^ I think -M is Age of file in days when script started. But what means
^^ 60/60/24??
Why don't you ask Perl?
perl -wle 'print 60/60/24'
Abigail
--
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail
------------------------------
Date: Wed, 25 Apr 2001 20:58:01 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Help for scrpit line..
Message-Id: <slrn9eeeip.5et.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCXCIV
September MCMXCIII in <URL:news:9c6qhq$35f$3@mamenchi.zrz.TU-Berlin.DE>:
::
:: 60/60/24 is just an arithmetic expression. The result is one second,
:: expressed as a fraction of one day.
You must be thousands of years old then.
Abigail
------------------------------
Date: 25 Apr 2001 21:46:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help for scrpit line..
Message-Id: <9c7gju$j5t$4@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCXCIV
> September MCMXCIII in <URL:news:9c6qhq$35f$3@mamenchi.zrz.TU-Berlin.DE>:
> ::
> :: 60/60/24 is just an arithmetic expression. The result is one second,
> :: expressed as a fraction of one day.
>
>
> You must be thousands of years old then.
Well, I certainly felt that age after I looked again.
Anno
------------------------------
Date: Wed, 25 Apr 2001 14:00:59 -0500
From: Dan Berger <djberge@uswest.com>
Subject: Re: How do I find the OS?
Message-Id: <3AE71EEB.C643451F@uswest.com>
> A quote from 'perldoc English':
>
> BUGS
> This module provokes sizeable inefficiencies for regular
> expressions, due to unfortunate implementation details.
> If performance matters, consider avoiding English.
>
> Cheers,
> Bernard
DOH! Just when I thought I could silence all those perl critics who whine
about obfuscated syntax...
BAC will this be addressed in Perl 6?
------------------------------
Date: Wed, 25 Apr 2001 21:39:34 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to use Perl subroutines/submodules from other server
Message-Id: <3AE7453E.4251B808@earthlink.net>
Abigail wrote:
>
> Tony Van der Voort (tvdv@advalvas.be) wrote on MMDCCLXXXIX September
> MCMXCIII in <URL:news:3ae00aaf.5340546@news.skynet.be>:
> <> Hello,
> <>
> <> I'm trying to make a perl script (CGI) with subroutines in a
> <> separate file, using the instruction 'require'. This works very
> <> good. BUT... I want to install this separate file on another
> <> server. The reason I will do this, is to protect the code of the
> <> subroutines. The 'require' instruction does not work here. Can
> <> some-one explain me, how I can solve this problem ?
>
> You forgot the NFS mount the disk from the other server! You should
> ask the sysadmin of the other server to share the disk with the world,
> and have the sysadmin of your server mount the remove disk.
>
> Then it will work all handy-dandy.
If you don't mind the 'protected' code being world readable by anyone
else who mounts the remote (I assume you meant remote, not remove) disk.
Also, even if you have the code shared only to the computer which is to
be calling it, what kind of encryption does NFS supply? Do you trust
that this is secure? I betcha someone, somewhere, knows how to snoop on
or even change the contents of the subroutine code as it is in transit
over NFS. It seems to me that serving the file over https and
retrieving it with LWP would be more secure.
Of course, to give the *best* answer, we would have to know *precisely*
what you mean by "protect the code of the subroutines"
--
Sometimes the journey *is* its own reward--but not when you're trying to
get to the bathroom in time.
------------------------------
Date: Wed, 25 Apr 2001 20:04:43 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Idiom: the expression of a copied & substituted string
Message-Id: <teeberm22euq17@corp.supernews.com>
nobull@mail.com wrote:
> "John Lin" <johnlin@chttl.com.tw> writes:
>> Although maybe eventually you will feel this question is not worthy discussing,
>> I think I still need to explain and make clear what I was talking about...
>>
>> "Chris Stith" wrote
>> > my $original = 'hello-world.pl';
>> > my $new = $original =~ s/\.pl$/.bak/;
>> > rename $original, $new;
>>
>> Let's take this for example. It takes two "statements" to bring the
>> "copied and substituted string" into "rename" as its parameter.
>> If we want to do it in "one expression", the current answer I have is
>>
>> do { (my $new = $original) =~ s/\.pl$/.bak/; $new }; # copied & substituted
>>
>> that is
>>
>> rename $original, do { (my $new = $original) =~ s/\.pl$/.bak/; $new };
> How about:
> rename $original, (map { s/\.pl$/.bak/; $_ } "$original")[0];
> Not really much better... :-)
> OK, so how about:
> rename $original, apply { s/\.pl$/.bak/ } $original;
> Where apply() would be defined as follows:
> sub last_item_when_in_scalar_context { wantarray ? @_ : $_[-1] }
> # If you are worried about speed you could re-write this in XS
> sub apply (&@) {
> my $action = shift;
> &$action for my @values = @_;
> last_item_when_in_scalar_context @values;
> }
How abouot this messy little sub, which lets you write
'$orig = replace( $orig, $exp1, $exp2, $exp3, ... );'?
#####
sub replace {
my $xxx = shift;
for( @_ ) {
eval "\$xxx =~ $_";
}
return $xxx;
}
#####
Like I said, it's messy, and I don't really like the string
eval. It lets me do this, though:
#####
my $orig = 'foo';
my $exp1 = 's/f/b/';
my $exp2 = 's/o/a/';
my $exp3 = 'tr/o/r/';
$orig = replace( $orig, $exp1, $exp2, $exp3 );
print $orig . "\n"; # outputs "bar\n"
#####
This is the functionality for which it seems to me John is asking.
Chris
--
The purpose of a language is not to help you learn the
language, but to help you learn other things by using the
language. --Larry Wall, The Culture of Perl, August 1997
------------------------------
Date: 25 Apr 2001 13:59:08 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Idiom: the expression of a copied & substituted string
Message-Id: <m3lmoox0ub.fsf@dhcp9-172.support.tivoli.com>
On 25 Apr 2001, ren@tivoli.com wrote:
> "as_list"? Probably too confusing...
(And I realize that there isn't really any such thing as a list in a
scalar context, but I'm not really sure how else to associate the
commonality of behavior of the comma operator and slices. Perhaps
just like that. Maybe "as_commas"... :))
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 25 Apr 2001 13:47:47 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Idiom: the expression of a copied & substituted string
Message-Id: <m3pue0x1d8.fsf@dhcp9-172.support.tivoli.com>
On 25 Apr 2001, nobull@mail.com wrote:
> While were looking for neat idioms, anyone know any built-in
> constuct which has similar semantics to
> last_item_when_in_scalar_context() above? I seem to need it an
> awful lot.
Does @array[0..$#array] seem suitable? A slice has scalar semantics
like a list rather than an array. Of course, I assume this is less
efficient than your method, though I guess it really depends on how
everything is implemented. At the very least, I would be surprised if
the "0..$#array" was not at least expanded, even if the slice only
actually retrieved the last element in scalar context (which I doubt
actually happens).
> Anyhow do folks think these would make suitable additions to
> List::Util? If so can anyone come up with a more snappy name for
> last_item_when_in_scalar_context?
"as_list"? Probably too confusing...
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 25 Apr 2001 15:30:50 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Idiom: the expression of a copied & substituted string
Message-Id: <m38zkowwlh.fsf@dhcp9-172.support.tivoli.com>
On Wed, 25 Apr 2001, mischief@velma.motion.net wrote:
> How abouot this messy little sub, which lets you write
> '$orig = replace( $orig, $exp1, $exp2, $exp3, ... );'?
[snip]
>
> #####
> my $orig = 'foo';
>
> my $exp1 = 's/f/b/';
> my $exp2 = 's/o/a/';
> my $exp3 = 'tr/o/r/';
>
> $orig = replace( $orig, $exp1, $exp2, $exp3 );
> print $orig . "\n"; # outputs "bar\n"
> #####
>
You don't really need a sub for that, just use:
s/f/b/, s/o/a/, tr/o/r/ for $orig;
> This is the functionality for which it seems to me John is asking.
Actually, it isn't. He's been pretty clear that what he wants is a
simple expression that returns the modified string. The same thing
that you get from:
do { (my $copy = $orig) =~ s/f/b/; $copy }
The best solution seems to be to write a subroutine like:
sub apply (&$) {
local $_ = $_[1];
$_[0]->();
$_;
}
my $orig = 'foo';
print "$orig => ", (apply { s/f/b/; s/o/a/; tr/o/r/ } $orig), "\n";
print "\$orig still $orig\n";
__END__
BTW, I'm annoyed that the prototype isn't strong enough to stop eating
arguments after the prototype is met, but I guess some things are just
considered too ambiguous. At least it works for zero argument
prototypes.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 25 Apr 2001 21:23:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Idiom: the expression of a copied & substituted string
Message-Id: <9c7f8r$j5t$2@mamenchi.zrz.TU-Berlin.DE>
According to Ren Maddox <ren@tivoli.com>:
> On 25 Apr 2001, ren@tivoli.com wrote:
>
> > "as_list"? Probably too confusing...
>
> (And I realize that there isn't really any such thing as a list in a
> scalar context, but I'm not really sure how else to associate the
> commonality of behavior of the comma operator and slices. Perhaps
> just like that. Maybe "as_commas"... :))
I submit "list_or_last".
Actually, if anything in Perl approaches a list in scalar context,
it is a slice. What absolutely doesn't exist in scalar context is
a list given in the "( a, b, c)" syntax.
Anno
------------------------------
Date: Wed, 25 Apr 2001 22:50:18 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: Re: idiotic behaviour of the symboltable ( how to call a subroutine of an EXPLICIT package without an inherited one (from the ISA) ) ????
Message-Id: <9c7d9l$cd2ja$1@ID-71895.news.dfncis.de>
I found the prob !
it was simple illness after a couple of hours head-banging with my code: I
found that everything is ok with perl, but my implementation was buggy ! As
always: perl ruled, me not !
The code was absolutely ok, even the function-/method-calling stuff was
absolutly right, also the GLOB things was ok. The problem was that i
stupidly blessed $this into wrong packages, before calling pre_init. So here
is the final and working code for the ones who are interested (it is part of
an "class module" with an attribute-/multiple- inheritance-supporting
general new operator):
foreach my $parent ( @{ inheritance_isa( ref( $this ) || die ) } )
{
my $class = ref($this);
bless $this, $parent;
no strict 'refs';
if( defined *{ $parent.'::pre_init' }{CODE} )
{
*{ $parent.'::pre_init' }->( $this, $args );
}
foreach my $initmethod ( qw( init initialize ) )
{
my $method = $parent . '::' . $initmethod;
# did the parent have this class method
if( my $coderef = $parent->can( $initmethod ) )
{
#indn;printfln "init package %s", $parent;
# call parent method with parent blessed instance
$this->$coderef( $args );
# restore our child package/class
bless $this, $class;
last;
}
}
bless $this, $class;
# call constructor arguments as functions, because we assume
attribute-handlers
foreach my $attr ( keys %{$args} )
{
if( my $coderef = $this->can( $attr ) )
{
$this->$coderef( $args->{$attr} );
delete $args->{$attr};
}
}
if( defined *{ $parent.'::post_init' }{CODE} )
{
*{ $parent.'::post_init' }->( $this, $args );
}
}
Many thanks for the help,
Murat
"Murat Uenalan" <murat.uenalan@gmx.de> schrieb im Newsbeitrag
news:9c5fjk$c1846$1@ID-71895.news.dfncis.de...
> IS THIS IMPOSSIBLE ?!
>
> I try to implement a code which calls a subroutine 'pre_init' (if it
exists)
> for every package in an ISA array. But it is fatal for me if perl calls a
> parent 'pre_init' because its "inherited", i really just want the one of
the
> package !!!!! This code-snippet doesn't seem to work, because when
tracking
> the symbol-table (at the end) it shows the misere -> perl just simply
copies
> subroutine-symbolnames to the ISA packages (urghhhh...) THAT SEEMS TO DRAG
> MY LEGS FROM THE GROUND -> HOW TO SOLVE MY PROBLEM ?
>
> package Object;
>
> sub Object::pre_init : method
> {
> my $this = shift;
>
> $this->{ref($this).'::PRE_INIT_CALLED'} = __LINE__;
> }
>
> package Vehicle;
>
> @ISA = qw( Object );
>
> package Car;
>
> @ISA = qw( Vehicle );
>
> package main;
>
> foreach my $parent ( @{ inheritance_isa( ref( $this ) || die ) } )
> {
> no strict 'refs';
>
> if( defined *{ $parent.'::pre_init' }{CODE} )
> {
> *{ $parent.'::pre_init' }->( $this, $args );
> }
> }
>
>
> __END__
>
> The symboltable after the code executed !
> main::Object::
> main::Object::Debugable:: (package)
> main::Object::ISA
> main::Object::MODIFY_CODE_ATTRIBUTES
> main::Object::post_init
> main::Object::pre_init
> main::Vehicle::
> main::Vehicle::ISA
> main::Vehicle::post_init
> main::Vehicle::pre_init
> main::Car::
> main::Car::ISA
> main::Car::post_init
> main::Car::pre_init
>
>
>
------------------------------
Date: Wed, 25 Apr 2001 20:54:04 +0200
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Lvalue
Message-Id: <9c76g5$2pd$1@newsy.ifm.liu.se>
> > Isn't there any way to check the pointer-counter for $_ ? If there is
more
> > than one pointer to the value of $_ it should be an L-value, shouldn't
it?
>
> Why should that be the case? $x = $y = \ 3;
I remember something I read about Perl internals in Advanced Perl
Programming. I think we're confusing pointers with references here. I'm not
very good at this so pleas correct me if I'm wrong.
Consider:
my $a='Value';
for ($a) {
#1#
}
#2#
$a='X'; #3#
We have a value ('Value') that is put into a acalar ($a). This gives the
value a pointercounter of one (1). There is one item pointing to it. Where
the #1# is however two items ($a and $_) is pointing to 'Value', giving it
the pointercounter of two (2). At #2# again only one item is pointion to
'Value', and at #3# no items is pointing to 'Value' making it obsolete, and
the memory will be given back to the system (perl).
Compare it to:
for ('Value') {
#4#
}
Where at #4# there is only one item pointing to 'Value' ($_).
And:
$a=$b='Value';
Where we have two values with different places in memory ('Value' and
'Value') which both have one (1) counter (they will have two when they are
aliased by $_).
And:
$a=$b=\3;
Where we have one value (3) which has an anonymous scalar pointing to it,
giving it one pointer. There are two L-values in $a and $b which both
happens to be references to the same anonymous scalar.
Consider this and it looks like you can use the pointer-counter as an
indicator of L-valueness. I don't know if there is a way to read the
counter-pointer however.
--
_______________________________
Jonas Nilsson
------------------------------
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.
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 765
**************************************