[8613] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2230 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 2 05:07:24 1998

Date: Thu, 2 Apr 98 02:00:26 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 2 Apr 1998     Volume: 8 Number: 2230

Today's topics:
    Re: ANNOUNCE: /bin/sh to Perl translator finally availa <swimmer@digital.de>
        current week <GERT.FRANCOIS@SD.BE>
    Re: current week <Tony.Curtis+usenet@vcpc.univie.ac.at>
        Data Structure for Input File (CH3704)
    Re: Diddling with search engines via CGI (Daniel Koch)
    Re: foreach loop & current element index <rjk@coos.dartmouth.edu>
    Re: foreach loop & current element index <rjk@coos.dartmouth.edu>
    Re: HELP !!! - Templates within Perl (Andy Wardley)
    Re: HELP !!! - Templates within Perl (Oliver Fischer)
        How to answer "is $this in @that"? <kairys@mi.sl.com>
    Re: How to answer "is $this in @that"? <ljz@asfast.com>
    Re: How to answer "is $this in @that"? <tchrist@mox.perl.com>
        i'm dumb...help!! search stuff (Fa Q 242)
    Re: Number of Perl Users/Instalitations. <quillan@doitnow.com>
        outputing dir to html page (Mike Lai)
        Perl and MySQL <dukat.2@osu.edu>
    Re: Perl dies with segmentation fault and leaves a core <rdpierce@mema.mail.fedex.com>
    Re: random picture for web page (Jeff Yoak)
        Tie/bless vs. bless/tie and segmentation fault lehman@javanet.com
    Re: Tie/bless vs. bless/tie and segmentation fault lehman@javanet.com
    Re: Use of implicit split to @_ is deprecated <rjk@coos.dartmouth.edu>
        use strict and GD (Tom Mornini)
    Re: verifying email address -- how? <metcher@spider.herston.uq.edu.au>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 02 Apr 1998 10:35:08 +0200
From: Stefan Wimmer <swimmer@digital.de>
Subject: Re: ANNOUNCE: /bin/sh to Perl translator finally available!
Message-Id: <35234DBC.41C6@digital.de>

Stuart McDow wrote:
> 
> Randal Schwartz <merlyn@stonehenge.com> writes:
> >
> > Yes!  Finally!  The long-awaited "Shell to Perl" translator is now available!
> 
> Damn!! I fell for it!! Forgot to check the date. D'oh!!! Very cute.
> 
> --
> Stuart McDow                                     Applied Research Laboratories
> smcdow@arlut.utexas.edu                      The University of Texas at Austin
>   "It is obvious that about 750,000 people ago, Austin was a wonderful City."

I already found it last week & tried to use it - wonderful =8-)

Reinstalled it today - even better !!:)

Regards 
Stefan

-- 
Stefan Wimmer               Online Services	
Digital Equipment GmbH      Tel: 089/9591-4459
Freischuetzstr. 91          Fax: 089/9591-1050
81927 Muenchen              email: swimmer@digital.de
----------------------------------------------------------
	"Never touch a running systemmanager ..."
----------------------------------------------------------


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

Date: Thu, 02 Apr 1998 10:16:00 +0200
From: FRANCOIS GERT <GERT.FRANCOIS@SD.BE>
Subject: current week
Message-Id: <35234940.298E@SD.BE>

Hi,

I'm using perl 5.004_02 on an NT-platform;

Can anyone can give me a piece of code, or just a method I can
use to calculate the current weeknumber (1 - 52) ?
Can I use the localtime -function ?

Thans in advance

Gert Frangois
Consultant Zeno
Antwerp - Belgium
GERT.FRANCOIS@SD.BE


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

Date: 02 Apr 1998 11:07:42 +0200
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
To: GERT.FRANCOIS@SD.BE
Subject: Re: current week
Message-Id: <7xhg4cy4kh.fsf@beavis.vcpc.univie.ac.at>

Re: current week, FRANCOIS <GERT.FRANCOIS@SD.BE> said:

FRANCOIS> Hi, I'm using perl 5.004_02 on an NT-platform;

FRANCOIS> Can anyone can give me a piece of code, or just a
FRANCOIS> method I can use to calculate the current
FRANCOIS> weeknumber (1 - 52) ?  Can I use the localtime
FRANCOIS> -function ?

Use the Date::DateCalc and/or Date::Manip modules.

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,      | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/

