[23890] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6093 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 7 18:05:49 2004

Date: Sat, 7 Feb 2004 15:05: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           Sat, 7 Feb 2004     Volume: 10 Number: 6093

Today's topics:
    Re: @INC unshift? (Malcolm Dew-Jones)
    Re: Callback during FTP <qumsieh@cim.mcgill.ca>
    Re: CPAN cc vs. gcc <usenet@morrow.me.uk>
    Re: filter a string in perl <matthew.garrish@sympatico.ca>
    Re: How to execute a command line in Perlscript <kuujinbo@hotmail.com>
    Re: How to execute a command line in Perlscript <ceo@nospan.on.net>
    Re: How to execute a command line in Perlscript <ceo@nospan.on.net>
    Re: How to execute a command line in Perlscript <ceo@nospan.on.net>
    Re: how to find the last "new line" in string (Walter Roberson)
    Re: how to find the last "new line" in string (Charles DeRykus)
    Re: including files in perl <usenet@morrow.me.uk>
    Re: Need help passing arrays by reference pls. <usenet@morrow.me.uk>
        Novice - help with pattern matching needed (Robert Day)
        Reference overloading helps inheritance (Anno Siegel)
    Re: Reference overloading helps inheritance <uri@stemsystems.com>
    Re: Req.for Advice: Learning Perl <usenet@morrow.me.uk>
    Re: SourceCode : perl OOPS by Conway: <matthew.garrish@sympatico.ca>
    Re: trying to create a network script: <usenet@morrow.me.uk>
    Re: Using "static" in Perl Extensions <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 7 Feb 2004 12:19:46 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: @INC unshift?
Message-Id: <40254862@news.victoria.tc.ca>

Jeff Thies (nospam@nospam.net) wrote:
:   I have shared hosting with an out of date LWP module.

:   I'd like to point to a local recent version, but it reads the out of date
: copy.

: Can I unshift a path onto @INC so it looks there first? 

Did you try?  The answer is yes.  You can do all sorts of things with @INC 
and %INC which are occasionally useful.


There must be a
: better way to point to the right path just for this module.

As shown in another post

	use lib path

is potentially more readable and might also be better as it might do
additional related useful things, and would allow perl to change the way
@INC works.


------------------------------

Date: Sat, 07 Feb 2004 17:11:17 GMT
From: Ala Qumsieh <qumsieh@cim.mcgill.ca>
Subject: Re: Callback during FTP
Message-Id: <V_8Vb.21241$Ep4.8843@newssvr27.news.prodigy.com>

Yehuda Berlinger wrote:

> &{$cb}($buf,$len) if ref $cb eq 'CODE';

The following syntax is clearer, IMHO:

	$cb->($buf, $len) if ref $cb eq 'CODE';

--Ala



------------------------------

Date: Sat, 7 Feb 2004 21:45:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: CPAN cc vs. gcc
Message-Id: <c03mab$h2v$1@wisteria.csv.warwick.ac.uk>


