[19369] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1564 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 19 06:10:26 2001

Date: Sun, 19 Aug 2001 03:10:10 -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: <998215810-v10-i1564@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 19 Aug 2001     Volume: 10 Number: 1564

Today's topics:
    Re: manipulating constant lists with map() <bcaligari@fireforged.com>
    Re: Perl OO needs the opposite of SUPER:: (John Lin)
    Re: Perl OO needs the opposite of SUPER:: (John Lin)
    Re: Perl OO needs the opposite of SUPER:: (John Lin)
    Re: Perl OO needs the opposite of SUPER:: <joe+usenet@sunstarsys.com>
    Re: Perl OO needs the opposite of SUPER:: (John Lin)
    Re: Re: OT active perl and dos <jnurick@zdnetonebox.com>
    Re: Search the pattern with Perl Regular Expression <bwalton@rochester.rr.com>
    Re: Search the pattern with Perl Regular Expression <Tassilo.Parseval@post.rwth-aachen.de>
    Re: sort alphabetically (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 19 Aug 2001 09:47:31 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: manipulating constant lists with map()
Message-Id: <9lnqjb015q1@enews2.newsguy.com>


"Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:3B7EFCC1.9010503@post.rwth-aachen.de...
> Brendon Caligari wrote:
> >>3)
> >>ethan@ethan:~$ perl
> >>@f = map { $_++ } qw(1 2 3);
> >>print @f;
> >>^D
> >>Modification of a read-only value attempted at - line 1.
> >>
> >
> > $_ in map is an alias to the list value, in your case the list is not
made
> > up
> > of variables, and hence can't be modified
>
>
> Yes, that's understood. But this still does not explain why it obviously
> can be modified if the list is generated by a backticks command. My
> problem is that I don't see a difference in qw(1 2 3) and for example
> `ls`. Both seem pretty read-only to me yet it only failed with qw(1 2 3).
>
> Tassilo

qw(1 2 3) is just a list literal, while `whatever` in a list context can be
seen as returning an anonymous list.  I assume that 'wherever'
the backticks have written to is being modified during the map.

However, I would appreciate if someone more knowlegeable could
shed some light.

Brendon





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

Date: 18 Aug 2001 20:16:12 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108181916.6fd796aa@posting.google.com>

Martien Verbruggen wrote

> This may very well be true, but it doesn't justify throwing over years of
> OO wisdom that a base class categorically doesn't ever want to know about
> its inherited child classes.

No.  What I am talking about is just like Java's "interface".
The base class doesn't require to know anything about the inheriting classes.
All it needs to do is assuming the presence of the interface method.

This "interface" concept is very common in OO's polymorphism designing, right?
So I am not throwing away OO's wisdom.  Instead I try to patch Perl's OO.

Looking at the problem (or restriction) that simplex (not even half-duplex)
SUPER:: causes, only the duplex "SUPER::+VIRTUAL::" OO can solve it elegantly.

I mean "the problem" (or restriction) by

### Perl's simplex (SUPER:: only) OO ###
The same "interface" in an inheritance hierarchy MUST NOT have the same name.

### Extended duplex (SUPER::+VIRTUAL::) OO ###
The same "interface" in an inheritance hierarchy WITH THE SAME NAME supported.

Thank you.
John Lin


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

Date: 18 Aug 2001 20:44:31 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108181944.6eb650c5@posting.google.com>

Ren Maddox wrote

> OK.  I've taken your example and changed it to use what I consider the
> more normal solution.  The trick is to separate the part that you want
> the intermediate class(es) to override from the part that you want the
> final class(es) to override.

> package ExtendedReport;
> our @ISA = qw/Report/;
>
> sub pre_report {
>     my $self = shift;
>     $self->SUPER::pre_report(@_);
>     print "NOTE: every report will add element counting.\n";
> }
>
> sub post_report {
>     my $self = shift;
>     print "There are @{[scalar @$self]} elements.\n";
>     $self->SUPER::post_report(@_);
> }

Great!!! Your solution is much better than I have ever thought of by myself.

Using your solution, consider the same classes.  Suppose that

Report::
    sub gen;               (calls report)
    sub save_as_html;      (calls report)
    sub print_to_printer;  (calls report)
    sub report {return}    # please inherit and override

My version is:

Report::
    sub gen;               # unchanged
    sub save_as_html;      # don't need to change
    sub print_to_printer;  # not even changed a single line
    sub report : virtual {return}    # just add a "virtual" attribute here

ExtendedReport::
    sub report : virtual { change the behavior }  # and call VIRTUAL:: if needed

Done!!! And nothing more.

But, with current Perl's restriction, using your solution:

Report::
    sub  pre_gen;             # You need to modify the original class
    sub      gen;             # breaking down subroutines into pieces
    sub post_gen;             # which I consider to be ugly  :)
    sub  pre_save_as_html;
    sub      save_as_html;
    sub post_save_as_html;
    sub  pre_print_to_printer;
    sub      print_to_printer;
    sub post_print_to_printer;