"Everything I am, I learned on the back of cereal boxes" ~ RJ, "Over the Hedge"


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

Date: 2 Apr 1998 06:58:35 GMT
From: ch3704@aol.com (CH3704)
Subject: Data Structure for Input File
Message-Id: <1998040206583500.BAA07133@ladder03.news.aol.com>


I am having a hard time trying to accomplish the following task.  I am writing
a Perl script that reads an input records from an UNIX file of approximately
400 bytes. The input records do have a common layout, but the records do not
contain a separator between each individual field.  I need to figure out a way
to define a layout of the record, so that I can modify information on the input
record before the information is used to update columns in an Oracle instance. 
The individual fields range in size from 1 byte to 40 bytes.  The input file
will be extremely large at times.  The file may contain up to 500,000 records.

Thank you in advance for assistance.

Carol Houts
     




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

Date: Thu, 02 Apr 1998 07:10:44 GMT
From: dkoch@amcity.com (Daniel Koch)
Subject: Re: Diddling with search engines via CGI
Message-Id: <3523394e.399995358@news.vnet.net>

On Wed, 01 Apr 1998 01:39:23 GMT, john13@interlog.com (John Russell)
wrote:

>I've done some launching of search engines like Altavista via
>Javascript.  (Open a window with the URL http:// ... + my query.)  Now
>I would like to do more elaborate things using Perl and LWP.
>
>Is there a body of knowledge about this subject already?  For example,
>I guess that anyone doing this kind of thing needs to know:
>
>- Is there a method to make the search engines return very long lists
>of results rather than a set of small pages with "next" links?  Which
>search engines are best or worst in this regard?
>
>- Do all search engines use CGI-friendly ?-encoded URLs for their
>query results?
>
>- Is there reusable code specifically for working with search engine
>results (e.g. compare if "hits" from 2 engines are really the same,
>transform results into standard format, etc.)?
>

http://www.perl.com/CPAN-local/modules/by-module/WWW/

from the readme for WWW::Search:

WHAT IS WWW::Search?
--------------------

WWW::Search is a collection of Perl modules which provide an API to
WWW search engines.  Currently WWW::Search includes back-ends for
variations of AltaVista, Dejanews, Excite, HotBot, Infoseek, and
Lycos.

CPAN is your friend.

Regards,

Dan Koch <dkoch@amcity.com>



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

Date: Wed, 01 Apr 1998 23:51:15 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: foreach loop & current element index
Message-Id: <35231946.A0D82D23@coos.dartmouth.edu>

Rick Schofield wrote:
> 
> Alexandra Stehman wrote:
> 
> > The question was:  "When in a foreach loop, is there a special variable
> > or perl function that can be used to determine the index of the current
> > array element?"
> >
> 
>    Sure.  $_.  Simple, no?

Um...  What does that have to do with the index of the current array element? 
I don't think you understood the question.

If you want to know the index, use a for loop instead of a foreach loop.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 01 Apr 1998 23:59:45 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: foreach loop & current element index
Message-Id: <35231B44.18F079F@coos.dartmouth.edu>

Alexandra Stehman wrote:
> 
>  for ($i=1; $i==@theArray; $i++){...}
> where the loop stops when $i is equal to the number of elements in
> @theArray.

You seem to be confused about the meaning of the condition in a for loop.  The
for loop stops when the condition is *false*, not when it is true.  You're
also skipping the first element; Perl arrays start at index 0, not 1.

  DB<1> @array = qw(foo bar baz)

  DB<2> for ($i=0; $i==@array; $i++) { print "$a[$i]\n" }

  DB<6> for ($i=0; $i<@array;  $i++) { print "$a[$i]\n" }
foo
bar
baz


What you meant was

for ($i=0; $i<@theArray; $i++){...}

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 2 Apr 1998 06:34:07 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: HELP !!! - Templates within Perl
Message-Id: <Eqrwwv.G11@cre.canon.co.uk>

T. de Konink <tkonink@horizon.nl> wrote:
>I'm looking for a way of using HTML templates within Perl CGI-scripts,
>so I can isolate HTML-code (for script-output) from the script-source.
>The problem is that the (html-)output contains some variables, which are
>used inside the script.

There is more than one way to do this.

Have a look at Text::MetaText.  This should do what you want.

You can defined a template file such as:

header:
   <html>
   <head>
     <title>%% title %%</title>
   </head>
   <body bgcolor="%% bgcolor %%">

and then from your CGI script, do something like this:

  use Text::MetaText;

  my $mt = new Text::MetaText;

  print $mt->process_file('header', {
          'title'   => 'This is a test',
          'bgcolor' => '#ffffff'
      });

  ...

The variable values get filled in by the process_file() method.  You can
also do other things like including files with files.  That way, you can
generate a template file for a given CGI application that pulls in other
standard elements:

my_app_template:
   %% INCLUDE header %%

   %% message %%
 
   ...other stuff...
   
   %% INCLUDE footer %%

You would process it the same way:

   print $mt->process('my_app_template', {
          'title'   => 'This is a test',
          'bgcolor' => '#ffffff',
          'message' => 'Welcome to My_App',
      });

which saves you having to process the header, then print a title, print the
application output, then process the footer, and so on.
          
There are also Text::Template and Parse:ePerl which may be suitable 
alternatives, although they expect perl code to be embedded with the 
file.

Text::MetaText is available from CPAN

    http://www.perl.com/CPAN/modules/by-authors/Andy_Wardley

The current version (0.15) is available there now.  The latest development
version (0.18 or 0.19) will be released some time later today.


A

--
Andy Wardley <abw@kfs.org> http://www.kfs.org/~abw    
Signature lost in transit.  We apologise for any inconvenience caused.


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

Date: Thu, 02 Apr 1998 08:58:53 GMT
From: fischer@desert.de (Oliver Fischer)
Subject: Re: HELP !!! - Templates within Perl
Message-Id: <352351ab.9939211@newshost.rz.hu-berlin.de>

On Wed, 01 Apr 1998 17:15:29 +0200, "T. de Konink"
<tkonink@horizon.nl> wrote:

>Hi,
>
>I'm looking for a way of using HTML templates within Perl CGI-scripts,
>so I can isolate HTML-code (for script-output) from the script-source.
>The problem is that the (html-)output contains some variables, which are
>used inside the script.
>

hi,

i am writing a module that uses templates. i call it HtmlDataParser.

ok, here are two examples:

<!--{ name='abc' }-->

now, the parser look for an literal in the object with the name 'abc'.
if is exist, the parser replace the metatag with the literals value.

<!--{ type='text' name='afield' }-->

in this case, the parser creates a text-input field with the name
'afield' and the value of the literal 'afield'.





in diesem sinne

oliver fischer // fischer@desert.de


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

Date: Wed, 1 Apr 1998 13:36:08 -0500
From: "Michael Kairys" <kairys@mi.sl.com>
Subject: How to answer "is $this in @that"?
Message-Id: <3522952a.0@news.ic.net>

There must be a simple way, but I haven't found it, to find out if a given
scalar is in a list. Of course I can write myself a function like:

    sub isin
        {
        my ( $elem, @list ) = @_;
        foreach ( @list ) { return 1 if $elem eq $_; }
        return 0;
        }

 .. but there must be a simple way...




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

Date: 02 Apr 1998 00:19:27 -0500
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: How to answer "is $this in @that"?
Message-Id: <lun2e44x7k.fsf@asfast.com>

"Michael Kairys" <kairys@mi.sl.com> writes:

> There must be a simple way, but I haven't found it, to find out if a given
> scalar is in a list. Of course I can write myself a function like:
>     sub isin
>         {
>         my ( $elem, @list ) = @_;
>         foreach ( @list ) { return 1 if $elem eq $_; }
>         return 0;
>         }
> 
> ... but there must be a simple way...

Here's one possibility:

   if (grep(/^$elem$/, @list)) {
      print "element found\n";
   }

Here's a variation:

   if (grep { $_ eq $elem } @list) {
      print "element found\n";
   }

And here's a different, more complicated approach, but one that some
people here might consider to be more "elegant" in a strange sort of
way (I inserted some extra white space in hope of making this a tiny
bit clearer):

   if ( do { my %temp; @temp{@list} = (); exists( $temp{$elem} ) } ) {
      print "element found\n";
   }

I hope this helps.

-- 
 Lloyd Zusman
 ljz@asfast.com


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

Date: 2 Apr 1998 08:49:02 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to answer "is $this in @that"?
Message-Id: <6fvjdu$dvc$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Michael Kairys" <kairys@mi.sl.com> writes:
:There must be a simple way, but I haven't found it, to find out if a given
:scalar is in a list. 

That's because you haven't bothered to read the standard FAQ that
is included with every perl distribution.  It answers this.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    I think I'm likely to be certified before Perl is...  :-) 
	--Larry Wall in <1995Feb12.061604.6008@netlabs.com>


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

Date: 2 Apr 1998 06:28:36 GMT
From: faq242@aol.com (Fa Q 242)
Subject: i'm dumb...help!! search stuff
Message-Id: <1998040206283601.BAA03784@ladder03.news.aol.com>

I've noticed that some link submittion sites check for a reciprical link.  I
want to add this to one of my scripts...I'm sure it's easy, but I dunno how to
go about this.

I would get the url of the webpage my link is supposed to be on through a
form...So I just want to search that specific page.

Thanks!


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

Date: Wed, 01 Apr 1998 22:39:25 -0700
From: "John C. Quillan" <quillan@doitnow.com>
Subject: Re: Number of Perl Users/Instalitations.
Message-Id: <3523248C.22E5807C@doitnow.com>

brian d foy wrote:

> In article <3520823B.6C0397B9@doitnow.com>, "John C. Quillan" <quillan@doitnow.com> posted:
>
> > Any information based on Number of Downloads, Number of books sold,
> > etc.. would be
> > helpfull.
>
> number of books sold won't be very useful since i know quite a few
> people that own multiple copies of the Camel and so on :)  i've
> personally downloaded the same version of perl several times, so
> you would have he same problem with that figure as well.

