[23979] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6180 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 22 21:05:36 2004

Date: Sun, 22 Feb 2004 18:05:06 -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           Sun, 22 Feb 2004     Volume: 10 Number: 6180

Today's topics:
    Re: Caching DBI 'prepare' statements for re-use with an (Anno Siegel)
        Device::Modem v1.36 released to CPAN <cosimo@cpan.org>
    Re: finding common words <dwall@fastmail.fm>
    Re: finding common words <matthew.garrish@sympatico.ca>
    Re: finding common words <noreply@gunnar.cc>
    Re: finding common words <noreply@gunnar.cc>
    Re: Help with end of line charaters <tadmc@augustmail.com>
    Re: html2text but preserving text links <invalid-email@rochester.rr.com>
    Re: I wish buy Perl book <matthew.garrish@sympatico.ca>
    Re: Installation Problem with XML::Parser perl module <usenet@morrow.me.uk>
    Re: Installation Problem with XML::Parser perl module (Anno Siegel)
    Re: Private methods within a Perl Object module (Anno Siegel)
    Re: Private methods within a Perl Object module <uri@stemsystems.com>
    Re: Private methods within a Perl Object module (Randal L. Schwartz)
    Re: Private methods within a Perl Object module <usenet@morrow.me.uk>
    Re: Private methods within a Perl Object module (Anno Siegel)
    Re: Questions on PAR <tadmc@augustmail.com>
    Re: Really unbuffered reads... <mb@uq.net.au.invalid>
    Re: Simple code runs on linux, but not on windows -- wh <tadmc@augustmail.com>
    Re: Simple code runs on linux, but not on windows -- wh <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Feb 2004 23:37:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Caching DBI 'prepare' statements for re-use with an Apache server
Message-Id: <c1befd$4g6$2@mamenchi.zrz.TU-Berlin.DE>

Sherm Pendley  <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> Dave Cardwell wrote:

[...]

> Then simply assign it with:
> 
> $sth ||= prepare(...);
> 
> That's a shortcut for:
> 
> $sth = ($sth || prepare(...) );
> 
> Perl is lazy (in a good way) with regard to logical ORs; it bails out upon
> finding the first true clause. So, if $sth is already defined it doesn't
> call prepare().
> 
> You can use this technique in many other ways, too. I've found it *very*
> useful when working with XSLT objects, as parsing the style sheet and
> creating the transformer object is relatively expensive.

It's known as the "orcish maneuver" (from "or cache").  See
    http://perlmonks.thepen.com/Orcish%20Maneuver.html
for the full background.

It's going to be even more versatile with the upcoming //=, which is like
||=, but sensitive to defined-ness, not boolean value.  We can still
call it "orcish maneuver", // is an or-like operation.

Anno


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

Date: Sun, 22 Feb 2004 17:36:00 GMT
From: Cosimo Streppone <cosimo@cpan.org>
Subject: Device::Modem v1.36 released to CPAN
Message-Id: <HtIEt6.3nr@zorch.sf-bay.org>

Version 1.36 of Device::Modem perl extension has been released to CPAN,
and should be available at your local CPAN mirror in a day or two.

Changes
-------------
1.36
1.35
1.34  Sun Feb 22 18:12:54 CET 2004
    - fixed  CPAN bug #5131 (https://rt.cpan.org/Ticket/Display.html?id=5131)
    - closed CPAN bug #5134 (https://rt.cpan.org/Ticket/Display.html?id=5134)
    - dial() now should return correctly after a successful connect,
      without unnecessarily waiting for timeout
    - updated changes file missing in 1.35

1.33
1.32
1.31  Fri Jan 23 01:14:01 CET 2004
    - Improved reliability in answer() method (sempre lui!),
	  that was more unstable due to recent changes.
	- Documented _answer() internal function to get the raw modem response
	  instead of response string stripped of all cr/lf chars.


What it is?
------------