mhunter@uclink.berkeley.edu wrote:
> On Fri, 6 Feb 2004 08:51:13 -0800, Mothra wrote:
> >  export CC=gcc
> 
> Unfortunately, that won't work:
> 
> perl -MCPAN -e 'install Digest::MD5'
> .
> .
> .
> cc: unrecognized option `-KPIC'
> cc: language depend not recognized
> cc: MD5.c: linker input file unused because linking not done
> 
> What's happening is that the config files are structured to build
> with cc, but I need to change that to gcc.
> 
> I tried hacking cc to gcc in
> /usr/perl5/5.6.1/lib/sun4-solaris-64int/Config.pm, but that didn't
> work either.
> 
> Any other thoughts?  Rebuild perl from source?

Always the best option IMHO. Build perl on the machine it will be
running on, with the compiler you intend to build extensions
with. Much less hassle.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else *  ben@morrow.me.uk


------------------------------

Date: Sat, 7 Feb 2004 14:03:45 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: filter a string in perl
Message-Id: <fEaVb.42943$9U5.1701212@news20.bellglobal.com>


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:n6PUb.14359$9a7.6943@nwrddc02.gnilink.net...
> Dino wrote:
> > need some help with a perlscript.
>
> Which script? I don't see any.
>

Could easily be one of the ones from nms, but any widely used script would
be open to this kind of spam (as it's rare that the people implementing them
know enough to change the names of the scripts or the parameters used in the
form).

I pointed my brother to the nms scripts for his Web site, for instance, and
it wasn't long before he came back complaining about all the spam it was
generating in his guestbook (the same Viagra postings the OP mentions). It's
easy to make a script to search around for the scripts and auto-generate a
submission. A spam filter will only work on the email copy that gets sent to
you, you still have to go in each time and remove the offending entry from
the page.

To the OP, as you didn't say what script you were using, all I can suggest
are the two steps I took to shore up the nms script: 1) add a hidden
password field and then check that it matches before processing the form
(ensures that it isn't a script submitting pre-formatted form data, and at
the same time doesn't inconvenience your users); and 2) add a list of banned
words (viagra, hgh, etc.) and check the subject and body of the post to make
sure they aren't contained therein.

Matt




------------------------------

Date: Sun, 08 Feb 2004 01:21:23 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <c033cr$rit$1@pin3.tky.plala.or.jp>

Jürgen Exner wrote:
> [TOFU snipped]
> 
> Eric SALGON wrote:
> 
>>Unfortunatly, I have implemented "shell" and "puts" functions in my
>>ASP code but `$_` return no result in @output array with a simple
>>'dir' command.
>>
>>I'm afraid it's a problem of right on my IIS server.
> 
> 
> But PerlScript is executed client side.
> The web server (be it IIS or Apache or whatever) has nothing to do with it.
> 
> jue

Actually, ActiveState Perl allows you to do something like this with 
PerlScript and IIS:

<% $Response->write( $_ . '<br>') foreach qx(dir) %>

To the OP - have you looked at the HTML documentation that comes with AS 
Perl? The IIS/PerlScript stuff is pretty much right under the Table of 
Contents...

keith


------------------------------

Date: Sat, 07 Feb 2004 19:11:58 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <2MaVb.19469$Us6.3190@newssvr16.news.prodigy.com>

Jürgen Exner wrote:
> [TOFU snipped]
> 
> Eric SALGON wrote:
> 
>>Unfortunatly, I have implemented "shell" and "puts" functions in my
>>ASP code but `$_` return no result in @output array with a simple
>>'dir' command.
>>
>>I'm afraid it's a problem of right on my IIS server.
> 
> 
> But PerlScript is executed client side.
> The web server (be it IIS or Apache or whatever) has nothing to do with it.
> 
> jue

Jurgen...! We've gone through this before once a year or so ago.  8-) 
PERLSCRIPT IS NOT JUST CLIENT-SIDE!!!!  In fact, it's run FAR more often 
SERVER-SIDE than it is CLIENT-SIDE.  Nobody uses it client-side.  It's 
useless.  If you install ActiveState Perl on a server running IIS, it 
gives you a chance to install the PerlScript ASP engine that runs JUST 
LIKE VBScript and JScript on an IIS server...  8-)  (It also allows you 
to use it as a WSH language as well.)

I say all that as kindly as possible since it's so easy to misconstrue 
things in print.  But you keep saying that PerlScript is "client-side", 
which is CAN BE, but it's FAR more prevalent (and far more useful) 
server-side.

So the question and my answer has EVERYTHING to do with IIS...

Chris
-----
Chris Olive
chris -at- --spammers-are-vermin-- technologEase -dot- com
http://www.technologEase.com
(pronounced "technologies")


------------------------------

Date: Sat, 07 Feb 2004 19:25:32 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <MYaVb.19474$Tv6.1254@newssvr16.news.prodigy.com>

Eric SALGON wrote:
> In article <elvUb.19067$Fp6.2360@newssvr16.news.prodigy.com>, 
> ceo@nospan.on.net says...
> 
>>Eric SALGON wrote:
>>
>>>Hi,
>>>
>>>Is there someone who knows how to execute a command line (such a simple 
> 
> echo 
> 
>>>cmd) in PerlScript.
>>>
>>>I hve tryed '' or system() but the result is the same: no result but no 
> 
> error 
> 
>>>!
>>>
>>>This syntax works fine in a perl program but not in PerlScript
>>>
>>>An idea ?
>>>
>>
>>I just realized I didn't answer your question in my last response.
>>
>>First of all, as a general rule, and one that is outlined in the FAQ 
>>(and asked about a lot here is) system() does NOT provide output.  But 
>>most especially in the Windows world where Microsoft writes their own 
>>rules, this is also not the case in either ASP or WSH (still assuming 
>>you are talking about "PerlScript" and not "Perl script.")
>>
>>Using output wrappers in the ASP and WSH worlds for outputing a string, 
>>the following code will work in both worlds for outputing a "system" 
>>command:
>>
>>sub shell {
>>
>>   my @output;
>>   for (@_) { push( @output, `$_` ) }
>>   chomp( @output );
>>   return wantarray ? @output : \@output;
>>
>>}
>>
>>puts( shell( 'dir /l/on/' ) );
>>
>>or you can:
>>
>>puts( shell(
>>   'dir',
>>   'type c:\\autoexec.bat',
>>   'dir c:\\winnt\\system32',
>>   'command4',
>>   'command5',
>>));
>>
>>If:
>>
>>ASP: sub puts { for (@_) { $Response->Write( "$_\n" ) } }
>>WSH: sub puts { for (@_) { $WScript->Echo( "$_\n" ) } }
>>
>>Incidentially using PerlScript in Windows allows you this convenience. 
>>The "official" Microsoft "interface" (read "complicated and 
>>convolluted") for executing a command in a scripting environment (both 
>>ASP and WSH) is WshShell.Exec() (which takes two calls to set up.)  You 
>>can do this in PerlScript if you want, but the regular Perl way of 
>>executing a system command works much smoother.
>>
 > [Top Posting Fixed]
 >
> Unfortunatly, I have implemented "shell" and "puts" functions in my ASP code 
> but `$_` return no result in @output array with a simple 'dir' command.
> 
> I'm afraid it's a problem of right on my IIS server.
>

If your tick marks above are an accurate portrayal of what you used in 
your shell() code, then, no you will not get output.  (You would only 
get an echo back of the command(s) you wanted to run that way.)  The 
single tick marks in my shell() routine above are backward ticks.  Use 
qx() if this is confusing:

sub shell {

    my @output;
    for (@_) { push( @output, qx($_) } }
    chomp( @output );
    return wantarray ? @output : \@output;

}

I would be very surprised that you can't execute 'dir' under IIS.  The 
username running IIS -- usually the default IUSR_machinename account -- 
should have enough privilege to do a 'dir' (and under most circumstances 
will give you a directory listing of C:\WINNT\SYSTEM32).

I'm wondering if it's not just a matter of the backwards tick, which the 
function written using qx() above should solve.

Chris
-----
Chris Olive
chris -at- --spammers-are-vermin-- technologEase -dot- com
http://www.technologEase.com
(pronounced "technologies")


------------------------------

Date: Sat, 07 Feb 2004 19:33:52 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <A4bVb.19477$2x6.1543@newssvr16.news.prodigy.com>

Chris wrote:
> Eric SALGON wrote:
> 
>> In article <elvUb.19067$Fp6.2360@newssvr16.news.prodigy.com>, 
>> ceo@nospan.on.net says...
>>
>>> Eric SALGON wrote:
>>>
>>>> Hi,
>>>>
>>>> Is there someone who knows how to execute a command line (such a simple 
>>
>>
>> echo
>>
>>>> cmd) in PerlScript.
>>>>
>>>> I hve tryed '' or system() but the result is the same: no result but no 
>>
>>
>> error
>>
>>>> !
>>>>
>>>> This syntax works fine in a perl program but not in PerlScript
>>>>
>>>> An idea ?
>>>>
>>>
>>> I just realized I didn't answer your question in my last response.
>>>
>>> First of all, as a general rule, and one that is outlined in the FAQ 
>>> (and asked about a lot here is) system() does NOT provide output.  
>>> But most especially in the Windows world where Microsoft writes their 
>>> own rules, this is also not the case in either ASP or WSH (still 
>>> assuming you are talking about "PerlScript" and not "Perl script.")
>>>
>>> Using output wrappers in the ASP and WSH worlds for outputing a 
>>> string, the following code will work in both worlds for outputing a 
>>> "system" command:
>>>
>>> sub shell {
>>>
>>>   my @output;
>>>   for (@_) { push( @output, `$_` ) }
>>>   chomp( @output );
>>>   return wantarray ? @output : \@output;
>>>
>>> }
>>>
>>> puts( shell( 'dir /l/on/' ) );
>>>
>>> or you can:
>>>
>>> puts( shell(
>>>   'dir',
>>>   'type c:\\autoexec.bat',
>>>   'dir c:\\winnt\\system32',
>>>   'command4',
>>>   'command5',
>>> ));
>>>
>>> If:
>>>
>>> ASP: sub puts { for (@_) { $Response->Write( "$_\n" ) } }
>>> WSH: sub puts { for (@_) { $WScript->Echo( "$_\n" ) } }
>>>
>>> Incidentially using PerlScript in Windows allows you this 
>>> convenience. The "official" Microsoft "interface" (read "complicated 
>>> and convolluted") for executing a command in a scripting environment 
>>> (both ASP and WSH) is WshShell.Exec() (which takes two calls to set 
>>> up.)  You can do this in PerlScript if you want, but the regular Perl 
>>> way of executing a system command works much smoother.
>>>
>  > [Top Posting Fixed]
>  >
> 
>> Unfortunatly, I have implemented "shell" and "puts" functions in my 
>> ASP code but `$_` return no result in @output array with a simple 
>> 'dir' command.
>>
>> I'm afraid it's a problem of right on my IIS server.
>>
> 
> If your tick marks above are an accurate portrayal of what you used in 
> your shell() code, then, no you will not get output.  (You would only 
> get an echo back of the command(s) you wanted to run that way.)  The 
> single tick marks in my shell() routine above are backward ticks.  Use 
> qx() if this is confusing:
> 
> sub shell {
> 
>    my @output;
>    for (@_) { push( @output, qx($_) } }
>    chomp( @output );
>    return wantarray ? @output : \@output;
> 
> }
> 

The extra "}" at the end of the line "for (@_) { push..." in the shell() 
routine should be removed.  Should have been:

for (@_) { push( @output, qx($_) ) }

Chris
-----
Chris Olive
chris -at- --spammers-are-vermin-- technologEase -dot- com
http://www.technologEase.com
(pronounced "technologies")

"Uh?  Yes... well...  You don't know *everything*..."
--Puddleglum, _The Silver Chair_


------------------------------

Date: 7 Feb 2004 19:49:38 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: how to find the last "new line" in string
Message-Id: <c03fgi$a23$1@canopus.cc.umanitoba.ca>

In article <c02egr$5d2$1@news.simnet.is>, gnari <gnari@simnet.is> wrote:
:"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message
:news:c02026$j7v$1@canopus.cc.umanitoba.ca...

:[replacing last newline in string to space]
:> This should work, though (I think):

:>   $string =~ s/\n([^\n]*)\z/ \1/;

:why the [^\n] ?
:whats wrong with:

:$string =~ s/\n(.*)\z/ \1/;

Good point, . doesn't match newline unless you use /s
I just tested a bit and what you suggest seems to do the job.
-- 
   And the wind keeps blowing the angel / Backwards into the future / 
   And this wind, this wind / Is called / Progress.
   -- Laurie Anderson


------------------------------

Date: Sat, 7 Feb 2004 20:02:03 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: how to find the last "new line" in string
Message-Id: <HsqCzF.ApM@news.boeing.com>

In article <c02026$j7v$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
>In article <Hsp94z.IL0@news.boeing.com>,
>Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
>:Did someone already mention:   $string =~ s/\n\Z//;
>
>That's wrong in three ways:
>
>              \Z  Match only at end of string, or before newline at the end
>              \z  Match only at end of string
>
>Bug #1: If the newline is the last character of the string,
>\n\Z is going to want to match a newline -before- that.
>
>Bug #2: The poster wanted to replace the last newline with a space,
>not remove it.
>
>Bug #3: If the last newline in the string is not at the end of the
>string, the pattern won't match it.
>
>This should work, though (I think):
>
>  $string =~ s/\n([^\n]*)\z/ \1/;

Ah, right on all counts...

Here's a shorter possibility (hopefully correct too :):

$string =~ s/(.*)\n/$1 /s;

--
Charles DeRykus



------------------------------

Date: Sat, 7 Feb 2004 22:05:28 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: including files in perl
Message-Id: <c03nf8$h2v$4@wisteria.csv.warwick.ac.uk>


spaughbradley@hotmail.com (brad) wrote:
> I have a list of about 100 constants that I want to use in several
> files.
> I have made this list of constants into a file with extension .hpl as
> in .h for perl.

The convention is for such files to have the extension '.ph': perl
header.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else *  ben@morrow.me.uk


------------------------------

Date: Sat, 7 Feb 2004 22:22:38 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Need help passing arrays by reference pls.
Message-Id: <c03ofe$imu$1@wisteria.csv.warwick.ac.uk>


ko <kuujinbo@hotmail.com> wrote:
> Walter Roberson wrote:
> 
> > In article <168f035a.0402061349.79d8b12b@posting.google.com>,
> > G Klinedinst <g_klinedinst@hotmail.com> wrote:
> > :> # You should avoid the unnecessary concatenations you had in your code.
> > 
> > :Why is that? Are the commas implemented faster, or just for
> > :readability?
> > 
> > Commas in print's are converted into concatenation internally, so both
> > have the same execution speed.
> 
> Got a question about the paragraph above ...
> 
> Remember reading somewhere that there is a difference between the two, so I
> tried this:
<snip benchmark>

A tool I like for answering this sort of question is B::Graph, which
produces a graph of the optree. It seems that

    print "a", "b";

becomes

    nextstate -> pushmark -> const -> const -> print

(nextstate starts a new statement. pushmark makes a mark in the Perl
stack to show where the arguments for the print begin. The consts push
items onto the stack, the print takes them off down to the mark and
prints them) whereas

    print "a" . "b";

becomes

    nextstate -> pushmark -> const -> print

ie. perl will perform the concatenation at compile time, and thus it
must be more efficient. However,

    print "a", $x;

becomes

    nextstate -> pushmark -> const -> padsv -> print

as before (padsv gets the value of the variable and pushes it onto the
stack) whereas

    print "a" . $x;

becomes

    nextstate -> pushmark -> const -> padsv -> concat -> print

ie. the concatenation is done as a separate step before the print, so
it may well be slower (this depends on whether printing several items
as opposed to one is slower or faster than concatenating them).

Certainly it is not true that they are the same: I suspect Walter was
thinking of

    print "a$x";

which *is* converted into

    print "a" . $x;

internally.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


------------------------------

Date: 7 Feb 2004 14:04:18 -0800
From: robertday@hotmail.com (Robert Day)
Subject: Novice - help with pattern matching needed
Message-Id: <63f953b1.0402071404.3dcb30f3@posting.google.com>

Hi

I am using a very basic Perl script to parse a file and extract just
the elements I need but one aspect is causing me trouble and I am sure
the answer is probably quite simple. Below are examples of two of the
lines (watch wrapping) - the value I seek is that between the date on
the left and the "UV Port" on the right.

Enter bookmobile session location code (or NONE) : NONE    06 FEB 2004
                  March Mobile A                          UV Port 51  
Circulation
    06 FEB 2004                  Papworth Library                     
   UV Port 50

The section of code dealing with this is currently

if(/UV/) {
	$library = $`;
	$library =~ s/^\s+\d{2}\s\w{3}\s\d{4}\s+//;
	$library =~ s/- CAMBOOK//g;
	$library =~ s/(\w+)/\u\L$1/g;
	print "$library\n";
}