Actually I am just trying to get a ball park range.  I figure I can come closewith a few sets
of figures.


>
>
> --
> brian d foy                                 <http://computerdog.com>
> Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
> Perl Mongers <URL:http://www.pm.org>
> let's hope there aren't 300,000 "i use perl" posts...





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

Date: Thu, 02 Apr 1998 09:38:31 GMT
From: mclai@binnie.demon.co.uk (Mike Lai)
Subject: outputing dir to html page
Message-Id: <35235686.6137124@news.demon.co.uk>

I am trying to output a directory listing within a html page.
I am running perl5 , MS Personal Web Server and Netscape 4.x all running under Windows 95
The code below runs on the command line (i.e in a command box) but not from an URL in Netscape.
Somehow, it is not interpreting $mydir=`dir`. Is this the case and if so, how else can you get at a directory listing
into a web page.

$mydir=`dir`;
print "Content-type: text/html\n\n";
print "<html>";
 ...
print "<pre>";
print "$mydir";
print "</pre>";
print "</html>";


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

Date: Thu, 02 Apr 1998 00:43:27 -0500
From: Alexander Dukat <dukat.2@osu.edu>
Subject: Perl and MySQL
Message-Id: <3523257E.B7AE8641@osu.edu>

I have gotten the following error and am wondering if anyone can explain
in general what it means, or if someone knows how to resolve it that
would also be great.  If not if I could be pointed in the right
direction.  Thanks