Device::Modem is a perl extension to talk to AT compliant devices via
serial ports. It should be enough platform independent as you need.


Prerequisites
-------------

+ working perl installation >= 5.005_03
+ Device::SerialPort >= 0.19 (Win32::SerialPort on Windows)
+ a modem or AT-compliant device if you want to use
   it for some real work


Installation
------------

This module installs like all other good old perl modules:

$ perl Makefile.PL
$ make
$ make test
$ make install


Licensing terms
---------------

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
Additionally, this is BETA software, so use it at your own risk,
and without ANY warranty!
For any need of commercial support and/or licensing, please contact
me directly: Cosimo Streppone <cosimo@cpan.org>


Advertising :-)
---------------

Check out also Device::Gsm module from the same author
to work with GSM devices connected via serial port.




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

Date: Mon, 23 Feb 2004 00:15:10 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: finding common words
Message-Id: <Xns9497C3DAAA5A4dkwwashere@216.168.3.30>

viv2k@hotmail.com (viv2k) wrote:

> Right now, I have two very long lists of words with comments attached
> to each of the words and I want to find the words that are common in
> both of them.

perldoc -q intersection

Gunnar Hjalmarsson has already posted working code. I just wanted to point to 
the FAQ entry, as the code there is readily adapted to the above problem.

-- 
David Wall


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

Date: Sun, 22 Feb 2004 20:10:32 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: finding common words
Message-Id: <7qc_b.3447$ee3.96873@news20.bellglobal.com>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:c1b7qa$1fpfks$1@ID-184292.news.uni-berlin.de...
> viv2k wrote:
> > Right now, I have two very long lists of words with comments
> > attached to each of the words and I want to find the words that are
> > common in both of them.
> >
> > example:
> >
> > ListA                ListB
> >
> > apple   1.1          apple 100
> > banana  2.2          boy   500
> > cat     3.3          cat   1000
> >
> > And I want the result to look something like:
> >
> > ListA                ListB
> > apple   1.1          apple 100
> > cat     3.3          cat   1000
>
>      my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
>      my %ListB = ( apple => 100, boy => 500, cat => 1000 );
>
>      for (keys %ListA) {
>          delete $ListA{$_} unless exists $ListB{$_};
>      }
>      for (keys %ListB) {
>          delete $ListB{$_} unless exists $ListA{$_};
>      }
>

I've never been a big fan of looping over both sets like that (especially if
you want to retain the original hashes). If you just want to extract the
common elements, my personal preference would be to do something like the
following instead:

my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
my %ListB = ( apple => 100, boy => 500, cat => 1000 );
my %common;

for (keys %ListA) {
   if ($ListB{$_}) { $common{$_} = [$ListA{$_}, $ListB{$_}] };
}

print "ListA\n";
print "$_\t$common{$_}[0]\n" for sort keys %common;

print "\nListB\n";
print "$_\t$common{$_}[1]\n" for sort keys %common;


But there's certainly nothing wrong with your code...

Matt




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

Date: Mon, 23 Feb 2004 02:25:26 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: finding common words
Message-Id: <c1bl99$1h0o4r$1@ID-184292.news.uni-berlin.de>

David K. Wall wrote:
> viv2k@hotmail.com (viv2k) wrote:
>> Right now, I have two very long lists of words with comments
>> attached to each of the words and I want to find the words that
>> are common in both of them.
> 
> perldoc -q intersection
> 
> Gunnar Hjalmarsson has already posted working code. I just wanted
> to point to the FAQ entry, as the code there is readily adapted to
> the above problem.

Well, applying that FAQ entry, you could do something like this:

     my ($elem, %count, %intersection);
     for $elem (keys %ListA, keys %ListB) { $count{$elem}++ }
     for $elem (keys %count) {
         $intersection{$elem} = "$ListA{$elem} : $ListB{$elem}"
           if $count{$elem} > 1;
     }
     print "$_\t$intersection{$_}\n" for sort keys %intersection;

