[9457] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3050 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 3 16:16:56 1998

Date: Fri, 3 Jul 98 13:06:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 3 Jul 1998     Volume: 8 Number: 3050

Today's topics:
        newbie q: populating array with interpolated scalar? (Sweth Chandramouli)
    Re: newbie q: populating array with interpolated scalar <simonf@conduit.co.uk>
    Re: newbie q: populating array with interpolated scalar (Tad McClellan)
    Re: newbie q: populating array with interpolated scalar <quednauf@nortel.co.uk>
    Re: newbie q: populating array with interpolated scalar (Tad McClellan)
        newbie: server error <marty@ulster.net>
    Re: newbie: server error <quednauf@nortel.co.uk>
    Re: newbie: trying to remove unwanted data from an arra (John Hocking)
    Re: newbie: trying to remove unwanted data from an arra (Larry Rosler)
        Oh man, DO I love Perl ! (References to things that go  <quednauf@nortel.co.uk>
    Re: Oh man, DO I love Perl ! (References to things that <jdporter@min.net>
    Re: Oh man, DO I love Perl ! (References to things that <jll@skynet.be>
    Re: Oh man, DO I love Perl ! (References to things that (Mark-Jason Dominus)
    Re: Oh man, DO I love Perl ! (References to things that (Josh Kortbein)
    Re: Oh man, DO I love Perl ! (References to things that <zenin@bawdycaste.org>
    Re: Oh man, DO I love Perl ! (References to things that <worrall+unet@cs.bris.ac.uk>
    Re: Oh man, DO I love Perl ! (References to things that <zenin@bawdycaste.org>
    Re: Oh man, DO I love Perl ! (References to things that <aas@sn.no>
    Re: parsing MIME types (I.J. Garlick)
    Re: Passing arguments to perl CGI (John Hocking)
    Re: Passing arguments to perl CGI <tchrist@mox.perl.com>
    Re: Passing arguments to perl CGI (brian d foy)
        perl & postscript <martin_neumann@gmx.net>
    Re: perl & postscript <chris.wareham@blackwell.co.uk>
        perl and ENV variables ??? <abcdm@wanadoo.fr>
    Re: perl and ENV variables ??? <qdtcall@esb.ericsson.se>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 02 Jul 1998 11:48:48 GMT
From: sweth-usenet@astaroth.nit.gwu.edu (Sweth Chandramouli)
Subject: newbie q: populating array with interpolated scalar?
Message-Id: <sweth-usenet-0207980748000001@alex-va-n013c081.moon.jic.com>

   i've got a perl script that ends up with a scalar ($values) that
consists of a series of comma-separated values.  i want to use this to
populate an associative array (%names), so that if $values contained
"one,bob,two,joe,three,fred", %names would contain the three pairs
(one,bob), (two,joe), and (three,fred).
   i would assume, from the examples in the camel and llama books, that
"%names = ($values)" would work, but it doesn't--it treats $values as one
item, rather than six comma-separated items.
   what am i missing here?

   tia,
   sweth.

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


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

Date: Thu, 2 Jul 1998 13:41:27 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: newbie q: populating array with interpolated scalar?
Message-Id: <359b7f38.0@nnrp1.news.uk.psi.net>

Hmmmm I'll be interested to hear why but I would think it has something to
do with the ordering of things (thinking aloud)

Regardless of the above if you want to get it working try:

%names = eval $values;

I'm not sure why this works, sorry, I can only assume it forces $values to
be evaluated which helps in the assignment *shrug* I hate it when I get
something to work without a full understanding.

Simon

PS: BTW they are called hashes now, I thought I better tell you before
someone makes a comment regarding how much space is saved by using 'hash'
rather than 'associative array' ;-)

Sweth Chandramouli wrote in message ...
>   i've got a perl script that ends up with a scalar ($values) that
>consists of a series of comma-separated values.  i want to use this to
>populate an associative array (%names), so that if $values contained
>"one,bob,two,joe,three,fred", %names would contain the three pairs
>(one,bob), (two,joe), and (three,fred).
>   i would assume, from the examples in the camel and llama books, that
>"%names = ($values)" would work, but it doesn't--it treats $values as one
>item, rather than six comma-separated items.
>   what am i missing here?
>
>   tia,
>   sweth.
>
>--
>Sweth Chandramouli
>IS Coordinator, The George Washington University
><sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
><a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>




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

Date: Thu, 2 Jul 1998 07:53:10 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: newbie q: populating array with interpolated scalar?
Message-Id: <mrvfn6.sv2.ln@localhost>

Sweth Chandramouli (sweth-usenet@astaroth.nit.gwu.edu) wrote:
:    i've got a perl script that ends up with a scalar ($values) that
: consists of a series of comma-separated values.  


  Using the Text::CSV module would likely be very helpful to you then.


: i want to use this to
: populate an associative array (%names), so that if $values contained
: "one,bob,two,joe,three,fred", %names would contain the three pairs
: (one,bob), (two,joe), and (three,fred).


   No problem.


:    i would assume, from the examples in the camel and llama books, that

   Those are some awfully big books. I can't take the time to go scan
   them for examples of populating hashes.

   You probably should either give the *exact* code, or give us a page
   number or something (and which Edition).



: "%names = ($values)" would work, 

   You have made some mistake here.

   I don't believe The Books would have that code anywhere in them.

   But, since we don't know which book/edition/page/code you are
   referring to, there isn't much we can do to identify where the
   mistake is.

   I'll bet it is not in The Books though!   ;-)


: but it doesn't--it treats $values as one
: item, 


   Good. Because it *is* one item.


: rather than six comma-separated items.


   You should arrange to provide six comma-separated items then, 
   rather than a single scalar.


:    what am i missing here?


   a split()


-----------------------------
#!/usr/bin/perl -w

$values = 'one,bob,two,joe,three,fred';

%names = split /\s*,\s*/, $values;

foreach (sort keys %names)
   {print "$_ ==> $names{$_}\n"}
-----------------------------


   But that, of course, will not handle quoted fields and whatnot.

   That is what Text::CSV is for  ;-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 02 Jul 1998 13:57:53 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: newbie q: populating array with interpolated scalar?
Message-Id: <359B83D1.B1DE22E5@nortel.co.uk>

Sweth Chandramouli wrote:
> 
>    i would assume, from the examples in the camel and llama books, that
> "%names = ($values)" would work, but it doesn't--it treats $values as one
> item, rather than six comma-separated items.
>    what am i missing here?

It seems that no interpolation occurs within a list creator, which you should
consider as being a Good Thing. In order to achieve your task you would have to
split $values. The split function then delivers a proper list context and fills
up the hash. There might be other tricks, but I'd do something like that:

%names = split (/,/, $values);

or 

eval "%names = ($values)";

HTH!

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Thu, 2 Jul 1998 08:41:39 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: newbie q: populating array with interpolated scalar?
Message-Id: <jm2gn6.d73.ln@localhost>

Simon Fairey (simonf@conduit.co.uk) wrote:
: Hmmmm I'll be interested to hear why but I would think it has something to
: do with the ordering of things (thinking aloud)

   Nope. It has something to do with the _quantity_ of things.


: Regardless of the above if you want to get it working try:

: %names = eval $values;


   You should be using the -w switch to enable warnings you know.

   Really.

   You should use -w on every single perl script that you ever write.

   I do.


   Using -w generates 6 warnings with your "solution"...



: I'm not sure why this works, sorry, 


   from 'perldata':

   --------------------
   =head2 List value constructors

   List values are denoted by separating individual values by commas
   --------------------


: I can only assume it forces $values to
: be evaluated 


   Right, mostly.

   Since the eval() is in a list context in the above usage,
   it interprets the commas as separating individual values.

   [ I guess.  Hmmm...

     Why does it interpret commas as separating list values
     rather than as the C style "comma operator"?

     ie. How does perl disambiguate the overloaded use of commas?
   ]


: which helps in the assignment *shrug* 


   Because it evaluates to a list containing six elements.


: I hate it when I get
: something to work without a full understanding.


   Hope you understand it better now.

   No need for eval() here anyway. See my other followup.
   


: Sweth Chandramouli wrote in message ...
: >   i've got a perl script that ends up with a scalar ($values) that
: >consists of a series of comma-separated values.  i want to use this to
: >populate an associative array (%names), so that if $values contained
: >"one,bob,two,joe,three,fred", %names would contain the three pairs
: >(one,bob), (two,joe), and (three,fred).
: >   i would assume, from the examples in the camel and llama books, that
: >"%names = ($values)" would work, but it doesn't--it treats $values as one
: >item, rather than six comma-separated items.
: >   what am i missing here?



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 02 Jul 1998 09:19:06 -0400
From: Marty Landman <marty@ulster.net>
Subject: newbie: server error
Message-Id: <359B88CA.5A64D460@ulster.net>

Newbie question:  I created the hello world script, my platform is
W95 and then uploaded it to my server (Unix).  On WWW I get a server
error, which really bugs me because I have some other scripts that do
work.  Anyhow, got on telnet and executed my script there and got 'hello

world' as expected.  The permissions for hello.cgi are 755 (-rwxr-xr-x).

What is it that I am not understanding about this?



--
Marty Landman
http://www.catnmoose.com
marty@catnmoose.com




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

Date: Thu, 02 Jul 1998 15:04:35 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: newbie: server error
Message-Id: <359B9373.CF5E2448@nortel.co.uk>

Marty Landman wrote:
> 
> Newbie question:  I created the hello world script, my platform is
> W95 and then uploaded it to my server (Unix).  On WWW I get a server
> error, which really bugs me because I have some other scripts that do
> work.  

> What is it that I am not understanding about this?

You possibly don't understand that the output to a browser has to look
differently than the output to a shell window. A browser likes to know what kind
of data it is getting. It likes it, because very thoughtful people decided a
long time ago that textfiles won't be the only thing that will be sent across
the web. So they devised a cunning plan to ensure that it would be possible to
send, say the contents of a jpeg file depicting the latest extravagant and
controversial pose of Demi Moore. So those Net-people, the creme de la creme of
modern society, thought of a header that would explain to the browser the
content-type of the oncoming body, and for html they rightfully thought that a
nice description could be text/html. Hmmm, so let us do it like that:

print "Content-type: text/html\n\n";

of course you worked on Windows, and all sorts of other things can happen then.
Especially certain characters might not get translated in the way you'd wish
them, and then the server won't recognise what is happening and gets all
confused about your script. Well, it is a hard life, and in a sort of weird way
I can only hope that the year 2000 will kill 95 % of all Computers. The other 5
%, of course, are running Perl scripts :)


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Thu, 02 Jul 1998 05:29:25 GMT
From: joker@inlink.com (John Hocking)
Subject: Re: newbie: trying to remove unwanted data from an array....
Message-Id: <359e19be.4029832@news.inlink.com>

On Wed, 01 Jul 1998 01:00:40 -0500, Bobn <"postmaster"@[127.0.0.1]>
wrote:

>Chad Thatcher wrote:
>> 
>> Steve Neuharth wrote:
>> >
>> > O.k. I KNOW there's an easy answer to this.... I can't seem to find it
>> > anywhere....
>> > I've got an array (@rawoutput). I only need the lines that contain
>> > "SUB-TOTAL:".... I'm trying some thing like this.....
>> > $x=0;
>> >    for ($y=0;$y <= @rawoutput; $y++){
>> >       if (@rawoutput[$y] =~ /SUB-TOTAL:/) {
>> >          @output[$x] = @rawoutput[$y];
>> >          $x++;
>> >       }
>> >    }
>> > @output never seems to populate with data (not sure why).
>
>WARNING: I haven't tested this, but I think, you should use:
>
>$output[$x] = $rawoutput[$y];
>
>When an element of an array is pointed to, it's a scalar.

 @output never seems to populate with data (not sure why).

Looking at the script I believe that your if statement is never true

 if (@rawoutput[$y] =~ /SUB-TOTAL:/) {

it might be a typo but I think it should read 

 if (@rawoutput[$y] =~ m/SUB-TOTAL:/) {

you left out the "m" for string match




John Hocking
Sr. Programmer
StudioPointe Incorporated
http://www.studiopointe.com
mailto:johnh@studiopointe.com


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

Date: Wed, 1 Jul 1998 23:02:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie: trying to remove unwanted data from an array....
Message-Id: <MPG.1004c2694f53485598970c@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <359e19be.4029832@news.inlink.com> on Thu, 02 Jul 1998 
05:29:25 GMT, John Hocking <joker@inlink.com> says...
 ...
>  if (@rawoutput[$y] =~ /SUB-TOTAL:/) {
> 
> it might be a typo but I think it should read 
> 
>  if (@rawoutput[$y] =~ m/SUB-TOTAL:/) {
> 
> you left out the "m" for string match

No.  The "m" is optional.  But referring to the *scalar* to be matched as

$rawoutput[$y]

is *not* optional!

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 02 Jul 1998 11:57:13 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <359B6789.D21A3605@nortel.co.uk>

With a grin on my face I can finally scan my mailbox and print out the messages
which got a hit, while only storing that at all stages that will become
displayed.

I am impressed with the following fact: I've got the following subroutine - - -

sub make_message {
  my $self = shift;
# ...
  my %message = ();
# assignments to %message
  return \%message;
}

and then it is called like that:

push @messages, $self->make_message(\$marker, \*ME);

Now I was almost expecting that, as a reference to %message is always returned,
all hashes pushed into @messages would have the same value, because all
reference %message, and this would probably be the case if %message is a global
variable (don't wanna try it :), but that doesn't happen here:


$results = $thing->search(what => "macracatam");
foreach $start(@$results) {
print $start->{subject};
print "\n-----------------------------\n\n";
print $start->{body};
print "\n**********end of body********\n\n";
}

prints out all messages that have been created with the make_message method. YES
! I am slowly beginning to realize the power of references to scoped variables.
And it suddenly made click with that example explained in the caeml book, where
a subroutine returns anonymous subroutines, which can later be called in the
context of their previous execution. So you can have many instances of the same
subroutine, all doing different things, as tey all work in different contexts.
Well, I know this is not Perl specific, but as I am exploring all these
wonderful things with Perl, you can consider yourself lucky of having had a
happy man talking here!


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Thu, 02 Jul 1998 15:51:55 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <359BAE5B.59CD@min.net>

F.Quednau wrote:
> 
> Well, I know this is not Perl specific, 

Geez, Frank, if this isn't Perl, what is it?
Feeling a little paranoid?  :-)

-- 
John Porter


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

Date: Thu, 02 Jul 1998 19:47:02 +0200
From: Jean-Louis Leroy <jll@skynet.be>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <VA.000000b1.0039a2c5@enterprise>

In article <359BAE5B.59CD@min.net>, John Porter wrote:
> F.Quednau wrote:
> > 
> > Well, I know this is not Perl specific, 

Well it could be LISP...but sure, Perl is a great language to do OO in. 
Certainly a match for C++ and Smalltalk.

But I wonder, why do relatively few people seem to do OO in Perl...at 
least that's the impression I get from reading the Perl NGs.

Jean-Louis Leroy
http://ourworld.compuserve.com/homepages/jl_leroy/



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

Date: 2 Jul 1998 14:24:40 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <6ngj98$aoj$1@monet.op.net>
Keywords: adjudge arteriosclerosis Celanese patrimony


In article <359BAE5B.59CD@min.net>, John Porter  <jdporter@min.net> wrote:
>F.Quednau wrote:
>> 
>> Well, I know this is not Perl specific, 
>
>Geez, Frank, if this isn't Perl, what is it?
>Feeling a little paranoid?  :-)

Yeah, I wish we had more articles like this.  The discussion and
opinion parts of the group are much more interesting to me than the
question-and-answer parts.


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

Date: 2 Jul 1998 20:58:15 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <6ngs97$q72$2@news.iastate.edu>

Jean-Louis Leroy (jll@skynet.be) wrote:
: In article <359BAE5B.59CD@min.net>, John Porter wrote:
: > F.Quednau wrote:
: > > 
: > > Well, I know this is not Perl specific, 

: Well it could be LISP...but sure, Perl is a great language to do OO in. 
: Certainly a match for C++ and Smalltalk.

: But I wonder, why do relatively few people seem to do OO in Perl...at 
: least that's the impression I get from reading the Perl NGs.

For me, it's taken a long time to start even caring about perl OO
because:

1) I've never really needed it in other languages yet
2) perl is so dense that it's taken a while to acclimate to the non-OO
features :)


Josh

--

________________________________________________________________________
Interviewer: "So Frank, you have long hair. Does that make you a woman?"
Frank Zappa: "You have a wooden leg. Does that make you a table?"



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

Date: 3 Jul 1998 07:42:37 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <899452309.483385@thrush.omix.com>

Jean-Louis Leroy <jll@skynet.be> wrote:
	>snip<
: But I wonder, why do relatively few people seem to do OO in Perl...at 
: least that's the impression I get from reading the Perl NGs.

	No language level support for private/protected/public fields
	is a big reason, IMO.

	If it's documented it's public, if not it's protected.  This
	I can deal with, and actually like.  But there is no private
	data.  Private data would make subclassing much easier and
	much, much safer.

	As it is now, the subclass must know a lot about the internals of
	it's super.  Even then, if the super desides to change something
	for itself (say, in an upgrade), it can trash the subclass.
	Such is the case if the super starts using a new field (say,
	$self->{foobar}).  A subclass that already exists may also be using
	that field (foobar).  This means that to upgrade the super may mean
	requiring it to then have extensive information abount all it's sub
	classes...blagh.  You can get past this with
	$self->{'Super::SubClass::foobar'}, but that's a very ugly kluge
	and doesn't really address the problem well.  Stephen Farrell
	and I are working on a system to do all this cleanly, but it's not
	ready for primetime yet, and requires a totally different object
	container style then most people use and is limited in other ways
	(public fields are pretty much non-existent).

	Basically, this makes it rather unproductive to try and sub class
	anything you didn't write and maintain yourself.

	Don't get me wrong, I love doing OO work in Perl.  Its just that
	simple things like this make it much, much harder to had sub classes
	off to a number of people to implement.  People can easily use
	other people's objects, so long as they don't try to subclass
	them...  Luckly for me I don't get into such situations oftin as
	I push for a uses relationship over a sub class relationship and
	typically win for the above reasons.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Fri, 3 Jul 1998 10:26:30 GMT
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <qppvfnw7qh.fsf@maxx.compsci.bris.ac.uk>

>>>>> "Zenin" == Zenin  <zenin@bawdycaste.org> writes:

    Zenin> No language level support for private/protected/public fields
    Zenin> is a big reason, IMO.

    Zenin> Such is the case if the super starts using a new field (say,
    Zenin> $self->{foobar}). A subclass that already exists may also be
    Zenin> using that field (foobar). This means that to upgrade the
    Zenin> super may mean requiring it to then have extensive
    Zenin> information abount all it's sub classes...blagh. You can get
    Zenin> past this with $self->{'Super::SubClass::foobar'}, but that's
    Zenin> a very ugly kluge and doesn't really address the problem
    Zenin> well.

Each object has its own hash, $self. Would it not be possible for each
class in an inheritance chain to access a hash ref within %$self, with
the key being the classname ? This is similar to the last example above,
but looks a little nicer. Basically, give each class its own namespace
within %$self.

I.e. if we have BaseCl, and InterCl, and SubCl, with InterCl being a
subclass of BaseCl and SubCl being a subclass of InterCl, an instance of
InterCl could access the following :

  $self->{'BaseCl'}{'foobar'}
  $self->{'InterCl'}{'foobar'}
  $self->{'SubCl'}{'foobar'}

Presumably, this will work OK as long as all class names in the
inheritance chain are unique, and I can't see why they wouldn't be.

Ahh, I suppose this might get ugly after you access a lot of variables.
And you couldn't easily change the class name.

Perhaps we could isolate it with a new 'standard' method like :

  sub GET_DATA {
    my $self = shift;
    return $self->{'SubCl'};  # Change this one line when renaming class
  }

  sub some_method_or_other {
    my $self = shift;
    my $data = $self->GET_DATA();

    $data->{'foobar'} = ...   # Where you'd use  $self->{'foobar'}
  }

Hmm, maybe this _is_ turning into a kludge after all.

  - Adam
-- 
 Adam.Worrall@bristol.ac.uk       http://www.cs.bris.ac.uk/~worrall/
 The London Mathematical Society  http://www.lms.ac.uk/


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

Date: 3 Jul 1998 11:12:43 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <899464915.248950@thrush.omix.com>

Adam Worrall <worrall+unet@cs.bris.ac.uk> wrote:
	>snip<
: Each object has its own hash, $self. Would it not be possible for each
: class in an inheritance chain to access a hash ref within %$self, with
: the key being the classname?

	Yes, but it's still klugy, and leads to even more bugs (more
	uncheckable strings to mistype...).

: I.e. if we have BaseCl, and InterCl, and SubCl, with InterCl being a
: subclass of BaseCl and SubCl being a subclass of InterCl, an instance of
: InterCl could access the following :
:   $self->{'BaseCl'}{'foobar'}
:   $self->{'InterCl'}{'foobar'}
:   $self->{'SubCl'}{'foobar'}
: Presumably, this will work OK as long as all class names in the
: inheritance chain are unique, and I can't see why they wouldn't be.

	@ISA = qw(HTML::Parser SGML::Parser);

	$self->{Parser} is who's?  You still need full package names, some
	how or another...

: Ahh, I suppose this might get ugly after you access a lot of variables.

	Yep.

: And you couldn't easily change the class name.

	Yep.

: Perhaps we could isolate it with a new 'standard' method like :
:   sub GET_DATA {
:     my $self = shift;
:     return $self->{'SubCl'};  # Change this one line when renaming class
:   }

	Much slower, and doesn't work well within the current class:

	$self->SetFoo ( 'SubCl', $self->GetCat() + $self->GetDog() );

	Still need to pass the class name, or you trash SetFoo for your
	supers...

:   sub some_method_or_other {
:     my $self = shift;
:     my $data = $self->GET_DATA();
:     $data->{'foobar'} = ...   # Where you'd use  $self->{'foobar'}
:   }
: Hmm, maybe this _is_ turning into a kludge after all.

	Yep. :-)

	I can be done to some degree with an array style object.

	package Super;
	use enum qw(Foo Bar Cat Dog LAST_INDEX); ## enum found at CPAN

	sub new {
	    my $self = [];

	    $self->[Foo] = 'foo';
	    $self->[Bar] = 'bar';
	    	...
	    return bless $self, shift;
	}

	package Super::SubClass;
	BEGIN { @ISA = 'Super' }

	use enum (
	    ':=' . __PACKAGE__->LAST_INDEX(),  ## Start our enum index at end of super's
	    qw(Foo Bar Cat Dog LAST_INDEX)
	);

	sub something {
	    my $self = shift;
	    print $self->[Foo];                    ## Our Foo
	    print $self->[ $self->SUPER::Foo() ];  ## Super's Foo
	}

	This doesn't work at all with multible inheritance however, nore is
	it pretty at all because of the requirement to self maintain
	LAST_INDEX.  Like I said, work is in progress for a Better
	Way[tm] of doing this style object.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 03 Jul 1998 14:56:29 +0200
From: Gisle Aas <aas@sn.no>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <m3zper9jpe.fsf@furu.g.aas.no>

Zenin <zenin@bawdycaste.org> writes:

> 	LAST_INDEX.  Like I said, work is in progress for a Better
> 	Way[tm] of doing this style object.

If my latest patch to fields.pm find its way into developer release
perl5.004_70 then you can have private fields as well as compile time
typo-check for your field names.

  package Base;
  use fields qw(a b _private);

  package Derived;
  use base 'Base';
  use fields qw(b _private);

  sub foo {
     my Derived $self = shift;
     $self->{_private} = 43;
  }

Fields beginning with "_" are made private and are not visible in
subclasses.  They can be used without risk.  Subclasses are allowed to
override public field names ("b" above) but will get a warning under
-w.

Typing 'my A::Very::Long::Class:Name $self' in every method is not
very attractive though (and 'my __PACKAGE__ $self' does not seem to
work either).

-- 
Gisle Aas


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

Date: Tue, 30 Jun 1998 08:44:46 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
To: philipp999@corpex.com (Philipp)
Subject: Re: parsing MIME types
Message-Id: <EvCwAM.KnG@csc.liv.ac.uk>

[Posted and mailed]

In article <35914075.29543841@nnrp.news.uk.psi.net>,
philipp999@corpex.com (Philipp) writes:
> Hi ya all!
> 
> I'm just about to write a small email client in perl. Does anybody
> know of a good way to parse MIME types?
> 
> Any help much appreciated.
> 

Yeah.

Go find the MIME tools on CPAN. I forget the exact package name but
a search will find them.

> th
> -philipp

-- 
--
Ian J. Garlick
ijg@csc.liv.ac.uk

Antonym, n.:
        The opposite of the word you're trying to think of.


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

Date: Thu, 02 Jul 1998 05:01:59 GMT
From: joker@inlink.com (John Hocking)
Subject: Re: Passing arguments to perl CGI
Message-Id: <359c1381.2432728@news.inlink.com>

On 30 Jun 1998 22:47:14 GMT, mikep@rt66.com (mikep) wrote:

>I'm using a perl script as a CGI script. I'd like to pass arguments to
>it. What is the appropriate syntax to interact with the HTTP server
>(e.g. is there one general way in which parameters are passed to a CGI
>script?)? Once I pass the arguments, how do they appear to the script
>itself (e.g. in the $ARGV built-in variable?)?
>
>MTIA
>
>===========================
>Mike Powell
>mikep@rt66.com
>http://www.rt66.com/~mikep/


Accepting input from HTML Forms is probably the most misunderstood
task in CGI programming. In reality, it should be the last thing you
worry about, as it is probably the single easiest problem to solve....

Why? All of the hard work has been done for you.

Lets examine the following, bullet-proof perl code for handling form
input:
(While you're examining it, copy it and past it to a text file
now....you'll want to put it into EVERY one of your CGI Programs) 


sub Get_Form_Variables{

  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  if (length($buffer) < 5) {
     $buffer = $ENV{QUERY_STRING};
  }
  @pairs=split(/&/,$buffer);
  foreach $pair(@pairs) {
     ($name, $value)=split(/=/,$pair);
     $value =~ tr/+/ /;
     $value =~ s/%([a-fA-F0-9][A-F0-9])/pack("C",hex($1))/eg;
     if($input{$name} eq "") {
	$FORM{$name} = $value;
        push (@FIELDS,$name);
     }
     else {
  	$FORM{$name} = $FORM{$name}." ".$value;
     }
  }

}

 

--------------------------------------------------------------------------------
This Perl Subroutine handles both GET and POST methods of submitting
form input, by assigning the variable $buffer either the value of
"STDIN" (POST methos uses STDIN to send data to the CGI program) OR
the contents of the ENVironment variable "QUERY_STRING", depending on
the existence of STDIN.
Once it has the $buffer variable filled, it breaks down the name=value
pairs, removing all the wierd characters your browser adds to them,
and creates 2 arrays that you can use in your programs: 


   $FORM{'variable_name'}  is the value of the <INPUT> field from your
form.
   @FIELDS holds the actual names of the <INPUT> fields.
For example, consider the following simple form: 
<INPUT NAME="full_name"> ... 
<INPUT NAME="email_address"> ... 

In this case, if you were to call some CGI program from this form, and
from within that CGI program, you called the Get_Form_Variables
Subroutine ( ... &Get_Form_Variables; ...) You could then reference
the following variable in your form:
(Lets assume you entered "John Doe" and "jdoe@themorgue.com" in the
above fields) 
   $FORM{'full_name'}  would be "John Doe"   .... and
   $FORM{'email_address'}  would be "jdoe@themorgue.com"

So... in a Perl Program, you could do something like this:

     #!/usr/local/bin/perl

     &Get_Form_Input;

     $name = $FORM{'full_name'};
     $mail = $FORM{'email_address'};
     $now = localtime;
     open(DAT, ">>visitors.txt");
        print DAT "$name ($email) was here on $now\n";
     close(DAT);

     print "Content-Type: text/html\n\n";
     print "<H1>Thanks, $name for stopping by</H1>\n";
     print "We'll drop you a line at $mail sometime this week with a
special offer!\n";
     
     exit 0;

     sub Get_Form_Input {
         ..... (copied from above) ...
     }
	 
The program would log the form's contents to a file and return the
visitor's browser with a personalized message:



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

Date: 2 Jul 1998 14:12:40 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Passing arguments to perl CGI
Message-Id: <6ng4go$ajo$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    joker@inlink.com (John Hocking) writes:
:Lets examine the following, bullet-proof perl code for handling form
:input:
:(While you're examining it, copy it and past it to a text file
:now....you'll want to put it into EVERY one of your CGI Programs) 
:
:
:sub Get_Form_Variables{
:
:  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
:  if (length($buffer) < 5) {
:     $buffer = $ENV{QUERY_STRING};
:  }
:  @pairs=split(/&/,$buffer);

Your bold assertion that that crappy code is bulletin proof
is either tongue-in-cheek or hopelessly naive.  I'll assume the
latter.

That code is wrong.  wrong wrong wrong wrong wrong wrong wrong wrong
wrong.  If I saw that on an intervew, I'd see you to the door.
If I saw that on an exam, you'd fail.

No, I'm not going to tell you why.  I'm written about this 
often.  Use the module, or die.  

--tom
-- 
Tactical?  TACTICAL!?!?  Hey, buddy, we went from kilotons to megatons
several minutes ago.  We don't need no stinkin' tactical nukes.
(By the way, do you have change for 10 million people?) --lwall


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

Date: Thu, 02 Jul 1998 10:43:07 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Passing arguments to perl CGI
Message-Id: <comdog-ya02408000R0207981043070001@news.panix.com>
Keywords: from just another new york perl hacker

In article <6ng4go$ajo$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com (Tom Christiansen) posted:

>In comp.lang.perl.misc, 
>    joker@inlink.com (John Hocking) writes:

>:sub Get_Form_Variables{
>:
>:  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>:  if (length($buffer) < 5) {
>:     $buffer = $ENV{QUERY_STRING};

>That code is wrong.  wrong wrong wrong wrong wrong wrong wrong wrong
>wrong.  If I saw that on an intervew, I'd see you to the door.

why waste time seeing them to the door?  they should be able to find
their own way out. :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>


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

Date: Fri, 03 Jul 1998 14:38:07 +0100
From: Martin Neumann <martin_neumann@gmx.net>
Subject: perl & postscript
Message-Id: <359CDEBF.E75FACA0@gmx.net>

i'am searching for an postscript interpreter for win NT 4.0.
where can i find someone?



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

Date: Fri, 03 Jul 1998 14:00:58 GMT
From: Chris Wareham <chris.wareham@blackwell.co.uk>
Subject: Re: perl & postscript
Message-Id: <359CE4B0.1D1160A5@blackwell.co.uk>

Martin Neumann wrote:
> 
> i'am searching for an postscript interpreter for win NT 4.0.
> where can i find someone?

On a newsgroup about DTP and other publishing stuff?

Your best bet is a combination of GhostScript and GSView,
available for free from:

  http://www.cs.wisc.edu/~ghost/

Chris
-- 
chris.wareham@blackwell.co.uk
+44 (0)1865 792792 ext. 3381


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

Date: 2 Jul 1998 09:40:34 GMT
From: "DUTOIT" <abcdm@wanadoo.fr>
Subject: perl and ENV variables ???
Message-Id: <01bda59d$a6d57f20$fdbffcc1@SIT.wanadoo.fr>

Hello,

I'ld want to use the https protocol in a form produced by a Perl script.

I know it's necessary to put , after the Content-type of this HTML page a
command wich permits to secure the  payment (unbroken blue left key of
the screen).

What is the syntax to do that in Perl?

Is it possible to use ENV parameters, like :
my $key;
my $value;
while (($key,$value) = each %ENV)
 {
  print  "$key = $value\n";
  print"<BR>";
 }
$ENV{"SERVER_PROTOCOL"}="HTTPS";
 .....

OR




  print "Content-type:text/html\n\n";
  $ENV{"SERVER_PROTOCOL"}="https";
  $ENV{"HTTP_REFERER"}="https://localhost/formulfr.html";
 ....




Thank you

Mr DUTOIT

NB: I test it with Sambar server







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

Date: 02 Jul 1998 15:56:11 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: perl and ENV variables ???
Message-Id: <isww9wcq6c.fsf@godzilla.kiere.ericsson.se>

"DUTOIT" <abcdm@wanadoo.fr> writes:

> I'ld want to use the https protocol in a form produced by a Perl script.

It doesn't become a Perl-related question just because there was a
perl script involved somewhere. What's worse, you've been told so
before. Go away.
-- 
		    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

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

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