Can't load '/usr/lib/perl5/site_perl/i586-linux/auto/DBD/mysql/mysql.so'
for module DBD::mysql: File not found at
/usr/lib/perl5/i586-linux/5.00404/DynaLoader.pm line 166.


Alex




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

Date: Thu, 02 Apr 1998 02:03:47 -0600
From: Richard Pierce <rdpierce@mema.mail.fedex.com>
To: joseph@5sigma.com
Subject: Re: Perl dies with segmentation fault and leaves a core
Message-Id: <35234663.4A77E00@mema.mail.fedex.com>

I have experienced some seg faults with the pre-built Perl package for
Solaris.  I corrected by obtaining the latest version of Perl and
installing the old-fashion way, complete configure, make, and install.

Richard

Joseph N. Hall wrote:

> Perl should not crash.  With few exceptions this is a perl bug.
> You should post code and/or submit the bug with the perlbug program.
>
>         -joseph
>          http://www.effectiveperl.com
>
> Bob wrote:
> >
> > Is there anything that a user script can do to cause a Segmentation
> > fault and core dump, or is it a perl bug?





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

Date: Thu, 02 Apr 1998 07:33:15 GMT
From: jeff@yoak.com (Jeff Yoak)
Subject: Re: random picture for web page
Message-Id: <6fveue$bfc@dfw-ixnews3.ix.netcom.com>

[posted and emailed]

stanz@en.com (stan zylowski) wrote:

>hello,
>i am new to perl. but i would like to know if there are any random picture 
>scripts or random quote scripts.  i am familiar with javascript but
>want to offer random functions to all browsers