But provided that it makes sense to start with populating two hashes
with the lists of words + comments, I don't really see that the FAQ
entry is very well adapted, since applying it would not take advantage
of the initial hashes.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 23 Feb 2004 02:36:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: finding common words
Message-Id: <c1bltj$1gjam7$1@ID-184292.news.uni-berlin.de>

Matt Garrish wrote:
> I've never been a big fan of looping over both sets like that
> (especially if you want to retain the original hashes). If you just
> want to extract the common elements, my personal preference would
> be to do something like the following instead:
> 
> my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
> my %ListB = ( apple => 100, boy => 500, cat => 1000 );
> my %common;
> 
> for (keys %ListA) {
>    if ($ListB{$_}) { $common{$_} = [$ListA{$_}, $ListB{$_}] };
> }
> 
> print "ListA\n";
> print "$_\t$common{$_}[0]\n" for sort keys %common;
> 
> print "\nListB\n";
> print "$_\t$common{$_}[1]\n" for sort keys %common;
> 
> 
> But there's certainly nothing wrong with your code...

Maybe not, but I like your solution. It would only require looping
through one of the lists.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sun, 22 Feb 2004 17:24:03 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help with end of line charaters
Message-Id: <slrnc3iegj.jgv.tadmc@magna.augustmail.com>

Bob Walton <invalid-email@rochester.rr.com> wrote:

> Since it looks like you're running Windoze (you say PC, so it 
> could be Linux, BSD, DOS, OS/2, etc, I suppose), you don't have a dump 
> command


I have a Perl program named "xdump". Looks like I copied it
from one of the Camel books...


--------------------------------------------------------------
#!/usr/bin/perl
# copied from the Camel book, page 272

open(STDIN, $ARGV[0]) || die "Can't open '$ARGV[0]' ($!)\n";

while (($len = read(STDIN, $data, 16)) == 16) {
   @array = unpack('N4', $data);
   $data =~ tr/\0-\37\177-\377/./;
   printf "%8.8ld   %8.8lx %8.8lx %8.8lx %8.8lx   %s\n",
          $offset, @array, $data;
   $offset += 16;
}

if ($len) {
   @array = unpack('C*', $data);
   $data =~ y/\0-\37\177-\377/./;
   for (@array) {
      $_ = sprintf('%2.2x', $_);
   }
   push(@array, ' ') while $len++ < 16;
   $data =~ s/[^ -~]/./g;
   printf "%8.8ld   ", $offset;
   printf "%s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   %s\n",
          @array, $data;
}
--------------------------------------------------------------


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


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

Date: Mon, 23 Feb 2004 01:41:22 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: html2text but preserving text links
Message-Id: <4039583A.2080203@rochester.rr.com>

Felix wrote:

> The script below tries converting html to text while preserving
> textual links. However, with www.news.com it renders many lines all
> bunched together as opposed to neatly separated as lynx would do with
> the same page (see www.marcfest.com/qxi5/news.cgi to see what I mean).
> Anybody know how I can improve the script? Using backticks with lynx
> is not an option, btw.
 ...

Sounds like maybe you could:

    use Text::Wrap;

to get more presentable text?

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sun, 22 Feb 2004 19:48:22 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: I wish buy Perl book
Message-Id: <l5c_b.3437$ee3.93574@news20.bellglobal.com>


