[16948] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4360 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 18 14:10:38 2000

Date: Mon, 18 Sep 2000 11: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: <969300619-v9-i4360@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 18 Sep 2000     Volume: 9 Number: 4360

Today's topics:
        Parsing a Report <jstone211@my-deja.com>
    Re: Parsing a Report (Clay Irving)
    Re: Password protecting a script nobull@mail.com
    Re: Perl and Databases FAQ (Tony L. Svanstrom)
    Re: perl and web <timewarp@shentel.net>
    Re: Possible to generate html frames from perl ??? <gellyfish@gellyfish.com>
    Re: Printing to a printer without "|lp" <gellyfish@gellyfish.com>
    Re: Printing to a printer without "|lp" <kj0@mailcity.com>
        Pure perl encrypt/decryption? grymoire@my-deja.com
    Re: Pure perl encrypt/decryption? <rlm@pricegrabber.com>
    Re: Pure perl encrypt/decryption? <Thomas.Kratz@lrp.de.nospam>
    Re: Pure perl encrypt/decryption? <godzilla@stomp.stomp.tokyo>
    Re: Pure perl encrypt/decryption? nobull@mail.com
    Re: Question about Overloading "=" (Daniel Chetlin)
    Re: Question to the Wise - Writing Spaces <gellyfish@gellyfish.com>
        Rant: Re: An identd faking ident. nobull@mail.com
    Re: Rant: Re: An identd faking ident. (Abigail)
    Re: Recipe For Sorting LoL <gellyfish@gellyfish.com>
    Re: Running a perl program as a daemon? (Rafael Garcia-Suarez)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 18 Sep 2000 16:31:28 GMT
From: J. Stone <jstone211@my-deja.com>
Subject: Parsing a Report
Message-Id: <8q5g10$p1t$1@nnrp1.deja.com>

I need to parse a report, and some columns will be blank.  Such as

                 COMPANY X
                 ---------

            Current        Month-to-Date         Year-to-Date
            -------        -------------         ------------

INTEREST    $1,555                                $1,555
DIVIDENDS   $2,000         $5000                 $16,000

What is the best way to parse this report so as to KNOW that the Month
to date column is 0?  I will need to load these values to a database
eventually.  There will be a lot of columns like this, and I will need
to know how to handle this.  And there will be various sections of the
report that will have data like this for me to parse.

Any suggestions will be greatly appreciated.

Thanks.
J. Stone



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 18 Sep 2000 17:40:29 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Parsing a Report
Message-Id: <slrn8scksd.7kc.clay@panix2.panix.com>

On Mon, 18 Sep 2000 16:31:28 GMT, J. Stone <jstone211@my-deja.com> wrote:

>I need to parse a report, and some columns will be blank.  Such as
>
>                 COMPANY X
>                 ---------
>
>            Current        Month-to-Date         Year-to-Date
>            -------        -------------         ------------
>
>INTEREST    $1,555                                $1,555
>DIVIDENDS   $2,000         $5000                 $16,000
>
>What is the best way to parse this report so as to KNOW that the Month
>to date column is 0?  I will need to load these values to a database
>eventually.  There will be a lot of columns like this, and I will need
>to know how to handle this.  And there will be various sections of the
>report that will have data like this for me to parse.
>
>Any suggestions will be greatly appreciated.

Something like this?

   #!/usr/local/bin/perl -w
   
   while ($line = <DATA>) {
       if ($line !~ /^ |^\n/) {
           chomp $line;
           ($name, undef, $mtd) = unpack("a10a9a20", $line);
           $mtd =~ s/\s+//g;
           $name =~ s/\s+$//g;
           if (! $mtd) {
               print "MTD for $name is blank\n";
           }
       }
   }
   
   __DATA__
                    COMPANY X
                    ---------
   
               Current        Month-to-Date         Year-to-Date
               -------        -------------         ------------
   
   INTEREST    $1,555                                $1,555
   DIVIDENDS   $2,000         $5000                 $16,000
   

prints:

   MTD for INTEREST is blank

-- 
Clay Irving <clay@panix.com>
Let us treat men and women well; treat them as if they were real; perhaps
they are. 
- Ralph Waldo Emerson 


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

Date: 18 Sep 2000 17:46:46 +0100
From: nobull@mail.com
Subject: Re: Password protecting a script
Message-Id: <u9aed5hcll.fsf@wcl-l.bham.ac.uk>