The 2nd and 3rd pattern matches deal with other lines in the data (not
shown) in which the value I seek is all CAPS or has "- CAMBOOK"
appended. This code works fine on line 2 of the sample data given
above but I don't know how to get rid of "Enter bookmobile session
location code (or NONE) : NONE" when it appears (as it does on a few
entries). i have tried various patterns and I am sure the solution is
simple but it eludes me at present. Can anyone help?

Robert


------------------------------

Date: 7 Feb 2004 17:24:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Reference overloading helps inheritance
Message-Id: <c036vv$d5d$1@mamenchi.zrz.TU-Berlin.DE>

Inheritance in Perl OO has its difficulties when it comes to data
encapsulation.  Basically, it can't be done without a peek at the
implementation of the superclass.

A frequent situation is that the inheriting class contains an object
of the superclass (or, more generally, has a method that returns a
superclass object), and you want it to respond to the methods of the
superclass.  But let me use a concrete example, the generalization
will be obvious.

Consider a class "Tape", whose objects are conceptually snapshots of
some files or directories at a given time (not necessarily on magnetic
tape, but that's a nice short name).  The implementation is a basic
hash-as-a-record:

    bless {
        name => $name,
        ...
        time => Time::Piece( ...),
    }, Tape;

    sub name { $_[ 0]->{ name} }
    sub time { $_[ 0]->{ time} }

Now I want Tape to respond to the methods of Time::Piece, that is, I
want to put "Time::Piece" on @Tape::ISA.  (Because of the overloading
Time::Piece does, this means I can compare tapes with each other, or
with other dates (Time::Piece objects) to see which is older.  Handy
when deciding which tape to overwrite.)

One way of doing this is through Tape::AUTOLOAD.  That can be considered
standard, I won't go into the possible variants here.

Instead of AUTOLOAD one can also use overload, which was new to me.
A peek at the implementation of Time::Piece shows that the objects
are array-refs.  So, if we can make Time::Piece think that Tape objects
are the right kind of array ref, we're done.  But that is what overloading
"@{}" does.  So, in package Tape, saying

    use base qw( Time::Piece);
    use overload ( '@{}' => 'time' );

is all that's needed to make Tape objects inherit from Time::Piece.
That's pretty minimal.

The method isn't entirely clean, but some methods that are described
in Perl's OO recommendations are less so.  It relies on the fact that
the superclass uses a particular (overloadable) data type for its
implementation, but on none of the further details.  Obviously, it also
occupies that particular reference overloading, so if you need that
for something else, you're out of luck.

The implementation also assumes that the inherited data type is different
from the data type of the inheriting class.  Otherwise, overloading
your own data type is still do-able, but a little involved.  This
restriction can be worked around by yielding and making your data type
something else (wrap a scalar ref around it, for instance), but that
makes the method less attractive.

I'm surely not the first to make the observation that overloading can
help inheritance in this way, but since I didn't know about it, I
conclude that it isn't "well known" and deserves a mention :)

Anno


------------------------------

Date: Sat, 07 Feb 2004 19:39:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Reference overloading helps inheritance
Message-Id: <x7d68qof1a.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> Inheritance in Perl OO has its difficulties when it comes to data
  AS> encapsulation.  Basically, it can't be done without a peek at the
  AS> implementation of the superclass.

some modules will do this for you. see the class:: modules by damian conway.

  AS> A frequent situation is that the inheriting class contains an object
  AS> of the superclass (or, more generally, has a method that returns a
  AS> superclass object), and you want it to respond to the methods of the
  AS> superclass.  But let me use a concrete example, the generalization
  AS> will be obvious.


  AS> Now I want Tape to respond to the methods of Time::Piece, that is, I
  AS> want to put "Time::Piece" on @Tape::ISA.  (Because of the overloading
  AS> Time::Piece does, this means I can compare tapes with each other, or
  AS> with other dates (Time::Piece objects) to see which is older.  Handy
  AS> when deciding which tape to overwrite.)

this is done by damian's class::delegate module. it can make methods in
the owner (the object that has the other object) that call through to
the owned object.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Sat, 7 Feb 2004 22:25:27 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Req.for Advice: Learning Perl
Message-Id: <c03okm$imu$2@wisteria.csv.warwick.ac.uk>


Eric Bohlman <ebohlman@earthlink.net> wrote:
> darren_uk <none@hotmail.com> wrote in
> news:jYVUb.549$vo1.424@newsfep4-winn.server.ntli.net: 
> 
> > As soon as you mentioned that book, I thought, "I'm sure I've got that
> > somewhere".  Sure enough, after much digging through archive boxes, I
> > came across a box with a bunch of computer books, including "Perl
> > Cookbook" (and found my "Perl5 Pocket Reference" too).
> 
> Keep in mind that there's a second edition which was published in the last 
> year or so, and significantly expanded; the first edition is nearly 6 years 
> old.  Nonetheless, the first edition should serve you well in the short-
> term; just get the new one when you need to expand your horizons even 
> further.

Also keep in mind 'Perl Recipe of the Day' on perl.com :)