"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7llmuhlam.fsf@mail.sysarch.com...
> >>>>> "MG" == Matt Garrish <matthew.garrish@sympatico.ca> writes:
>
>   MG> "toylet" <toylet@mail.hongkong.com> wrote in message
>   MG> news:4036ff85$1_2@rain.i-cable.com...
>
>   >> This kind of links could easily be found by google. There are even
*.edu
>   >> that did that, Notably in certain 3rd world countries. I had nothing
to
>   >> do with the site. DOn't mis-understand.
>
>   MG> I don't think anyone is blaming you (well, maybe Uri) for posting
>   MG> those books online. Just be aware that there are people who read
>   MG> this newsgroup, like Randal, who authored or contributed to those
>   MG> books, so this is not the forum to be recommending pirated
>   MG> information. Either point people to the free documentation or
>   MG> suggest they buy a book / subscription.
>
> i do blame him for even posting the link. if he knows it is a bootleg
> and he still posts the link then he is either very stupid or condoning
> the theft.

Or young and naive about where he was posting (which the pseudonym would
attest to). I was just trying to give him the benefit of the doubt, but I
haven't seen an acknowledgement that he understands why what he did was
offensive, so I hope you don't mind if I join your camp for a while...

On a positive note, it appears that the site has finally been
decommissioned.

Matt




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

Date: Sun, 22 Feb 2004 23:53:05 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Installation Problem with XML::Parser perl module
Message-Id: <c1bfd1$kdf$1@wisteria.csv.warwick.ac.uk>


anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> [...]
> 
> > Is there another XML/Parser/Expat.pm somewhere in @INC that is getting loaded
> > first?
> > 
> > Try adding
> > 
> > BEGIN {
> >     $SIG{__DIE__} = sub {
> >         die <<DIE
> > Parser.pm is $INC{'XML/Parser.pm'}
> > Expat.pm  is $INC{'XML/Parser/Expat.pm'}
> > $@
> > DIE
> >     }
> > }
> > 
> > at the top of your program.
> 
> Ugh, that won't work.  It's interpolating $INC{ ...} before anything is
> loaded.

Eh? No it's not... $INC{...} is interpolated when the heredoc is
evaluated, not when it's compiled:

~% perl -e'BEGIN { $SIG{__DIE__}=sub{ die <<DIE' 
        -e'Fcntl is $INC{q/Fcntl.pm/}' 
        -e'$_[0]' 
        -e'DIE' 
        -e'} } use Fcntl qw/foo/'
Fcntl is /usr/lib/perl5/5.8.2/i686-linux-thread-multi/Fcntl.pm
"foo" is not exported by the Fcntl module
Can't continue after import errors at -e line 5
BEGIN failed--compilation aborted at -e line 5.

> Did you mean to eval() something?  Otherwise, $@ is useless.

No, that's just me getting $SIG{__DIE__}/$@ confused with END{}/$?... 
I meant $_[0], of course.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: 23 Feb 2004 01:37:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Installation Problem with XML::Parser perl module
Message-Id: <c1blgf$8bg$1@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:

[...]

> > > Try adding
> > > 
> > > BEGIN {
> > >     $SIG{__DIE__} = sub {
> > >         die <<DIE
> > > Parser.pm is $INC{'XML/Parser.pm'}
> > > Expat.pm  is $INC{'XML/Parser/Expat.pm'}
> > > $@
> > > DIE
> > >     }
> > > }
> > > 
> > > at the top of your program.
> > 
> > Ugh, that won't work.  It's interpolating $INC{ ...} before anything is
> > loaded.
> 
> Eh? No it's not... $INC{...} is interpolated when the heredoc is
> evaluated, not when it's compiled:

You're right.  Sorry for the false alarm.

Anno


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

Date: 22 Feb 2004 23:17:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Private methods within a Perl Object module
Message-Id: <c1bda4$4g6$1@mamenchi.zrz.TU-Berlin.DE>

Johnny J  <johnj@nospam.here.com> wrote in comp.lang.perl.misc:
> I'm doing object oriented programming w/ Perl and created a Perl module 
> for a class.  What I am trying to do within the module itself is 
> implement private methods or subroutines that can only be used by 
> (possibly public) methods within the module; I do not want them 
> accessible outside the module.
> 
> Here's how I'm trying to do it in the module.  For flexibility, I wanted 
> some of my public methods to invoke the private subroutines via a hash 
> table to subroutine refs (which are the private subs).  For what I am 
> trying to do, this scheme adds much flexibility and manageability, as 
> opposed to calling the private subroutines explicitly in the methods by 
> name.