Geoff Soper <g.soper@soundhouse.co.uk> writes:

> In article <8ptilk$90v$1@msunews.cl.msu.edu>, Eric <eric.kort@vai.org>
> wrote:
> > This is a cgi script being served by Apache?  Use .htaccess and
> > .htpasswd. See for example http://faq.clever.net/htaccess.htm
> 
> Providing the user closes all instances of his web browser (effectively
> logging out) after he finishes is this comepletely secure?

That's a question about the user's web browser, not about Perl.

If the user has asked the broswer is set to remember passwords between
sessions then anyone else running the same browser as the same user on
the same machine will be able to log in again without re-entering the
password.  This is true whether you use basic HTTP authentication or
roll your own password screen using CGI scripts and HTML forms.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 18 Sep 2000 18:54:31 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Perl and Databases FAQ
Message-Id: <1eh64ax.1q01qdrlf08e6N%tony@svanstrom.com>

<pohanl@my-deja.com> wrote:

> The following is a Mini-FAQ on...
> 
> Perl and Databases

How did you know that i was going to ask a question about that? ;)

What I'd like to know is why this is such an extremly bad idea; we're
talking bad idea to the point where this "harmless" little thing creates
a file that is at least a couple of sizes too big (832K), and if I add
some more to it Perl crasches with an Out of memory-message (MacPerl).

    use DB_File ;
    use vars qw( %h $k $v ) ;

    tie %h, "DB_File", " -fruit", O_RDWR|O_CREAT, 0640, $DB_HASH
        or die "Cannot open file 'fruit': $!\n";

    # Add a few key/value pairs to the file
    $h{"1"}{"apple"} = "red" ;
    $h{"1"}{"orange"} = "orange" ;
    $h{"1"}{"banana"} = "yellow" ;
    $h{"1"}{"tomato"} = "red" ;
    $h{"2"}{"apple"} = "red" ;
    $h{"2"}{"orange"} = "orange" ;
    $h{"2"}{"banana"} = "yellow" ;
    $h{"2"}{"tomato"} = "red" ;
    $h{"3"}{"apple"} = "red" ;
    $h{"3"}{"orange"} = "orange" ;
    $h{"3"}{"banana"} = "yellow" ;
    $h{"3"}{"tomato"} = "red" ;



     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: Mon, 18 Sep 2000 13:05:58 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: perl and web
Message-Id: <39C64B76.8A6D8C5E@shentel.net>

daud11@hotmail.com wrote:

> Hi
>
> I installed Perl in my windows NT server. I wanted to use it from the
> web as a CGI program. At first I got it working ie I was able to
> execute it from the web server using http://www..../cgi-bin/script.pl.
>
> Now it is no longer working. When the above url is tested it seems to
> download the file. Why? and how do i fix it?
>
> thanks
> Daud11
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

Have you set the permissions to execute only?
If they are read only, then the script will not execute and be considered
a downloadable file.
I set all my scripts to the bare minimum and that is chmod 711 on a unix
machine.
Not sure how this translates into NT speak but there it is....

Albert Dewey



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

Date: 18 Sep 2000 06:57:01 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Possible to generate html frames from perl ???
Message-Id: <8q4ard$gqm$1@orpheus.gellyfish.com>