The following script can be seen in action at
http://joe-the-circle.com/eight.html and is a fun example of what you
have in mind.  Good luck with your own!

Cheers,
Jeff

#!/usr/local/bin/perl -w
use strict;

$|=1;

### First a couple definitions
my $basedir='/mnt/web/guide/joe-the-circle';
my $answerdir=$basedir."/images/answers";

### Create the CGI object.
use CGI;
my $query = new CGI;

### What is the question?
my $question = $query->param('question');
chomp($question);

### Is it a good question?

my ($img,$msg);
if ($question !~ /\w\s\w/) {	# Questions have at least two words.
	$img='../images/dope.gif';
	$msg="So where's your question?";
} elsif ($question =~ /<.+?>/){	# Clumsy HTML Catcher
	$img='../images/dope.gif';
	$msg="Lay off the HTML!";
} else {				# OK
	opendir(DIR,"$answerdir") || die "Couldn't open directory $!";
	my @imagefilenames = grep !/^\.\.?$/, readdir DIR;
	closedir(DIR);
	$img='../images/answers/'.$imagefilenames[rand(@imagefilenames)];
	$msg="Your question was <STRONG>$question</STRONG><P>Joe says:\n";
}

### Output top stuff

print $query->header;
print $query->start_html(-title=>"Joe's Answer",
              -author=>'webmaster@joe-the-circle.com',
              -meta=>{'keywords'=>'comics',
                      'copyright'=>'copyright 1998 Mike Shapiro'},

-BACKGROUND=>'http://joe-the-circle.com/images/back.gif');

### Print from textfile
open(IN,'nineball.txt') || die "Couldn't open source file $!";
while(<IN>) {
	s/\$\$IMG\$\$/$img/;
	s/\$\$MSG\$\$/$msg/;
	print;
}
close(IN);

### Output bottom stuff
print $query->end_html;

-- 
Jeff Yoak         jeff@yoak.com



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

Date: Thu, 02 Apr 1998 05:49:07 GMT
From: lehman@javanet.com
Subject: Tie/bless vs. bless/tie and segmentation fault
Message-Id: <nFFU.216$CX.709888@ptah.visi.com>

I'm doing something sort of weird which isn't really all that weird, but
it's weird enough to freak out perl (5.004_02 under Gurusamy Sarathy's
Win32 port and 5.004_01 under FreeBSD 2.1.7.1, but not 5.003_0 under
SunOS 5.5.1).

I'm tying the hash inside of an object to another object.  At first I didn't
know whether it was even going to be possible, but I gave it a shot and it
seems to work great.  But there's a catch:

If, inside of A::new(), I bless the hash as class A before tying it to
class B, then everything's cool when I retain a reference to object A
inside of B.  But if I tie the hash to class B before blessing it as
class A, then perl gets a segmentation fault when it shuts down if I don't
explicitly remove the reference to object A before the destruction of B.
Does that make any sense?  It might be moot, because I'm not sure I really
need to retain a reference to A from inside B, but I'm thinkin' that perl
ought not to be coughing up a lung in my lap in the latter case.

Why am I tying a blessed hash in the first place?  Well, I'm playing around
with multi-level tied hash structures where the components down the tree act
as first-class objects as well as tied hashes.  That is, I want to write
things like...

   $DB->{Person}{$oid}{FirstName} = "Fred";
   $DB->{Person}{$oid}{LastName} = "Flintstone";
   $DB->{Person}{$oid}->Smite("Big Toe", "Bowling Ball");

 ...where each object in the hierarchy supports the object method calling
convention but also has its attributes hash tied (for persistence and
other fun things).  To do this takes two classes, because hidden object
attributes like internal filenames and things like that can't be stored
in the tied hash object -- the tied hash object is only for accessing
visible object attributes.

I can make this all work, but I'm curious to learn why perl is more lenient
with me when I tie a blessed hash than when I bless a tied hash.  In either
case I think it's best if I explicitly unlink the two objects inside DESTROY
so I don't confuse the reference-count garbage collector, but it shouldn't
be crashing (should it?).

The code below is really to be part of a larger chunk of code for a simple
embedded multiple-tied-DB_File RDBMS, so what's shown is a contrived version
of the real thing -- but it crashes perl nonetheless, and that's the real
curiosity.  (I struck out at DejaNews and FMTEYEWTK about tie.)