I'm not sure I understand entirely what you want to achieve, but there's
enough wrong with your code to comment on.

> -------------------------------------------------
> my %PRIVMETHS = ( 'MOVE'  => $prv_MOVE,
>                    'WRITE'  => $prv_WRITE,
>                    'READ'   => $prv_READ,
>                    'DELETE' => $prv_DELETE, );

You are using the package global variables $prv_MOVE etc to set up the
hash.  These are undefined at this point, as far as anyone can see, so
that's what's going into the hash.

You seem to be running without strict, otherwise your program would
have died at this point.

Quite generally, this kind of setup, which is going to be used by other
subs, should go into a BEGIN block, so it is ready when the subs are
ready.  It may often not matter, but sometimes it does.

> ##### Private Subroutines (not access. to public) ########
> my $prv_MOVE = sub {
>     ....
> }

Here you are setting the lexical variables $prv_MOVE etc.  These are
different from the package globals you used above.  But even if you
were using the same set of variables, what makes you think setting them
here would retro-actively change the values in your hash?  Programs work
sequentially.

> my $prv_WRITE = sub {
>     ....
> }
> 
> my $prv_READ = sub {
>     ....
> }
> 
> my $prv_DELETE = sub {
>     ....
> }
> 
> ##### Public Methods for Object Class  ########
> sub action {
>    my $self = shift;
>    # Method called as $obj->action(<action>, <value>), where <action> is
>    # any one of MOVE, WRITE, READ, DELETE, ...
> 
>    ...
>    $PRIVMETHS{$action}->($value);
>    ...
> }
> -------------------------------------------------
> 
> Unfortunately, I have not been able to get this to work.  I have tried 
> so many other convolutions to get this to work, even using evals, but no 
> go.   Any help would be greatly appreciated!

Well, the call should work if $action contains the right value.  You just
never assigned anything useful to $PRIVMETHS{ $action}.

Judging from your attempt, you need to learn some elementary Perl, and
probably some programming concepts too, before you try to write your own
OO method dispatcher.

Anno


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

Date: Sun, 22 Feb 2004 23:52:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Private methods within a Perl Object module
Message-Id: <x7wu6efz95.fsf@mail.sysarch.com>

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


  AS> Quite generally, this kind of setup, which is going to be used by other
  AS> subs, should go into a BEGIN block, so it is ready when the subs are
  AS> ready.  It may often not matter, but sometimes it does.

this doesn't need any BEGIN block and the real problem and fix is below:

  >> my $prv_WRITE = sub {
  >> ....
  >> }

why do you need the variable there just to insert it into a hash?

my %method_dispatch ;