On Sun, 17 Sep 2000 19:47:59 GMT Sean Malloy wrote:
> Alone@Work.com (Alone) wrote:
>>Is it possible to generate an html frameset without writing to a file?
> 
> Certainly. On the website that I administer, I use a Perl script to
> generate framesets so that the search engine links to properly-framed
> pages (top banner, left menu, right content) based on the results of
> searches that locate information in the content pages. Here's the
> script (once the print statements start, any line _not_ starting with
> 'print' is wrapped from the previous line until you get to the
> document close tag):
> 
> ---------------------------------
> #!/usr/local/bin/perl
> $hostname = "www-nmcsd.med.navy.mil";
> $len = length($ARGV[0]);
> @path = split("/",$ARGV[0]);
> $basename = @path[$#path];
> $#path -= 1;
> $root = join("/",@path);
> print "Content-type: text/html\n\n";
> print "<HTML>\n";
> 
<snip squillions of print() statements>

Looks like a very clear case for a here docucument.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 18 Sep 2000 07:07:27 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Printing to a printer without "|lp"
Message-Id: <8q4bev$grh$1@orpheus.gellyfish.com>

On 17 Sep 2000 16:37:55 -0400 kj0 wrote:
> 
> I've written a CGI script for in-house use that, among other things,
> prints barcode labels via a networked barcode printer.  I can get the
> printing to work if I do something like:
> 
>   open  BARCODE_PRINTER, "|/usr/bin/lp -d zebra" or PFFff_f_t(__LINE__);
>   print BARCODE_PRINTER $gobbledeyGook;
>   close BARCODE_PRINTER;
> 
> But the above will crash my script if I turn on taint checking.  I
> understand the problem has to do with the implicit fork done by the
> open command.
> 
> Therefore, I would like to print directly to the printer without
> forking a new process.  
> 

No you don't, you want to clean up the problems with your environment
that the taint checking throws up.  You will want to read the perlsec
manpage and the perldiag entry for the messages that you get.

Subverting the print spooling mechanism by writing directly to the
printer device is bound to end in tears - but it is simply a matter
of opening the appropriate device file for writing and printing to it.
Of course this takes no account of the issue of concurrent access (which
the print spooler deals with for you) or any processing that the interface
programs for the printer might do.

But really you will be far better off trying to fix your tainting problem.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 18 Sep 2000 13:58:02 -0400
From: kj0 <kj0@mailcity.com>
Subject: Re: Printing to a printer without "|lp"
Message-Id: <8q5l3a$doj$1@panix3.panix.com>

In <8q4bev$grh$1@orpheus.gellyfish.com> Jonathan Stowe <gellyfish@gellyfish.com> writes:

>No you don't, you want to clean up the problems with your environment
>that the taint checking throws up.  You will want to read the perlsec
>manpage and the perldiag entry for the messages that you get.

I did read it before posting, and it explicitly mentions the problem
with "|lp".  The solution they give seemed very convoluted at the time
(spawning a child process and stripping it of all privileges, to do
the printing).  There was no mention of any solution via cleaning up
%ENV.  I know for a fact that explicitly setting $ENV{'PATH'} (the
variable taint complains about) doesn't help.  I'll look at perldiag,
though.

KJ


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

Date: Mon, 18 Sep 2000 15:31:28 GMT
From: grymoire@my-deja.com
Subject: Pure perl encrypt/decryption?
Message-Id: <8q5cgg$kq6$1@nnrp1.deja.com>

I'm setting up a web page, and need an encryption (not hash) function
that is in pure perl. My ISP doesn't want to install any
external modules. I've looked at the perl modules but all the ones
I've looked at use an external library.


Is there a pure perl encryption/decryption routine someplace?
This is for low volume data, so speed isn't important.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 18 Sep 2000 08:58:22 -0700
From: Rob McMillin <rlm@pricegrabber.com>
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <39C63B9E.5B3871A9@pricegrabber.com>

grymoire@my-deja.com wrote:

> I'm setting up a web page, and need an encryption (not hash) function
> that is in pure perl. My ISP doesn't want to install any
> external modules. I've looked at the perl modules but all the ones
> I've looked at use an external library.
>
> Is there a pure perl encryption/decryption routine someplace?
> This is for low volume data, so speed isn't important.

Not that I've seen.


--
          http://www.pricegrabber.com | Dog is my co-pilot.





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

Date: Mon, 18 Sep 2000 18:23:47 +0200
From: "Thomas Kratz" <Thomas.Kratz@lrp.de.nospam>
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <39c64550.0@juno.wiesbaden.netsurf.de>


grymoire@my-deja.com wrote in message <8q5cgg$kq6$1@nnrp1.deja.com>...
>I'm setting up a web page, and need an encryption (not hash) function
>that is in pure perl. My ISP doesn't want to install any
>external modules. I've looked at the perl modules but all the ones
>I've looked at use an external library.
>
>
>Is there a pure perl encryption/decryption routine someplace?
>This is for low volume data, so speed isn't important.
>


What about Crypt::Blowfish_PP ? (the PP stands for Pure Perl)

--
Thomas




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

Date: Mon, 18 Sep 2000 09:35:33 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <39C64455.AEDE1A48@stomp.stomp.tokyo>

grymoire@my-deja.com wrote:

> Is there a pure perl encryption/decryption routine someplace?
> This is for low volume data, so speed isn't important.


Mix and match as you wish. With a little thought, you 
will decrypt my last two encrypted encryption routines.
If you are smart, you will beta test extensively before
messing with valuable data.


TEST SCRIPT:
____________


#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";

$sample = "Green Hornet Secret Decoder Ring";

print "Input Sample Is: 
     $sample\n\n";


## Encode:

$random_key = int(rand(2));

if (!($random_key))
 {
  srand;
  $random_key = int(rand(2));
 }

if ($random_key == 0)
 { $sample =~ tr/a-zA-Z/h-za-gH-ZA-G/; }

elsif ($random_key == 1)
 { $sample =~ tr/a-zA-Z/t-za-sT-ZA-S/; }

else
 { print "Random Key Generation Failed"; exit; }

$sample = reverse ($sample);

$sample =~ s/(.)/sprintf('%02x',ord($1))/ge;

$sample = join ("", $sample, $random_key);

print "Encoded Sample Is:
     $sample\n\n";


## Decode:

$random_key = chop ($sample);

$sample =~ s/([0-9A-Fa-f]{2})/sprintf("%c",hex($1))/ge;

$sample = reverse ($sample);

if ($random_key == 0)
 { $sample =~ tr/h-za-gH-ZA-G/a-zA-Z/; }

elsif ($random_key == 1)
 { $sample =~ tr/t-za-sT-ZA-S/a-zA-Z/; }

else
 { print "Random Key Generation Failed"; exit; }

print "Decoded Sample Is:
     $sample\n\n";



print "\n\n\n";

######



$sample = "God's Little Girl Kicks Ass!";

print "Input Sample Is: 
     $sample\n\n";

## Encode:

$sample =~ tr/ H-OV-ZP-UA-G/ˆ‰Š›œ‚ƒ„…†‡‹ŒŽ“”•–—˜™š/;

$sample = reverse ($sample);

$sample =~ s/(.)/sprintf('%02x',ord($1))/ge;

$sample =~ tr/975318642abcdef/†‡‹ŒŽŠ›œ“”•–—/;
                                 
print "Encode: 
     $sample \n\n";

## Decode

$sample =~ tr/†‡‹ŒŽŠ›œ“”•–—/975318642abcdef/;

$sample =~ s/([0-9A-Fa-f]{2})/sprintf("%c",hex($1))/ge;

$sample = reverse ($sample);

$sample =~ tr/ˆ‰Š›œ‚ƒ„…†‡‹ŒŽ“”•–—˜™š/ H-OV-ZP-UA-G/;

print "Decode: 
     $sample \n\n";



print "\n\n\n";

######



$sample = "Godzilla Rocks N Rolls!";

print "Input Sample Is: 
     $sample\n\n";

## Encode:

$sample =~ tr/ H-OV-ZP-UA-G/“”•–—˜™š›œ‚ƒ„…†‡ˆ‰Š‹ŒŽ/;

$sample = reverse ($sample);

$sample =~ s/(.)/sprintf('%02x',ord($1))/ge;

$sample =~ tr/975318642abcdef/…‡‰873514“•—™›/;
                                 
print "Encode: 
     $sample \n\n";

## Decode

$sample =~ tr/…‡‰873514“•—™›/975318642abcdef/;

$sample =~ s/([0-9A-Fa-f]{2})/sprintf("%c",hex($1))/ge;

$sample = reverse ($sample);

$sample =~ tr/“”•–—˜™š›œ‚ƒ„…†‡ˆ‰Š‹ŒŽ/ H-OV-ZP-UA-G/;

print "Decode: 
     $sample \n\n";



print "\n\n\n\n";



@© = (a .. z); @® = qw (7 15 4 26 9 12 12 1 18 15 3 11 19);
srand(time() ^ ($$ + ($$ << 15))); for ($§ = $®[$®[0]]; 
$§ < $®[0]-2; $§++) { sub G { rand(1000) < 500 ? "\u$1" : "\l$1" ; }
foreach $¿ (@®) { $¢ = $©[$¿-1]; $¢ =~ s¡([a-z])¡G($1)¡gie;
$Ø = "$Ø$¢"; } $Ø ="$Ø! "; $ø = substr ($Ø, $®[12] - $®[11], 0, " ");
$Ø =~ s¯(a)(r)¯$1 $2¯i; push (@Ø,$Ø); } foreach $¡ (@Ø)
{ print "$¡\n"; } @¶ = reverse (@Ø); foreach $¶ (@¶)
{ print "$¶\n"; } exit;



PRINTED RESULTS:
________________


Input Sample Is: 
     Green Hornet Secret Decoder Ring

Encoded Sample Is:
     7a67624b206b787768767857206d786b76784c206d78676b6841206778786b5a1

Decoded Sample Is:
     Green Hornet Secret Decoder Ring




Input Sample Is: 
     God's Little Girl Kicks Ass!

Encode: 
     œ‡Œ‡Œ†›ŽŽ‡ŒŠ“ŠŒŠ††”ŽŽŠ”‡œŠ††ŽŽŠ‹Š”‡›‡›Š†ŽŽŽ‡Œœ‡Š›Š—† 

Decode: 
     God's Little Girl Kicks Ass! 




Input Sample Is: 
     Godzilla Rocks N Rolls!

Encode: 
     47‡85—5—535‡……‡‡85•58535‡575—5—5…‡“515…0 

Decode: 
     Godzilla Rocks N Rolls! 





gOdZiLlA roCks! 
gOdZiLlA  roCks! GOdZilla ROcKs! 
gOdZiLlA   roCks! GOdZilla ROcKs! GOdZILlA roCKS! 
gOdZiLlA    roCks! GOdZilla ROcKs! GOdZILlA roCKS! godzilLA rOCks! 
gOdZiLlA    roCks! GOdZilla ROcKs! GOdZILlA roCKS! godzilLA rOCks! 
gOdZiLlA   roCks! GOdZilla ROcKs! GOdZILlA roCKS! 
gOdZiLlA  roCks! GOdZilla ROcKs! 
gOdZiLlA roCks!


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

Date: 18 Sep 2000 17:54:08 +0100
From: nobull@mail.com
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <u98zsphc9b.fsf@wcl-l.bham.ac.uk>

grymoire@my-deja.com writes:

> I'm setting up a web page, and need an encryption (not hash) function
> that is in pure perl. My ISP doesn't want to install any
> external modules. I've looked at the perl modules but all the ones
> I've looked at use an external library.

Take a look at the Crypt:: modules on CPAN.  Pay particular attension
to the ones with "pure Perl" in their on-liner descriptions.

There aren't all that many to choose from I'm affraid.	

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 18 Sep 2000 15:18:59 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: Question about Overloading "="
Message-Id: <Dnqx5.4941$o6.30089@news-west.usenetserver.com>

On Fri, 15 Sep 2000 13:03:37 GMT,
 alphazerozero@my-deja.com <alphazerozero@my-deja.com> wrote:
>I was wondering if anyone knew of any Modules on CPAN that overload the
>"=" operator.
>Ive been reading the documentation for overload but every time I do I
>get more confused not less.
>
>Any help on this subject would be very apreciated.

It can be very confusing. I've been meaning to change the wording in
overload.pm for a while, but have been caught up fixing other things.

The difficult thing to understand about '=' is what it really affects.
Most people initially assume that overloading '=' means that when I
assign one object to another, the subroutine I specified for '=' is
called. But if you think about it from a Perl point of view, this would
make no sense.

In Perl, an object is simply a reference (note to self: try not to use
the word "thingy" in this post). If we do this:

  package MyPackage;
  sub new { 
      my $self = $_[0];
      bless { foo => $_[1] }, ref($self) || $self;
  }

  package main;
  my $a = MyPackage::->new(1);

We've created an object of type MyPackage. However, $a itself _is not_
the object, $a is not a member of MyPackage, and it hasn't been blessed.
It simply _points_ to the object we created.

    /---\         /--------------------------------\
    | a | ------> | instance of MyPackage: foo = 1 |
    \---/         \--------------------------------/

And now, we create a new variable $b, and assign $a to it:

  package main;
  my $b = $a;

What has happened here? Remember that $a and $b are references, and
they're just pointing to other things. If $a was a reference to an
unblessed array, and we executed the above assignment, would we create a
brand new array for $b to point to? Of course not. $b would be pointing
to the same array. So in our case, all that has changed is:

    /---\         /--------------------------------\
    | a | ------> | instance of MyPackage: foo = 1 |
    \---/    /--> \--------------------------------/
             |
    /---\    |
    | b | ---/
    \---/

We now have two variables pointing to the same object. Things are as
they should be.

Ah, but what happens if we try to change one of them? Well, it depends
on how you try to change it. If you treat it like a normal reference to
an object, overloading has nothing to do with it. If you go and modify
$a->{foo}, it will of course be reflected when you ask for $b->{foo}.
Just like always, it's your responsibility to create a new copy if you
want one. So the only question is what happens if you try to modify them
with an overloaded operation?

  my $c = $a + $b;

Well, actually, nothing, because we forgot to overload addition, so Perl
has no way of knowing how to add a MyPackage.

  package MyPackage;
  use overload q/+/ => \&add;

  sub add {
      $_[0]->new( $_[0]->{foo} + (ref($_[1]) ? $_[1]->{foo} : $_[1]) )
  }

In the add subroutine, we're creating a new instance of MyPackage with
its foo attribute initialized to the foo attribute of the first operand
plus either the foo attribute of the second operand if it's a MyPackage
and the actual value of the second operand if it's not. (In real code
we'd probably do a little more error checking to make sure we're not
passed, say, an IO::Socket as our second operand).

  package main;
  my $c = $a + $b;