ExtendedReport::
    sub pre_gen {
        $self->SUPER::pre_gen(@_);
        ... do my stuffs here
    }
    sub post_gen {
        ... do my stuffs here
        $self->SUPER::post_gen(@_);
    }
    sub pre_save_as_html {
        # hey, I am writing the same code again
    }
    sub post_save_as_html {
        # can you save my time
    }
    sub pre_print_to_printer {
        # although the problem is solvable by current Perl OO
    }
    sub post_print_to_printer {
        # I'd rather Perl provide me better OO mechanism to write elegantly
    }

Thank you.
John Lin


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

Date: 18 Aug 2001 21:19:34 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108182019.507d2600@posting.google.com>

Martien Verbruggen wrote

> Note that all of this renaming is a result of the fact that you had a
> class (and inhertance tree) design, and you are now changing it by
> changing the inheritance pattern.

No.  If I ask you to release two classes: Report and ExtendedReport,
both "ready to use", that is, users can choose whichever to inherit

        Report <- SimpleReport
or
        Report <- ExtendedReport <- SimpleReport

You can plan your inheritance in advance (so that's not a "change" anymore).
Can you provide just one "interface" (say, sub report) for SimpleReport
to override instead of two (sub report and sub _report)?

Is it possible in current Perl OO?

> A design using abstract methods:

<snip of "renaming" solution, already discussed>

> An alternative design, which doesn't require changing the classes, but
> requires the caller to change their behaviour:
>
> Report:
>     provides new() gen()
>     requires report()
>
> ExtendedReport <- Report
>     provides counted_report() (which calls $self->report)
>
> EvenReport <- ExtendedReport
>     provides report()
>
> OddReport  <- ExtendedReport
>     provides report()
>
> Not great, because now the caller needs to decide which report they
> want, and I suspect that's not what you want.

Here, Report::gen calls $self->counted_report to link to ExtendedReport, right?
(Originally Report::gen calls $self->report)

Then the old "interface" is broken:

Report <- EvenReport  (Sorry, it means your EvenReport <- Report,
I need to be consistant with other posts in the thread.)

EvenReport::counted_report is not defined

Thus, Report is no more "ready to use".

> This last one could also be done with multiple inheritance.

Hmm... I couldn't figure it out...

> But I think there is a better design, which will make future changes
> (other report formats) easier to deal with as well:
> would your design be helped if you thought about those bits before
> and after the $self->_report() as functional entities that could be
> implemented as _header() and _footer()?

I discussed this in the thread answering to Ren Maddox.  Please have a look :)

> > How would you solve this problem?
>
> By redesigning the whole thing, and then changing the classes according
> to the new design.

Remember I dumped a question at the beginning of this post?
Try to solve it and you will understand it is impossible.

Thank you.
John Lin


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

Date: 19 Aug 2001 00:56:38 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <m3vgjk1wc9.fsf@mumonkan.sunstarsys.com>

johnlin@chttl.com.tw (John Lin) writes:

> Now ExtendedReport inherits Report and tries to change the behavior of
> "sub report", so it must be named "sub ExtendedReport::report".
> 
> But "ExtendedReport::report" will not be called at all
> because "OddReport::report" (or "EvenReport::report") exists.
> 
> To solve the problem, I have to rename all the inheritor-class's "sub report"
> into "sub _report".  Otherwise I have to re-write the base class Report.

That's not surprising, since ExtendedReport and Report have entirely
different programming interfaces.  In the original, it is expected that 
module authors that inherit Report will be providing a report() method; 
whereas in the latter, ExtendedReport effectively exports its report() 
method (in an apparently non-overridable fashion) and requires module 
authors to provide an auxiliary method to support it.  Adding a
"VIRTUAL" keyword won't make these two interfaces any less different.

My main gripe with what you are suggesting is that it allows base-class
authors to interfere too much with the design of derived classes.
It's as if I had purchased a happy meal, but the ketchup dispenser
sprayed mustard all over my fries.

-- 
Joe Schaefer    "I don't give a damn for a man that can only spell a word one
                                            way."
                                               --Mark Twain



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

Date: 18 Aug 2001 22:19:45 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108182119.6cbd4a09@posting.google.com>

> My version is:
> 
> Report::
>     sub gen;               # unchanged
>     sub save_as_html;      # don't need to change
>     sub print_to_printer;  # not even changed a single line
>     sub report : virtual {return}    # just add a "virtual" attribute here
> 
> ExtendedReport::
>     sub report : virtual { change the behavior }  # and call VIRTUAL:: if needed
> 
> Done!!! And nothing more.

I think the attribute added to Report::report can be optional.
Thus, we don't need to change a single line of the base class at all!!!
That's even a bigger improvement.

John Lin


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

Date: Sun, 19 Aug 2001 06:38:38 +0100
From: John Nurick <jnurick@zdnetonebox.com>
Subject: Re: Re: OT active perl and dos
Message-Id: <214tntcad62725ubpel750tounqc5n64be@4ax.com>

On Sat, 18 Aug 2001 10:27:54 GMT, "spamfree" <spamfree@sorted2000.net>
wrote:

>Im having trouble typing the pipe character in dos!
>Instead of | I get ¦ from the keyboard, or ^V when pasted from Character
>Map!