$method_dispatch{ 'WRITE' } = sub {} ;

  >> ##### Public Methods for Object Class  ########
  >> sub action {
  >> my $self = shift;
  >> # Method called as $obj->action(<action>, <value>), where <action> is
  >> # any one of MOVE, WRITE, READ, DELETE, ...

  >> $PRIVMETHS{$action}->($value);

that should work now but still has a major bug. google for some threads
on diapatch tables and you should see the problem. this has been covered
many times and is now in the process of being added to the FAQ (i owe
an edit pass on the entry someone wrote).

  AS> Judging from your attempt, you need to learn some elementary Perl,
  AS> and probably some programming concepts too, before you try to
  AS> write your own OO method dispatcher.

he wasn't that far off but i agree with your general sentiment. first, i
would never do this as it gains little. why shouldn't code that uses
this module be able to call those methods and instead be forced to call
them through this table. there is no noticeable benefit that i can see.

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: Sun, 22 Feb 2004 23:51:35 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Private methods within a Perl Object module
Message-Id: <e695df3ac19d0a10e83edee945a983f3@news.teranews.com>

>>>>> "Johnny" == Johnny J <johnj@nospam.here.com> writes:

Johnny> I'm doing object oriented programming w/ Perl and created a Perl
Johnny> module for a class.  What I am trying to do within the module itself
Johnny> is implement private methods or subroutines that can only be used by
Johnny> (possibly public) methods within the module; I do not want them
Johnny> accessible outside the module.

The convention for this is to begin them with an underscore.

If you want more control than that, you know where to find C++ or Java.

Every time someone tries to restrict what can be done by subclasses
and foreign classes, someone else finds a legitimate reason to need
to work around that.

Please don't be that short-sighted.

And please supply an email address for people to contact you privately
if they choose.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 23 Feb 2004 00:16:11 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Private methods within a Perl Object module
Message-Id: <c1bgob$l6m$1@wisteria.csv.warwick.ac.uk>


Uri Guttman <uri@stemsystems.com> wrote:
> he wasn't that far off but i agree with your general sentiment. first, i
> would never do this as it gains little. why shouldn't code that uses
> this module be able to call those methods and instead be forced to call
> them through this table. there is no noticeable benefit that i can see.

The OP's stated intent was that these methods should be private: i.e.
not callable from outside the class... to make this work, I would ditch
the action() method and instead use AUTOLOAD:

use Carp;

our $AUTOLOAD;

sub AUTOLOAD {
    (my $meth = $AUTOLOAD) =~ s/.*:://;
    __PACKAGE__ eq caller and exists $dispatch{$meth}
        or croak "Undefined subroutine &$AUTOLOAD called";
    goto &$dispatch{$meth};
}

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: 23 Feb 2004 01:49:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Private methods within a Perl Object module
Message-Id: <c1bm85$8bg$2@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
> 
>   AS> Quite generally, this kind of setup, which is going to be used by other
>   AS> subs, should go into a BEGIN block, so it is ready when the subs are
>   AS> ready.  It may often not matter, but sometimes it does.
> 
> this doesn't need any BEGIN block and the real problem and fix is below:

No, it doesn't *need* BEGIN (as far as we know the code), and I pointed
out as much.  However, I've been bitten often enough by routines that
need initialization when trying to call such a beast too early (often
for debugging purposes).  I like it when a routine is runnable as soon
as it is compiled.

[...]

Anno


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

Date: Sun, 22 Feb 2004 17:29:03 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Questions on PAR
Message-Id: <slrnc3iepv.jgv.tadmc@magna.augustmail.com>

chatiman <chatiman@free.fr> wrote:
> "Tad McClellan" <tadmc@augustmail.com> a écrit dans le message de news:
> slrnc3hcs1.j2i.tadmc@magna.augustmail.com...
>> chatiman <chatiman@free.fr> wrote:
>>
>> > I'm interested in using PAR for my CGI scripts.
>>
>> What to you hope to gain by using PAR for your CGI scripts?
>>
> source code obfuscation 


What to you hope to gain by having source code obfuscation for 
your CGI scripts?


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


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

Date: Mon, 23 Feb 2004 12:02:43 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: Really unbuffered reads...
Message-Id: <c1bn04$ohn$1@bunyip.cc.uq.edu.au>

Anno Siegel wrote:

> Matthew Braid  <mb@uq.net.au.invalid> wrote in comp.lang.perl.misc:
<snip>
>>		$ok = [1, $1] if $buffer =~ PGP_SIGOK;
> 
>                                             ^^^^^^^^^
> Uh... I suppose that's a constant that returns a regex.

Whoops - sorry, yeah it does.

> Use select() or IO::Select to see if the filehandle is ready for reading.
> You could also make it non-blocking, but I don't know how well that works
> with sysread().
> 
> In both cases you'll have to decide what to do if the handle never
> becomes ready, and how long "never" is.

As a quick fix I used a couple of surrounding alarm statements, which 
worked for a while until another test case came along that led to the 
solution.

My first two test cases were very similar, the third was much larger. It 
seems the first two were just on either side of a boundary problem (they 
differed in size by 23 bytes, so it was a close thing :) )