This time, it works. If you take a look at $c, it points to a brand new
instance of MyPackage.

    /---\         /--------------------------------\
    | a | ------> | instance of MyPackage: foo = 1 |
    \---/    /--> \--------------------------------/
             |
    /---\    |
    | b | ---/
    \---/
    /---\         /--------------------------------\
    | c | ------> | instance of MyPackage: foo = 2 |
    \---/         \--------------------------------/

So in the case of a binary operation, Perl relies on us to provide the
right subroutine. If we'd had our add subroutine return an reference to
a URI object, it would have still worked, and $c would now point to that
URI object.

So what happens when we use a mutator like `++'?

  $b++;

Believe it or not, Perl does the right thing here. Remember, we haven't
overloaded `++', nor have we overloaded `='. But look at our revised
structure:

    /---\         /--------------------------------\
    | a | ------> | instance of MyPackage: foo = 1 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | b | ------> | instance of MyPackage: foo = 2 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | c | ------> | instance of MyPackage: foo = 2 |
    \---/         \--------------------------------/

So now you're thinking "Hey, everyone always told me that you overload
`=' for mutators!" Ah, but we didn't actually overload the mutator `++'.
Perl just saw us use the increment operator and translated that into an
addition operation, namely $b+1. And because we wrote our add function
intelligently, everything worked out.