IME this happens with some combinations of OS, keyboard, and keyboard
drivers. Try holding down Alt-Gr and typing a backtick ` . And Ctrl-V
does not paste into a command prompt: try a right-click instead (or
RTM).
--
John

Please reply to the newsgroup and not by e-mail.
split $q,q[ acehJklnoPrstu]; $q.=$_[$_] for map hex, unpack
q,a,x29,q;89D010B3170A3B7041263B01D0177;;print qq;...$q.\n;


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

Date: Sun, 19 Aug 2001 02:26:18 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Search the pattern with Perl Regular Expression
Message-Id: <3B7F23ED.59F075F5@rochester.rr.com>

Eric Chow wrote:
 ...
> I am a beginner in Perl.
> Would you please to teach me how I can get a pattern of text from a string ?
> 
> For example :
> =========================================================
> <small><font size=12 color=red>PERL</font></small>
> <small><font size=18 color=blue>Regular Expression</font></small>
> ========================================================
> 
> As the above text, how can I use only one expression, so that it can return
> tow results as "PERL" and "Regular Expression" ???
> 
> Would you pelase to teach me and show me the solution??
 ...
> Eric
Well, Eric, you have chosen a really bad example to start with.  In
general, the parsing of HTML is far and away best done with a genuine
HTML parser, like what you will find in the CPAN module HTML::Parser,
for example.  The reason why is that general HTML (that is, the stuff
somebody else generates, not the stuff you generate yourself) could have
commentary and other goodies embedded in it.  The syntax rules for HTML
commentary are such that a simple regexp won't really be able to deal
with it (and yes, perhaps someone could write one with the latest
version of Perl, but it would be a dilly).  

If you know the HTML you will be parsing looks just like the examples
you show (no commentary, no newlines in the middle, only one piece of
text on the line prefixed and suffixed by complete HTML tags all on the
same line, etc), you could do:

while(<DATA>){
   s/^\s*(?:<[^>]*>\s*)*([^<]+)(?:<[^>]*>\s*)*$/$1/;
   print "$_\n";
}
__END__
<small><font size=12 color=red>PERL</font></small>
<small><font size=18 color=blue>Regular Expression</font></small>

But that will break as soon as the slightest thing changes.  I strongly
encourage you not to waste your time pursuing stuff like that, but
rather study and learn how to use HTML::Parser or equivalent.  Regexes
are very useful for many things and are well worth learning, but they
are not the appropriate tool for everything.
-- 
Bob Walton
@b=reverse qw(5.343661747946449e10 -6.870680690767926e8 
-1.975771987860562e11 2.131669362055020e9 3.109571746855627e11 
-2.596991050289181e9 -2.730223404245535e11 1.509524556094990e9 
1.473205544423461e11 -3.461473703699918e8 -5.076036670755333e10 
-5.454741451803003e7 1.124701215943620e10 5.059108441610335e7 
-1.575711669364010e9 -1.182973200557814e7 1.338518987279448e8 
1.290612694169348e6 -6.387952390526651e6 -7.131700994976459e4 
1.490495390583466e5 2.244925340775351e3 -1.247664152253088e3 
-2.608118501828809e1);for(1..24){($_-=12.5)/=12.5;@c=@b;$a=0;
while(@c){($a*=$_)+=pop @c}print chr $a+95.7}


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

Date: Sun, 19 Aug 2001 04:36:22 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Search the pattern with Perl Regular Expression
Message-Id: <3B7F2626.5020004@post.rwth-aachen.de>

Bob Walton wrote:

[request for regex for HTML]

> Well, Eric, you have chosen a really bad example to start with.  In
> general, the parsing of HTML is far and away best done with a genuine
> HTML parser, like what you will find in the CPAN module HTML::Parser,
> for example.  The reason why is that general HTML (that is, the stuff
> somebody else generates, not the stuff you generate yourself) could have
> commentary and other goodies embedded in it.  The syntax rules for HTML
> commentary are such that a simple regexp won't really be able to deal
> with it (and yes, perhaps someone could write one with the latest
> version of Perl, but it would be a dilly).  

(unconditionally agreeing)
Yet, I remember when I started with Perl (it was CGI stuff that brought 
me to Perl). I quickly needed something for HTML and HTML::Parser 
sounded pretty promising. But HTML::Parser is pretty unusable for a 
beginner. Thinking back to the manpages I read it talked about 
subclassing HTML::Parser which left me with a big blank on my face.

Thus, I'd recommend HTML::TokeParser that also comes with docs that 
actually include some useful and almost ready-to-do examples. I always 
missed that in HTML::Parser.


Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Sat, 18 Aug 2001 19:22:28 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sort alphabetically
Message-Id: <slrn9ntu5k.frn.tadmc@tadmc26.august.net>

greg <benz@op.net> wrote:
>I'm having a hard time trying to find out how to sort alphabetically,
>i have two fields, title and text and i'm trying to sort
>alphabetically by the title field.


First, get the things (lines in your case) you want to sort
into an array, then:

   perldoc -q sort

      "How do I sort an array by (anything)?"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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


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