The problem was the output handle (not the error handle). The function 
that called the problem code was trying to handle verification, 
encryption and decryption. When it came to verification it sometimes 
decrypted the message instead of just verifying it so that the 
signatures on encrypted messages could be checked. Unfortunately, this 
meant that it 'threw away' the decrypted output but supplying an 
IO::Handle object that was never read from. It was also not closed until 
_after_ the error handle was scanned.

This meant that for large enough messages whatever underlying buffer 
IO::Handle has was filling up. What I was seeing in top was gpg sitting 
in pipe-write state, and my script sitting in pipe-read - but gpg was 
trying to write to the output handle, while my script was trying to read 
from its error handle. I had thought that the two were stuck on the same 
handle.

Once I changed the code so that if decryption is required for 
verification the output handle is undef (and thus the output disappears 
into the void) everything suddenly worked perfectly. It also explains 
why the problem only came up with verification - on encryption and 
decryption the output filehandle was opened to a temp file (I needed to 
keep it, and I needed it seekable), so the data could pretty much flow 
straight through unhindered.

Phew :)

Thanks for mentioning select though - looks a little cleaner than alarms...

MB



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

Date: Sun, 22 Feb 2004 17:11:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <slrnc3idpe.jgv.tadmc@magna.augustmail.com>

Lukas Mai <rwxr-xr-x@gmx.de> wrote:
> Tad McClellan schrob:
> [...]
> 
>> You should not use modifiers that you don't understand. m//o is
>> useless for your pattern.
> 
>>    my $tail = $1 if $the_number =~ m/\d+(.*)/s;
> 
> Whoa! Don't do that! 


Why not?


> The behaviour of
> `my $foo if bar;' is undefined 


I believe that that is incorrect.

The docs themselves use that form twice that I can see:

   perl -ne 'print "$ARGV: $_" if /^\s+my\b.*\bif\b/' *.pod

   perltooc.pod:   my $class = ref $self if $self;
   perlwin32.pod:  my @g = File::DosGlob::glob($_) if /[*?]/;


> (see perldoc perlsyn).


Whereabouts in perlsyn, exactly?

I looked for every occurance of "my", "undef" and "defined"
in perlsyn.pod, and I didn't see that anywhere.

Please quote a bit of perlsyn that made you think that the behavior is
not defined.


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


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

Date: Mon, 23 Feb 2004 00:29:13 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c1bhgp$le2$1@wisteria.csv.warwick.ac.uk>


tadmc@augustmail.com wrote:
> Lukas Mai <rwxr-xr-x@gmx.de> wrote:
> > Tad McClellan schrob:
> > [...]
> > 
> >> You should not use modifiers that you don't understand. m//o is
> >> useless for your pattern.
> > 
> >>    my $tail = $1 if $the_number =~ m/\d+(.*)/s;
> > 
> > The behaviour of
> > `my $foo if bar;' is undefined 
> 
> I believe that that is incorrect.
> 
> > (see perldoc perlsyn).
> 
> Whereabouts in perlsyn, exactly?

From perlsyn.pod of 5.8.2, at the end of the section "Statement
Modifiers":
| NOTE: The behaviour of a "my" statement modified with a statement
| modifier conditional or loop construct (e.g. "my $x if ...") is
| undefined.  The value of the "my" variable may be "undef", any
| previously assigned value, or possibly anything else.  Don't rely on
| it.  Future versions of perl might do something different from the
| version of perl you try it out on.  Here be dragons.

Presumably what is meant is 'The value of the "my" variable [if the
condition is false] may be...'

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: 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 6180
***************************************


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