--
Todd Lehman
lehman@javanet.com

_____________________________________________________________________________

#!/bin/perl
use strict;
$^W = 1;


my $DB;


#
# --- HAPPY
#
$DB = new Happy::A;
$DB->{Person} = new Happy::A;
#
$DB->{Person}{1} = new Happy::A;
$DB->{Person}{1}{FirstName} = "Fred";
$DB->{Person}{1}{LastName} = "Flintstone";
print "$DB->{Person}{1}{FirstName} $DB->{Person}{1}{LastName}\n";
$DB->{Person}{1}->Smite("Belly", "Dino");
#
$DB->{Person}{2} = new Happy::A;
$DB->{Person}{2}{FirstName} = "Barney";
$DB->{Person}{2}{LastName} = "Rubble";
print "$DB->{Person}{2}{FirstName} $DB->{Person}{2}{LastName}\n";
$DB->{Person}{2}->Smite("Big_Toe", "Bowling_Ball");


#
# --- NOT HAPPY
#
$DB = new Crashes::A;
$DB->{Person} = new Crashes::A;
#
$DB->{Person}{1} = new Crashes::A;
$DB->{Person}{1}{FirstName} = "Fred";
$DB->{Person}{1}{LastName} = "Flintstone";
print "$DB->{Person}{1}{FirstName} $DB->{Person}{1}{LastName}\n";
$DB->{Person}{1}->Smite("Belly", "Dino");
#
$DB->{Person}{2} = new Crashes::A;
$DB->{Person}{2}{FirstName} = "Barney";
$DB->{Person}{2}{LastName} = "Rubble";
print "$DB->{Person}{2}{FirstName} $DB->{Person}{2}{LastName}\n";
$DB->{Person}{2}->Smite("Big_Toe", "Bowling_Ball");


#
# --- These execute just fine...
#
package Happy::A;  # Main object
   sub new
   {
      my $self = bless {}, shift;         # Bless $self first,
      tie %$self, 'Happy::B';             # Then tie %$self.
      $self;
   }
   sub DESTROY
   {
      my ($self) = @_;
      untie %$self;
   }
   sub AUTOLOAD
   {
      my ($self, @args) = @_;
      print "$Happy::A::AUTOLOAD @args\n";
   }

package Happy::B;  # Implements tie inside main object
   sub TIEHASH
   {
      my ($class, $obj) = @_;
      bless { DATA=>{}, OBJ=>$obj }, $class;
   }
   sub FETCH
   {
      my ($self, $k) = @_;
      ref $self->{DATA}{$k}?  $self->{DATA}{$k} : uc $self->{DATA}{$k};
   }
   sub STORE
   {
      my ($self, $k, $v) = @_;
      $self->{DATA}{$k} = $v;
   }


#
# --- But Perl 5.004_0[12] crashes sometime after cleanup with these...
#
package Crashes::A;  # Main object
   sub new
   {
      my ($class) = @_;
      my $self = {};
      tie %$self, 'Crashes::B', $self;    # Tie %$self first,
      bless $self, $class;                # Then bless $self.
   }
   sub DESTROY
   {
      my ($self) = @_;
      # If the next line is uncommented, then perl doesn't crash at exit.
      # (tied %$self)->Unref;  # Hmm...  Why necessary?
      untie %$self;
   }
   sub AUTOLOAD
   {
      my ($self, @args) = @_;
      print "$Crashes::A::AUTOLOAD @args\n";
   }

package Crashes::B;  # Implements tie inside main object
   sub Unref
   {
      my ($self) = @_;
      delete $self->{OBJ};   # Hmm...  Why necessary?
   }
   sub TIEHASH
   {
      my ($class, $obj) = @_;
      bless { DATA=>{}, OBJ=>$obj }, $class;
   }
   sub FETCH
   {
      my ($self, $k) = @_;
      ref $self->{DATA}{$k}?  $self->{DATA}{$k} : uc $self->{DATA}{$k};
   }
   sub STORE
   {
      my ($self, $k, $v) = @_;
      $self->{DATA}{$k} = $v;
   }



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

Date: Thu, 02 Apr 1998 07:58:29 GMT
From: lehman@javanet.com
Subject: Re: Tie/bless vs. bless/tie and segmentation fault
Message-Id: <FyHU.281$CX.779179@ptah.visi.com>

In article <nFFU.216$CX.709888@ptah.visi.com>, <lehman@javanet.com> wrote:
> [code & text snipped]