But let's say we decide that autoincrement for MyPackage has to do
something special -- it's going to double the value in foo, rather than
add 1 to it.

  package MyPackage;
  use overload q/++/ => sub { $_[0]->{foo}*=2; shift };  

  package main;
  $d = $c;
  $d++;

Oops -- we get a fatal runtime error:

  Operation `=': no method found, argument in overloaded package
  MyPackage at overload.pl line 26.

So _now_ it's asking for the copy constructor, because we have a custom
autoincrement. We'll add a very simple one:

  package MyPackage;
  use overload q/=/ => sub { $_[0]->new($_[0]->{foo}) };

All we're doing here is asking for a new object, which is pretty much
exactly what was happening before we added our custom autoincrement. So,
we try the above code again:

  package main;
  $d = $c;

Let's stop here and look at our structures:

    /---\         /--------------------------------\
    | a | ------> | instance of MyPackage: foo = 1 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | b | ------> | instance of MyPackage: foo = 2 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | c | ------> | instance of MyPackage: foo = 2 |
    \---/    /--> \--------------------------------/
             |
    /---\    |
    | d | ---/
    \---/

And now, we do the increment:

  $d++;

And voila, our new autoincrement has worked:

    /---\         /--------------------------------\
    | a | ------> | instance of MyPackage: foo = 1 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | b | ------> | instance of MyPackage: foo = 2 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | c | ------> | instance of MyPackage: foo = 2 |
    \---/         \--------------------------------/
    /---\         /--------------------------------\
    | d | ------> | instance of MyPackage: foo = 4 |
    \---/         \--------------------------------/

So the point of this insanely long example is that:

  a) You rarely need to worry about overloading the copy constructor
     unless you also overload `++' (or another mutator), which in turn
     you rarely need to worry about unless you want it to mean
     something other than += 1 (or the standard meaning for the mutator
     you've chosen).

  b) When you do overload `++' (or some other mutator), you'll need to
     overload `=' as well, but in general it will be a very
     straightforward function, doing pretty much exactly what Perl does
     underneath when you don't overload your mutators but let it derive
     them for you.

  c) The documentation for overload is confusing and oddly ordered.
     Hopefully I'll get that fixed before 5.6.1.