Ben

-- 
               EAT
               KIDS                                          (...er, whoops...)
               FOR                                             ben@morrow.me.uk
               99p


------------------------------

Date: Sat, 7 Feb 2004 14:20:59 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: SourceCode : perl OOPS by Conway:
Message-Id: <qUaVb.42954$9U5.1704256@news20.bellglobal.com>


"David Combs" <dkcombs@panix.com> wrote in message
news:c0264h$t2$1@reader2.panix.com...
> In article <pan.2004.01.11.19.20.14.740006@remove.adelphia.net>,
> James Willmore  <jwillmore@adelphia.net> wrote:
> >
> >It's sad that once a book is written and published, the publisher retains
> >more control than the author over the finished product.
>
> A couple of years ago he told me that they (Manning)
> also had the rights to any *second* volume -- or in fact
> to anything on the same subject (oop in perl) that he
> might write, and that, however, they had decided,
> he thought, *not* to publish such a book.
>

While he's under contract to them, sure, but I've never heard of such a
clause that can ban someone from ever writing on a topic for another
publisher. At most he might have to agree not to write a similar book for a
couple of years, anything longer than that and he signed a really bad
contract.

>
> He said, back then, that he was legally blocked.
>
> (I suggested he *ask* them to release him, but
> he wasn't too optimistic about doing that.)
>

You should have told him to push for a release. Most publishers aren't
willing to legally pursue their authors if they want to end their contracts
prematurely. It really doesn't make you look good to hound the people
providing the content, and will discourage others from doing business with
you in the future (and there's also very little to gain by suing an
author!). Were he selling books along the lines of J.K. Rowlings it might be
a different story.

>
> Which is way too bad, since even back then
> he said that he had enough new material,
> uncovered in the existing book, to fill an
> entire second book (I think that's what he said.)
>

It is, because his is far-and-away the best Perl book I've ever owned.

Matt




------------------------------

Date: Sat, 7 Feb 2004 21:57:59 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: trying to create a network script:
Message-Id: <c03n17$h2v$3@wisteria.csv.warwick.ac.uk>


see@sig.invalid wrote:
> Nex6 wrote:
> > open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";
>
> Better is probably something like:
> 
> open FH,"+<//$file/c\$/reset.reg" or die "Can't open $file: $!";

Better again is

open my $FH, '+<', "//$file/c\$/reset.reg" or die "can't open $file: $!";

The lexical FH will close automatically when it goes out of scope.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


------------------------------

Date: Sat, 7 Feb 2004 21:49:29 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Using "static" in Perl Extensions
Message-Id: <c03mh9$h2v$2@wisteria.csv.warwick.ac.uk>


Mark Shelor <mshelor@comcast.removeme.net> wrote:
> I've encountered a troublesome inconsistency in the Perl extension I've 
> written for CPAN (Digest::SHA).  The problem involves the use of a 
> static array within a performance-critical transform function.  When 
> compiling under gcc on my big-endian PowerPC (Mac OS X), declaring this 
> array as "static" DECREASES the transform throughput by around 5%. 
> However, declaring it as "static" on gcc/Linux/Intel INCREASES the 
> throughput by almost 30%.
> 
> I would prefer that the array not be "static" so that the underlying C 
> function will be thread-safe.  However, giving up close to 30% 
> performance on gcc/Linux/Intel is unacceptable for a digest routine, 
> whose value is often closely tied to speed.
> 
> Can anyone enlighten me on this mystery, and recommend a simple, clean, 
> portable way to assure good performance on all host types?

I don't know about the speed issues, but static data in extensions
*really* ought to use the MY_CXT stuff, so it ends up threadsafe. See
"Safely Storing Static Data in XS" in a recent perlxs, and get a
recent ppport.h if your perl doesn't support it.

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


------------------------------

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 6093
***************************************


home help back first fref pref prev next nref lref last post