Oops...  In my previous post, my function Happy::A::new was neglecting
to pass $self to Happy::B::TIEHASH, so that appears to be why it wasn't
crashing perl while the other pair of classes did crash it.  Sorry about
that.

I rearranged things a bit to remove the kludgey Unref() member function and
use DESTROY() instead.  This way, both the crashing and uncrashing versions
of the tied-hash class are identical.  I made the main (outer) class have
two constructors new_tb and new_bt for tie-then-bless and bless-then-tie,
respectively, and now the example crashing code is much smaller.

So now my curiosity is no longer Why does it crash in one case and not the
other, but Why does it crash in both cases?  :-)

--
Todd Lehman
lehman@javanet.com
____________________________________________________________________________

#!/bin/perl
use strict;
$^W = 1;

my $TB = new_tb Foo;
$TB->{Person} = new_tb Foo;
$TB->{Person}{1} = new_tb Foo;
$TB->{Person}{1}{FirstName} = "Fred";
$TB->{Person}{1}{LastName} = "Flintstone";
print "$TB->{Person}{1}{FirstName} $TB->{Person}{1}{LastName}\n";
$TB->{Person}{1}->Smite("Belly", "Dino");
$TB->{Person}{2} = new_tb Foo;
$TB->{Person}{2}{FirstName} = "Barney";
$TB->{Person}{2}{LastName} = "Rubble";
print "$TB->{Person}{2}{FirstName} $TB->{Person}{2}{LastName}\n";
$TB->{Person}{2}->Smite("Big_Toe", "Bowling_Ball");

my $BT = new_bt Foo;
$BT->{Person} = new_bt Foo;
$BT->{Person}{1} = new_bt Foo;
$BT->{Person}{1}{FirstName} = "Fred";
$BT->{Person}{1}{LastName} = "Flintstone";
print "$BT->{Person}{1}{FirstName} $BT->{Person}{1}{LastName}\n";
$BT->{Person}{1}->Smite("Belly", "Dino");
$BT->{Person}{2} = new_bt Foo;
$BT->{Person}{2}{FirstName} = "Barney";
$BT->{Person}{2}{LastName} = "Rubble";
print "$BT->{Person}{2}{FirstName} $BT->{Person}{2}{LastName}\n";
$BT->{Person}{2}->Smite("Big_Toe", "Bowling_Ball");


package Foo;

sub new_tb  # Tie then bless
{
   my ($class) = @_;
   my $self = {};
   tie %$self, $class."::Tie", $self;
   return bless $self, $class;
}
sub new_bt  # Bless then tie
{
   my ($class) = @_;
   my $self = bless {}, $class;
   tie %$self, $class."::Tie", $self;
   return $self;
}
sub DESTROY
{
   my ($self) = @_;
   untie %$self;
}
sub AUTOLOAD
{
   my ($self, @args) = @_;
   print "$Foo::AUTOLOAD @args\n";
}


package Foo::Tie;

sub TIEHASH
{
   my ($class, $obj) = @_;
   bless { DATA=>{}, OBJ=>$obj }, $class;
}
sub DESTROY
{
   my ($self) = @_;
   delete $self->{OBJ};
   delete $self->{DATA};
}
sub FETCH
{
   my ($self, $k) = @_;
   ref $self->{DATA}{$k}?  $self->{DATA}{$k} : uc $self->{DATA}{$k};
}
sub STORE
{
   my ($self, $k, $v) = @_;
   $self->{DATA}{$k} = $v;
}



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

Date: Thu, 02 Apr 1998 00:07:29 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Use of implicit split to @_ is deprecated
Message-Id: <35231D14.7F60AF95@coos.dartmouth.edu>

Jason Gloudon wrote:
> 
> If you want to count the number of elements returned by split you should say
> $x = scalar(@junkarray = split), which says explicitly what you want and what
> actually happens.

$x = () = split; works too.  Although it might look a little weird, it's a lot shorter.

On a related note, does anyone know why the 'Use of implicit split to @_ is
deprecated' warning is not output in the debugger?

~> perl -de 1
[...]
  DB<1> $^W = 1

  DB<2> $_ = "foo bar baz"

  DB<3> $x = split  # no warning

  DB<4> p $]
5.004

~ > perl -w
$_ = "foo bar baz";
$x = split;  # warning
Use of implicit split to @_ is deprecated at - line 2.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 2 Apr 1998 09:42:47 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: use strict and GD
Message-Id: <tmorniniEqs5nC.3qK@netcom.com>