-dlc




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

Date: 18 Sep 2000 07:30:36 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Question to the Wise - Writing Spaces
Message-Id: <8q4cqc$gta$1@orpheus.gellyfish.com>

On Fri, 15 Sep 2000 18:59:20 GMT desertedge@my-deja.com wrote:
> I need to read this data, and print it to an HTML file "as is". To save
> the VB programmer days, or months, of re-formating the data to html
> tables

To a Perl programmer creating the tables would probably be just as simple
as any other of the solutions you have been suggested and an hours work
at the most.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 18 Sep 2000 18:23:37 +0100
From: nobull@mail.com
Subject: Rant: Re: An identd faking ident.
Message-Id: <u9vgvtfwbq.fsf@wcl-l.bham.ac.uk>

abigail@foad.org (Abigail) writes:

> # A simple identd program, that has no intention of revealing any system
> # information.
> # The program expects to be run from inetd, and hence, only reads from
> # STDIN. It will ignore all arguments given, nor will it pay attention
> # to any of the environment variables.
> # Appropriate errors are generated when the request is syntactically
> # not valid, or when the given ports are out of bounds.
> # For valid requests, regardless whether the ports are in use or not,
> # a random OS and a random user name are picked from a fixed set of
> # names. These random values are, appropriately formatted, returned.

What the!!!???

What kind of K00l d00d would want such a script?

This is plain cyber-valdalism.

If you don't want identd then simply don't run it.  If there are
people out there who refuse to talk to you if you don't respond to
ident requests then are they really worth talking to?

Servers that log ident info on requests do so in order to _help_ the
admins of the client sites track abusive users.  If your site has only
one user at a time and you know who that is then there's no reason to
respond to ident requests.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 18 Sep 2000 18:02:29 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Rant: Re: An identd faking ident.
Message-Id: <slrn8scm3g.h8o.abigail@alexandra.foad.org>

nobull@mail.com (nobull@mail.com) wrote on MMDLXXV September MCMXCIII in
<URL:news:u9vgvtfwbq.fsf@wcl-l.bham.ac.uk>:
:} 
:} If you don't want identd then simply don't run it.  If there are
:} people out there who refuse to talk to you if you don't respond to
:} ident requests then are they really worth talking to?

Unfortunally, yes.



Abigail
-- 
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};


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

Date: 18 Sep 2000 07:19:16 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Recipe For Sorting LoL
Message-Id: <8q4c54$gsa$1@orpheus.gellyfish.com>

On Sun, 17 Sep 2000 18:05:58 GMT andre_sanchez@my-deja.com wrote:
> In article <slrn8s85pm.ntr.mgjv@martien.heliotrope.home>,
>   mgjv@tradingpost.com.au wrote:
> 
>> Sort by first key first, then by second:
>>
>> sub sortsub { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] }
>>
> 
> I would like to sort by successive keys, in a fashion similiar to the
> one you describe, but for the more general case where the number of
> elements in the lists are not known in advance and that may vary for
> each
> succesive list.

You could use a loop in your search sub - which is probably not such a
great idea, or you can pack your sort keys in the manner of the GRT so
the sort sub doesnt need to be changed.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Mon, 18 Sep 2000 15:20:00 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Running a perl program as a daemon?
Message-Id: <slrn8scd15.j2e.rgarciasuarez@rafael.kazibao.net>

Damien Dove wrote in comp.lang.perl.misc:
>Hi all. I was wondering how you program a perl script as a daemon using
>inetd.

If it's run from inetd, it's not a daemon. A daemon is a program that
runs continuously in the background ; this is not the case of the
servers run by inetd. (see the manpage of your system for inetd).

>At the moment i have a program that runs selected commands to a schedule.
>I'd like to convert that program to a daemon. What things do i have to
>change etc.. Is there any information on the web that could shed some light
>on the issue?

A good tutorial on how to write daemons is at
  http://www.webreference.com/perl/tutorial/9/

-- 
Rafael Garcia-Suarez | http://rgarciasuarez.free.fr/


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4360
**************************************


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