In an effort to clean house in preparation for a move to mod_perl,
I'm working on getting my CGI's to run using:

use strict;
use diagnostics;

In a script that also has:

use GD;

I'm now having trouble with the following line:

  $im->string(gdSmallFont,$CENX,$CENY,$LOTNUMBER,$black);

The error message is:

Bareword "GD::Font::gdSmallFont" not allowed while "strict subs" in use at
        /usr/local/etc/httpd/perl/pq-mp.mod_perl line 879 (#1)
    
    (F) With "strict subs" in use, a bareword is only allowed as a
    subroutine identifier, in curly braces or to the left of the "=>" symbol.
    Perhaps you need to predeclare a subroutine?

I'm guessing that there is some magic goo that I can wrap that gdSmallFont
in to make Perl happy, but I can't figure it out!

Also, I'm formally complaining :-) about Perl's method of checking for
unitialized variables. If I have code that says:

01: my $foo='';

63: if ($foo)
64:  {
65:   print 'foo is';
66:  }
 
Perl will complain that $foo is unitialized at line 63, if $foo didn't
have any non-null values assigned between lines 1 and 63.

Where I come from, unitialized means just that...that you're assuming an
initial value. Setting a variable to null is definitely initializing it,
AFAIK!

I'll expect an immediate response to correct this horrendous error! :-)

Why is Perl so scandalized by null-valued variables?

-- Tom Mornini
-- InfoMania


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

Date: Thu, 02 Apr 1998 18:56:46 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: verifying email address -- how?
Message-Id: <352352CE.2706ABFB@spider.herston.uq.edu.au>

This is somewhat off-topic, but I'm making a case for the applicability
of perl in this area:

John Stanley wrote:
> 
> In article <35219ED3.DEF6051D@spider.herston.uq.edu.au>,
> Jaime Metcher  <metcher@spider.herston.uq.edu.au> wrote:
> >It doesn't cost much to do a quick check of a list of addresses that are
> >going on to a listserv.  For each address you get one of three results:
> >either definitely OK, obviously bogus, and who knows.
> 
> Nope, you get one of two results: "obviously bogus" and "who knows".
> Most of the addresses, if properly formed, are "who knows", until you
> send mail and get a response back from the recipient. At that point,
> they enter the "previously valid but may change to invalid at any time"
> catagory.
> 

In more detail, my three results are (in order): got an OK result from a
EXPN or RCPT (after necessary MX lookups), couldn't find the hostname at
all and/or the address looks weird, and neither of the above.  I might
not have mentioned that this system is a machine/human hybrid - you have
to eyeball the rejects.

You're right in that the first one definitely isn't definitely OK.  I
use it as a first step - can we *send* mail to that address.  In some
cases, as you and everyone else has pointed out, the answer to that is
not the same as the answer to "will the mail *get* there".

My point is that, in giving addresses a plausibility rating, there's a
big difference between the first case and the third.

> The value of simple checks to discard "obviously bogus" addresses is
> that the person entering it gets the clue that you are somewhat serious
> about entering a valid email address, even if you can't test it
> immediately.
> 
> >on, but when you see something like:
> >
> >Bill.Cilnton@dyselxia.com
> >
> >you reach for the "bogus" stamp and the ink-pad.
> 
> The domain exists. You have no way of knowing if the mailbox exists or
> not.  Just what criteria are you applying to this address to brand it
> "obviously bogus"?
> 

I can't get my SMTP host to accept mail for that address. InterNIC says
the domain doesn't exist.  Eyeballing says that two of the components in
that address could be regarded as mispelt variations of common
words/names.  You assumed I'd made a typo in the domain name - I'd
assume the same.  I'd say that's plenty of justification for getting on
the phone and asking Mr Cilnton if he's given me the right address.

> >The pay-off in my case
> >is reduced stress for those of my users who aren't *really* up to
> >dealing with listserv administration, even though it's their list.
> 
> At the expense of poor Mr. Cilnton at dyslexia.com...
That's dyselxia.com.

Poor Mr Cilnton had better get himself an account on an RFC822 compliant
mail server in a registered domain if he wants to have his address taken
seriously.  Or at least get used to writing "I know this looks weird but
it really is my address" after it.

-- 
Jaime Metcher


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2230
**************************************

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