[8720] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2337 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 16 12:07:45 1998

Date: Thu, 16 Apr 98 09:00:30 -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           Thu, 16 Apr 1998     Volume: 8 Number: 2337

Today's topics:
        .= so why not =. ? <John.Adams@BentonvilleAR.ncr.com>
    Re: .= so why not =. ? (Jeffrey R. Drumm)
    Re: ?? Perform a remote query and reformat results <rootbeer@teleport.com>
        ANNOUNCE: nsapi_perl/Netscape::Server v0.23 available <bsugars@canoe.ca>
    Re: Array / List question <jdporter@min.net>
    Re: Array / List question (Abigail)
    Re: Array / List question <bmb@ginger.libs.uga.edu>
    Re: array of matches in s/// <rootbeer@teleport.com>
        Comma delimeted, quoted data <scotts@mdmgr.com>
    Re: Farnham's Freehold <jdporter@min.net>
    Re: Filname into variable <rootbeer@teleport.com>
        grep <snyderc@bvsd.k12.co.us>
    Re: grep <grinch@whoville.com>
    Re: hash/complex data structure problem (Andrew M. Langmead)
    Re: Help: to eliminate eval() on a HTML Filling script. (Abigail)
    Re: Hide or Encrypt perl source code <jdporter@min.net>
        HTTP Perl Question <pmein@johnco.cc.ks.us>
    Re: info on cookies <rootbeer@teleport.com>
        New Website <m.ubl@elmshorn.netsurf.de>
    Re: OOPS and several parents <jdporter@min.net>
    Re: OOPS and several parents (Tony Bass)
    Re: OOPS and several parents (Kevin Reid)
    Re: passing persistant data - was Re: considerations fo <jdporter@min.net>
    Re: Perl 5.004_64 Slower??? (Dominic Dunlop)
        PERL aware code editor <Glenn.J.Schworak@state.or.us>
        Please help with bizzare error (Vladimir Gabrielescu)
    Re: push a non HTML document to a web browser? <rootbeer@teleport.com>
    Re: question of interest: How does perl compile? (Andrew M. Langmead)
        Question <tw96@email.msn.com>
    Re: Question <rootbeer@teleport.com>
        Select call (Win32) timeout value doesn't work <j_harrison1@ti.com>
    Re: Select call (Win32) timeout value doesn't work <grinch@whoville.com>
    Re: sleep & print in cycles (Andrew M. Langmead)
    Re: unix commands in a perl <grinch@whoville.com>
    Re: unpack and physical network address droby@copyright.com
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 16 Apr 1998 10:14:40 -0400
From: "John Adams" <John.Adams@BentonvilleAR.ncr.com>
Subject: .= so why not =. ?
Message-Id: <01bd6941$d1cb6340$32325299@arbentadamsj.bentonvillear.ncr.com>

Okay, if

	$string1 = "foo";
	$string2 = "bar";
	$string1 .= $string2; #$string1 is now "foobar"

then why doesn't

	$string1 = "foo";
	$string2 = "bar";
	$string1 =. $string2; #$string1 is now "barfoo"

Or am I missing something here?

	John A
	speaking only for himself


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

Date: Thu, 16 Apr 1998 15:08:19 GMT
From: drummj@mail.mmc.org (Jeffrey R. Drumm)
Subject: Re: .= so why not =. ?
Message-Id: <35361ddb.533724214@news.mmc.org>

On Thu, 16 Apr 1998 10:14:40 -0400, "John Adams"
<John.Adams@BentonvilleAR.ncr.com> wrote:

>then why doesn't
>
>	$string1 = "foo";
>	$string2 = "bar";
>	$string1 =. $string2; #$string1 is now "barfoo"

Um, because there is no '=.' operator?

>Or am I missing something here?

Just that . . . so far :-)

see the perlop man page, or type 'perldoc perlop' at whatever you use for a
command line . . . all the wondrous operators supported by Perl are found
therein.

>	John A
>	speaking only for himself

-- 
                               Jeffrey R. Drumm, Systems Integration Specialist
                       Maine Medical Center - Medical Information Systems Group
                                                            drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented!" - me


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

Date: Thu, 16 Apr 1998 15:53:18 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: j5rson@iversonsoftware.com
Subject: Re: ?? Perform a remote query and reformat results
Message-Id: <Pine.GSO.3.96.980416085233.838J-100000@user2.teleport.com>

On Thu, 16 Apr 1998 j5rson@iversonsoftware.com wrote:

> I want to perform a POST query on another server, capture the results and
> reformat them for display.

Use the LWP module.

> How can I simulate a POST from Perl, capture the results in the script,
> reformat and display for my user?

Use the LWP module. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 16 Apr 1998 14:35:06 GMT
From: Benjamin Sugars <bsugars@canoe.ca>
Subject: ANNOUNCE: nsapi_perl/Netscape::Server v0.23 available
Message-Id: <6h54uq$p2a$1@news.neta.com>

Greetings,

Version 0.23 of nsapi_perl has been added to the CPAN as:
  file: $CPAN/authors/id/BSUGARS/nsapi_perl-0.23.tar.gz
  size: 45923 bytes
   md5: 0dff83377ad9363064ef5127b6620014

The latest version can always also be found at the nsapi_perl home
page located at:
  http://interact.canoe.ca/~bsugars/nsapi_perl.html

nsapi_perl is a set of Netscape Server API functions and Perl
extension modules that (in the spirit of mod_perl for Apache) embed a
Perl interpreter in a Netscape web server.  This allows you to program
to the Netscape server API in Perl rather than C.

The package includes the Netscape::Registry module which runs
unmodified Perl CGI programs from within the server process providing
large performance gains over regular CGI.

Major changes since version 0.22:
  - Jumbo Makefile.PL that allows one to install via
      perl Makefile.PL
      make
      make install
  - Registry.pm now properly sets AUTH_TYPE and REMOTE_USER
  - Applied Bill Ward's Makefile.PL patch

Thanks,
-Ben

--
Ben Sugars <bsugars@canoe.ca>
Senior Webmaster,
CANOE Canadian Online Explorer,
http://www.canoe.ca/




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

Date: Thu, 16 Apr 1998 14:31:05 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Array / List question
Message-Id: <35361794.277C@min.net>

Calle Dybedahl wrote:
> 
> "A.P." <road@apdo.com> writes:
> 
> > I say this because an array in an scalar context I think it should
> > return the number of elements, not the value of the last one.
> 
> It does. You don't have a scalar context.

Wrong. The context is scalar; the expression returns the last
item, contrary to what A.P. was expecting.

John Porter


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

Date: 16 Apr 1998 15:02:02 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Array / List question
Message-Id: <6h56ha$bj$1@client2.news.psi.net>

A.P. (road@apdo.com) wrote on MDCLXXXIX September MCMXCIII in
<URL: news:3535F5F1.FAD8C08E@apdo.com>:
++ Hi!
++ I don't understand the behaviour of the following code:
++ 
++ print ((0,4)**2);
++ 
++ It prints 16, why doesn't it print 0? I discovered this trying to do it
++ with an array. I'm a Perl beginner and I wondered if there was a way of
++ doing some operation (like squaring) all the elements of an array/list
++ without using a loop block. What I tried was:

No, there isn't.

If you have (0,4) ** 2, the left operand of ** is evaluated in scalar
context. A plain list evaluated in scalar context returns the last element.
So.... (0,4) ** 2 == 4 ** 2 == 16.

++ @i=(0..4);
++ @j=@i[@i]**2;
++ print @j;
++ 
++ I thought that it should print 25, but it prints 16!!! I say this
++ because an array in an scalar context  I think it should return the
++ number of elements, not the value of the last one. Please help! I can't
++ stand not knowing the solution! Thanks a lot!

Yes, you are right of an array. However, there is no general rule of
converting a list to a scalar. A slice evaluated in scalar context
returns the last element, not the number of elements.

Perls "there is no general rule to convert a list to a scalar" is a
mixed blessing. It means you have to do less conversion yourself, as
the result of evaluating something in scalar context usually gives a
sensible result. It also means there is no general rule, and that you
have to learn what scalar context does in all cases....



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Thu, 16 Apr 1998 11:31:07 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Array / List question
Message-Id: <Pine.A41.3.96.980416110006.48516C-100000@ginger.libs.uga.edu>

The key here is 'context'.  I believe the '**2' is forcing the list
'(0,4)' into a 'scalar context', which means the list gets evaluated into
the last item in the list: '4'.  Then 4**2 == 16.  For example:

+4  print (0,4);
+5  print "\n";
+6  print scalar (0,4);
+7  print "\n";
+8  print ((0,4)**2);
+9  print "\n";

In line 4, the 'print' is forcing the list '(0,4)' into an 'array
context', so the output of line 4 is '04', i.e. it prints both the '0' and
the '4'.

By contrast the output of line 6 is '4', because a list in scalar context
returns the last item in the list.

In line 8 (your code) you could imagine that the '**2' is overriding the
'print', so the list is treated as a scalar rather than as an array.

As for

> @i=(0..4);
> @j=@i[@i]**2;
> print @j;

'@i[@i]' looks very strange.  When I ran this, neither '-w' nor 'use
strict' complained about it, so I'm not sure I have a clue what it
might be doing, so I hope someone else explains it :-)

The following

    @i=(0..4);
    @j=@i**2;
    print @j;

*does* output '25'.  However, rather than

    @j=@i**2;

you may want to say

    push @j, @i**2;

or even

    push @j, (scalar(@i)**2);

to be more clear what your intentions are (that is, assuming I know what
your intentions are :-)  If your code is ever looked at by others in your
company, using the explicit 'scalar' can help them (and perhaps you)
tell just exactly what you think you want.

Cheers!

Brad Baxter
UGA


On Thu, 16 Apr 1998, A.P. wrote:

> Hi!
> I don't understand the behaviour of the following code:
> 
> print ((0,4)**2);
> 
> It prints 16, why doesn't it print 0? I discovered this trying to do it
> with an array. I'm a Perl beginner and I wondered if there was a way of
> doing some operation (like squaring) all the elements of an array/list
> without using a loop block. What I tried was:
> 
> @i=(0..4);
> @j=@i[@i]**2;
> print @j;
> 
> I thought that it should print 25, but it prints 16!!! I say this
> because an array in an scalar context  I think it should return the
> number of elements, not the value of the last one. Please help! I can't
> stand not knowing the solution! Thanks a lot!
> 
> 
> 
> 
> 



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

Date: Thu, 16 Apr 1998 15:41:25 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bart Lateur <bart.mediamind@tornado.be>
Subject: Re: array of matches in s///
Message-Id: <Pine.GSO.3.96.980416083737.838E-100000@user2.teleport.com>

On Thu, 16 Apr 1998, Bart Lateur wrote:

> So I'd like to propose an extension to Perl, in the form of a special
> variable array. In agreement with the $& variable, which contains the
> whole matched string, @& could be a decent name. 

Would that (somehow) hold all of the matched substrings in a list? 

> I'm pretty sure that internally, Perl builds this array of matches.

If I understand you correctly, not in s///g, it doesn't. It does one match
at a time. And in m//g, it only does builds a list in a list context. 

> 	s/$key/&interpolate($translate{$key},@&)/e;
> 
> That surely would solve my problem in a very neat way, wouldn't you
> think?

I can't see what @& could hold which would be useful there. Can you
describe your proposed feature in more detail?

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 16 Apr 1998 10:19:11 -0500
From: Scott Saddison <scotts@mdmgr.com>
Subject: Comma delimeted, quoted data
Message-Id: <3536216F.AFB6E8F0@mdmgr.com>

Hi

Having a problem...

I have a data base file that I need to grab data from.  The file is
comma delimeted and sometimes quoted.  The problem is sometimes there
are commas in the quoted text.

i.e.

1,2,5,"some text", "some more text",5,"text with, a, comma or two",6,7

how can I split this data into fields ignoring the commas in quoted
text?

(@fields) = split(',', $_, 999);   does not work because it see's the
commas in the quoted fields as a delimeter.

If you have an answer, please let me know.  I can over analyze/program
this by splitting the files down by characters and checking for
start/end quotes but really don't want to do it that way.

hoping there is a module that handles this, or perhaps a simple command.

Thanks in advance...

Scott Saddison
scott@skyenet.net or scotts@mdmgr.com




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

Date: Thu, 16 Apr 1998 14:21:44 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Farnham's Freehold
Message-Id: <35361563.7068@min.net>

Ronald Stephens wrote:
> 
> written by Todd Christianson and larry Wall, which I bumped into

Nack!

s/dd/m/;
s/son/sen/;

John Porter


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

Date: Thu, 16 Apr 1998 15:35:40 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: andreas.puttkammer@not.around.ch
Subject: Re: Filname into variable
Message-Id: <Pine.GSO.3.96.980416083338.838D-100000@user2.teleport.com>

On Thu, 16 Apr 1998, Andreas Puttkammer wrote:

> is it possible to get the filename used (f.ex. whithin a filehandle)
> into a variable. 

If you're asking, "Is it possible to find out the name of the file
associated with a filehandle?", the answer is generally, no. There may be
zero, one, two, or any other number of names! But if you'll need it later,
just save the filename when you open the file, possibly in an array
indexed with the fileno. Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 16 Apr 1998 07:29:07 -0700
From: Chris Snyder <snyderc@bvsd.k12.co.us>
Subject: grep
Message-Id: <353615AE.66E9@bvsd.k12.co.us>

I am trying to write a program where the grep command is used to search
through all files in a directory (without knowing the file names) based
on a user entered string, and print out the names of all files
containing text matching the string.

Thanks,
	Keenan Crane
	codewarrio@aol.com


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

Date: Thu, 16 Apr 1998 10:47:09 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: grep
Message-Id: <6h54s0$6mk@fridge.shore.net>

Chris Snyder wrote in message <353615AE.66E9@bvsd.k12.co.us>...

>I am trying to write a program where the grep command is used to search
>through all files in a directory (without knowing the file names) based
>on a user entered string, and print out the names of all files
>containing text matching the string.


Perl is overkill for that. grep already has an option to print just the
filenames.

grep -l 'exp' *

-grinch

--
-----
"Yes, I'm paranoid, but that doesn't mean
no one's out to get me." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





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

Date: Thu, 16 Apr 1998 14:12:48 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: hash/complex data structure problem
Message-Id: <ErIFHD.9GE@world.std.com>

Mika Koivisto <mika@wcug.wwu.edu> writes:

>Now the problem is that I need to walk trough each item on that structure
>and crap the price, setup and other and then do something with them.

Have you seen the examples of nested loops in the perllol man page?

for $plan (keys %virtual) {
   for $period (keys %{$plan}) {
       $something = $period->{price};
   }
}
-- 
Andrew Langmead


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

Date: 16 Apr 1998 14:28:24 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Help: to eliminate eval() on a HTML Filling script.
Message-Id: <6h54i8$bn4$1@client3.news.psi.net>

Tommy (tkho@technologist.com) wrote on MDCLXXXIX September MCMXCIII in
<URL: news:3535B087.9ECCD23C@technologist.com>:
++ Interesting idea. I believe I still have to replace characters line by line,
++ then join() or push() them, and eval() couple hundred of line together.

Why?


Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Thu, 16 Apr 1998 14:35:52 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Hide or Encrypt perl source code
Message-Id: <353618B3.7BCA@min.net>

Stuart McDow wrote:
> 
> "Grinch" <grinch@whoville.com> writes:
> >
> > the only way to run a Perl script on a Win32 machine would be to
> > install the entire Perl-Win32 distribution.
> 
> Is this really such a bad thing? The core distribution (5.004_2)
> without the man directory is only 10MB or so. 

"only 10MB".

I wish 10MB were a mere pittance to everyone (such as our
marketers) as it is to you.

I commercial project I'm on had a total installation footprint 
of about 4 meg until I suggested (and started) using perl.
Now it's 14 meg.  Do you think that's easy to justify?

John Porter


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

Date: Thu, 16 Apr 1998 10:19:04 -0500
From: Phil Mein <pmein@johnco.cc.ks.us>
Subject: HTTP Perl Question
Message-Id: <044B4AFA4898D1118248006097BDA86704029139@news.jccc.net>

Does anyone have a simple perl script that fetches a nonlocal web page
in a text only mode?

thanks



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

Date: Thu, 16 Apr 1998 15:27:07 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "Gilles L. Chong Hok Yuen" <glchy@csah.com>
Subject: Re: info on cookies
Message-Id: <Pine.GSO.3.96.980416081244.838C-100000@user2.teleport.com>

[ Please don't see this as a flame; since you can't see my smiling face
over Usenet, you'll have to take my word for it. :-)  ]

On Thu, 16 Apr 1998, Gilles L. Chong Hok Yuen wrote:

> First of all, i appreciate ur help. N nope, i didnt know tt a CGI
> MetaFAQ existed. As i said (n im not ashamed of saying it cos it's
> true), im a newbie.I turn to u guys in the newsgroup to get some help or
> some direction of where the help is. 

Please don't use 'kewl' spellings. Many readers of this newsgroup aren't
native speakers of English, and those spellings don't impress the rest of
us! :-)

You say you want to get "some direction of where the help is". Perhaps you
haven't noticed the messages directing you to the documents and newsgroups
which can help you. 

> I dont understand what is ur problem if someone wants to help in a more
> explicit n detailed way. Doesnt cost u anyfing, does it? 

Some people have misled you by encouraging you to post your non-Perl
questions here. An on-topic newsgroup is going to be able to give you
better and more-complete answers than we can give here.

> Putting it in a 'starving-fish' context, if u help the starving by
> pointing out the direction of the nearest river (even tho it can be 50
> miles away!), fine. 

In what way is an on-topic newsgroup 50 miles away? Are you claiming that
it's a hardship for you to look in the right place for the answers, as
everyone should do?

> But wat's the problem if someone ELSE gives some food n then teach the
> starving how to fish? 

You're painting yourself as a panhandler with the sign "will work for
food". But it seems that you're not willing to go next door to the soup
kitchen to get the food yourself. Hmmm...

But, in answer to your question - these ongoing postings of yours are the
problem. You're still looking in the wrong place for your answers. It's
not that your questions are "irritating" me in some way - it's that
they're off topic, and in a FAQ. If you ask an on-topic question that I
can answer in a newsgroup that I read, you'll get an answer, even if it's
only a pointer to a FAQ. 

In other words: Everyone here is trying to help you. The best help for you
is to find and consult the appropriate FAQs and other docs. If you still
have questions after having read those docs, please ask in an on-topic
newsgroup. Thank you!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 16 Apr 1998 17:08:11 +0100
From: Malte Ubl <m.ubl@elmshorn.netsurf.de>
Subject: New Website
Message-Id: <35362CEB.5DCC@elmshorn.netsurf.de>

Hello,

I just released a very interesting website concerning Perl-Scripts.
You'll find there new scripts (Access-Counter, Statistics) that
are very easy to install and use which I developed for the website
http://www.io.com/~icc.

Go to http://elmshorn.netsurf.de/~m.ubl ! You won't be disappointed !

I'll soon release some kind of "CGI-Script-Office" with a guided
wizzard-style installation, so that you dont have to change any
of the variables in the scripts.

Who can offer me cgi-enabled web-space for free?
mailto:m.ubl@elmshorn.netsurf.de

Thank you,
Malte Ubl

-- 
\ Malte Ubl                                      \
 \ mailto:m.ubl@elmshorn.netsurf.de               \
  \ http://elmshorn.netsurf.de/~m.ubl              \
   \ http://www.io.com/~icc                         \
    \ This eMail will selfdestruct in 3 seconds      \


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

Date: Thu, 16 Apr 1998 13:57:19 GMT
From: John Porter <jdporter@min.net>
Subject: Re: OOPS and several parents
Message-Id: <35360FAA.6BD0@min.net>

Daniel wrote:
> 
> >
> >package something;
> >@something::ISA = qw( second extra );
> >sub new {
> >    my $pkg = shift;
> >    my $second = new second;
> >    my $extra = new extra;
> >    my $self = bless {
> >       %$second,
> >       %$extra,
> >       cost => 'high',
> >       @_
> >    }, $pkg;
> >};
> >
> >
> >hth,
> >John Porter
> 
> John, thanks for the help.  Your code works
> well but I'm still looking for more automation.
> What if I didn't know the number of parents?
> 
> $#something::ISA gives me the number of items
> in ISA but how can I convert something::new
> so that it reblesses the hash references
> from all it (unknown number of) parents?

The general answer is, don't do this. Do it only
in specific cases, where you know exactly what
all the parents are.  The two-parent example I
gave is one such specific case.  A general case
example might look like this:

package something;
@something::ISA = @parents; # who knows how many.
sub new { 
    my $pkg = shift; 
    my %h = ();
    for my $p ( @ISA ) {
        my $o = new $p;
        %h = ( %h, %$o );
    }
    bless \%h, $pkg;
};

But this makes numerous assumptions, e.g. that all
the parents are constructed via methods called 'new';
that all those new()s don't need any arguments; that
all the blessed references they return are hash refs;
that none of those hashes contain duplicate key strings.

As tchrist mentioned, reblessing is ABT when you've got
multiple inheritance.  In any case, I defer to his
wisdom in these matters.


> package extra;
> sub twiddleData {
>     my $self = shift;
>     $self->{ state } = "unknown";
> };
> package main;
> my $thing = new something;
> $thing->twiddleData();
> 
> this would work only if I knew that
> package extra was a parent of package
> something.

That's what @ISA tells you.
At runtime, you can test if twiddleData is a callable
method of $thing using the can() method. See UNIVERSAL.
	if ( $thing->can('twiddleData') ) ...

hth,
John Porter


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

Date: 16 Apr 1998 16:09:45 +0100
From: aeb@brains.cartoon.bt.co.uk (Tony Bass)
Subject: Re: OOPS and several parents
Message-Id: <6h56vp$878$1@brains.cartoon.bt.co.uk>

>From article <6h4tma$4rr$1@csnews.cs.colorado.edu>, by Tom Christiansen <tchrist@mox.perl.com>:
[...]
> Following is a first-draft (not even proofed) of a bit from the Perl
> Cookbook, due out this summer, that talks about this.  Constructive
> feedback welcome.
[...]
>         # in Frobniz.pm, do this:
>         package Frobniz;
>         sub spawn {
>             my $classname  = shift;         # What class are we constructing?
>             my $obref      = {};            # Allocate new memory
>             bless($obref, $classname);      # Mark it of the right type
>             $obref->_init(@_);              # Call _init with remaining args
>             return $obref;
>         } 

>         # "private" method to initialize fields 
>         sub _init {
>             my $ob = shift;
>             $ob->{START} = time();
>             $ob->{COUNT} = 0;
>             if (@_) {
>                 my %extra = @_;
>                 @$ob{keys %extra} = values %extra;
>             } 
>         } 
[...]


Being keen on functional style I venture to suggest including a brief
note somewhere (or perhaps it will already exist in a different
section?) on the possibility of writing methods with a minimum of
assignment and imperative constructions.  For instance, this spawn
might be rendered as

   sub spawn {
    my ($classname, @extra) = @_;
    return bless({
     START => time(),
     COUNT => 0,
     @extra
     }, $classname);      # Mark it of the right type
   }

A separate _init may be a little more awkward in this style.  My own
preference would be to show just a simple functional form once, enough
hint of the possibility.

    Tony Bass

-- 
# A E Bass                                      Tel: (01473) 645305
# MLB 3/19, BT Laboratories                     e-mail: aeb@saltfarm.bt.co.uk
# Martlesham Heath, Ipswich, Suffolk, IP5 7RE   DO NOT e-mail to From: line
#                                               Opinions are my own


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

Date: Thu, 16 Apr 1998 11:18:51 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: OOPS and several parents
Message-Id: <1d7krt3.g785r1178ya80N@slip166-72-108-9.ny.us.ibm.net>

Daniel <daniel.mendyke@digital.com> wrote:

> John, thanks for the help.  Your code works
> well but I'm still looking for more automation.
> What if I didn't know the number of parents?
> 
> $#something::ISA gives me the number of items
> in ISA but how can I convert something::new
> so that it reblesses the hash references
> from all it (unknown number of) parents?

In this sample code, the constructor for class tomato calls the
constructors for its parent classes, overriding one of the returned
values:

#!perl -w

package fruit;

sub new ($) {
  my $class = shift;

  return bless {hasSeeds => 1}, $class;
}

package vegetable;

sub new ($) {
  my $class = shift;

  return bless {rabbit_food => 1}, $class;
}

package tomato;

@ISA = qw(fruit vegetable);

sub new ($) {
  my $class = shift;
  my @parents = ();
  foreach (@ISA) {
    if ($_->can("new")) {
      push @parents, $_->new;
    }
  }
  $self = {
    (map {%{$_}} @parents),
    color => "red",
    rabbit_food => 0,
  };
  bless $self, $class;
}

package main;

$x = new tomato;
foreach (keys %$x) {
  print "$_ => @{[$x->{$_}]}\n";
}

__END__

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: Thu, 16 Apr 1998 14:06:44 GMT
From: John Porter <jdporter@min.net>
Subject: Re: passing persistant data - was Re: considerations for global variables?
Message-Id: <353611DF.736A@min.net>

Dan Baker wrote:
> 
> John Porter wrote:
> 
> > Well now, if WWW is the context of your application... have you
> > considered using cookies?  Might be a nice elegant solution to
> > the problem of passing state from one cgi program to the next.
> ---------
> sounds like an interesting possability... please expand on the general
> considerations/limitations! I don't know ANYTHING about what is possible
> with cookies.
> 
> The application I'm working on is not truely a WWW application because
> it is not going to be used over the web and through servers. I really
> just intend to use html/perl as interface tools for a simple text-based
> application that is single user local on a single machine. html can
> handle all the interface needs I have, and perl can handle all the data
> munging, but I'm struggling a little with methods to pass data to
> emulate procedural data passing.

I think you need to get a better handle on the technical basis of
what you're talking about.  Your understanding of web-related
things is pretty shaky.

"World Wide Web" is something of a misnomer, because all the
technical aspects are still relevant when the server application
(your perl script) and the client program (browser) are on the
same machine, without even a network.  HTTP is still the way
these two components communicate.  To do what you want to do,
you need HTTP.  And (unless you're going to get fancy and use
server-side includes (SSI) or active server pages (ASP) or
equivalent) you need CGI.

There are plenty of good tutorials on the web about how
HTTP and CGI work.  Go read them, and then your questions
here -- and their answers -- will be much more sensible.
A good place to start is www.w3c.org.

good luck,
John Porter


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

Date: Thu, 16 Apr 1998 17:27:51 +0000
From: domo@tcp.ip.lu (Dominic Dunlop)
Subject: Re: Perl 5.004_64 Slower???
Message-Id: <1d7kn9z.ia1ujdj56tfeN@ppp35.vo.lu>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:

> And quoting from Bill 'Sneex' Jones' post:
>> ...
> Doesn't the "usethreads=define" here mean that the binary was compiled

Indeed.  That post hadn't hit my server when I posted.  I sit corrected.

While, according to Malcolm Beattie, this would account for a slow-down
of up to ten per cent, we seem to be talking about a hundred per cent
increase in execution time which has nothing to do with threads:

>From Larry W Virden in <6gvqcr$cel$4@srv38s4u.cas.org>:
>Looks like the system times are in the same ball park, but user time is
>about twice as slow.  Note this has _nothing_ to do with threading
>compiled in - I wasn't able to get the threading code to compile in my
>environment the last time I tried.
-- 
Dominic Dunlop


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

Date: Thu, 16 Apr 1998 07:06:52 -0700
From: Glenn Schworak <Glenn.J.Schworak@state.or.us>
Subject: PERL aware code editor
Message-Id: <3536107C.74201B6F@state.or.us>

Hi, I am use to using a C editor that has a few nice features. The one I
like most is the fact that comments and code are given two different
colors while editing (not saved that way).

I am wondering if there are such editors developed for PERL that will
run under the Windows 95 environment. Also, are there any UNIX based
programs that can do this by serving ANSI color codes to a telnet
session?

I have written a quick and dirty little editor using VB for use right
now, but if there is something standard already out there it would be
better to not re-invent the wheel. And if there is a UNIX program that
can feed out ANSI color codes that would be even better yet as that way
we wouldn't need to FTP the source codes up and down off the system any
time we needed to make a change.

Thanks for any guidence that can be offered!



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

Date: 16 Apr 1998 11:04:38 -0400
From: vgabriel@lochaber.rutgers.edu (Vladimir Gabrielescu)
Subject: Please help with bizzare error
Message-Id: <6h56m6$3si$1@lochaber.rutgers.edu>
Keywords: perl error help


Hi all, 

I appologize if this has been asked before but I can't find a 
reference to in the FAQ.

I working on this perl program, using perl 5.004, and at run time
I get a whole bunch of errors like this:


Attempt to free unreferenced scalar.
Attempt to free unreferenced scalar.
Attempt to free unreferenced scalar.

>From the manual description of this error I am even more confused, 
because I am not _directly_ including any C code. I am however using
a bunch of the modules that come with perl 5.004, such as most of the
File::, FileHandle, and Getopts, and also a module from CPAN, 
Sort::Versions, though I get the same errors even with that last 
one removed. 

Note that these seems to not affect the behavior of the program in 
any way but it worries me nevertheless.

Please let me know if you have any ideas.

Vlad


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

Date: Thu, 16 Apr 1998 15:48:18 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Paul <fgculp@YOUKNOWWHATTODO.vianet.net.au>
Subject: Re: push a non HTML document to a web browser?
Message-Id: <Pine.GSO.3.96.980416084657.838G-100000@user2.teleport.com>

On Thu, 16 Apr 1998, Paul wrote:

> Is is possible to open a binary file like MSWord and send it to STDOUT?

Sure it is possible; in Perl it's even easy! Whether it's permitted by
your protocol, of course, is another question. If you're not sure about
that, you should check the protocol specification. If you're still not
sure after that, you should ask in a newsgroup about the protocol you're
using. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 16 Apr 1998 14:33:41 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: question of interest: How does perl compile?
Message-Id: <ErIGG6.DM@world.std.com>

"Frank L. Quednau" <quednauf@nortel.co.uk> writes:

>&format_hd                                        if $action=1;

You have a bug here.

>if $action comes from a form and is set to 1, how is the script
>compiled? The whole thing or just the code on top and the
>&format_hd subroutine? Can I influence that? 

The entire source file is compiled, including the subroutines that
aren't called. Then it starts to execute the script. While running, if
it gets to the "require" function, it then find the file given as an
argument, and sends _that_ to the compiler, runs that, and then
returns to running the original script. (A similar action is done for
"do", and "eval")

The BEGIN {} blocks and the "use" construct is a little
different. Once perl completely parses one of these, even before it
has finished compiling the script, it then executes it, and once done,
continues compiling.

There are modules called AutoLoader.pm and SelfLoader.pm that delay
compiling subroutines until the very last possible moment. They wait
until Perl is looking for the subroutine, and can't find it, and then
passes the code for the subroutine to the compiler, then jumps to this
subroutine that didn't exist before.

It usually isn't necessary, perl's compiler is pretty fast, and the
overhead for these modules is fairly big, rarely is it a win, but it
may be useful if you have many subroutines, and most of them are
rarely used.
-- 
Andrew Langmead


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

Date: Wed, 15 Apr 1998 13:43:53 -0500
From: "tw96" <tw96@email.msn.com>
Subject: Question
Message-Id: <edapuCUa9GA.100@uppubnews03>

hello, everybody!
i am a beginner to perl.
i wrote a cgi program in perl.
it will parse the form input, create a file to save them, then read sth from
another file, to write a html file to the STDOUT.
i run it by command line, it works.
but when i using a page to action it, it can not create the file to save the
form inputs!!!
what's the problem? could somebody give a help?

thanks!!!

meng






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

Date: Thu, 16 Apr 1998 15:54:30 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: tw96 <tw96@email.msn.com>
Subject: Re: Question
Message-Id: <Pine.GSO.3.96.980416085354.838K-100000@user2.teleport.com>

On Wed, 15 Apr 1998, tw96 wrote:

> Subject: Question

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> i run it by command line, it works.
> but when i using a page to action it, it can not create the file to save the
> form inputs!!!

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN.

   http://www.perl.com/CPAN/
   http://www.perl.org/CPAN/
   http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
   http://www.perl.org/CPAN/doc/manual/html/pod/

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 16 Apr 1998 08:57:23 -0500
From: Jim Harrison <j_harrison1@ti.com>
Subject: Select call (Win32) timeout value doesn't work
Message-Id: <35360E43.B4FD84DD@ti.com>

I need a way to sleep at a lower resolution than a second.

I am trying to write portable code that will run on Unix and NT.

The following works on Unix, but not under the Win32

select (undef, undef, undef, 2.5);

i.e. the code waits 2.5 seconds on UNIX, but returns immediately on NT.

I am running NT 4.0 with version 5.004.

The IO::select code fails as well.



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

Date: Thu, 16 Apr 1998 11:01:15 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: Select call (Win32) timeout value doesn't work
Message-Id: <6h55mf$7g0@fridge.shore.net>

Jim Harrison wrote in message <35360E43.B4FD84DD@ti.com>...

>I need a way to sleep at a lower resolution than a second.

I think that's the catnap() function. Other close relatives are crash(),
which is measured in hours, and hibernate(), which is measured in months.
:-)

>The following works on Unix, but not under the Win32
>
>select (undef, undef, undef, 2.5);


In the Camel Book, the description of this function mentions that may not
work on some non-UNIX systems. Win32 is probably one of those platforms.
FWIW, alarm() isn't implemented on win32 either.

-grinch

--
-----
"Yes, I'm paranoid, but that doesn't mean
no one's out to get me." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





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

Date: Thu, 16 Apr 1998 14:17:54 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: sleep & print in cycles
Message-Id: <ErIFpu.DE1@world.std.com>

uph@is.pdas.cz (Petr Hrbek) writes:

>In script the output is going to be written after the end of cycle and 
>not during that cycle.

For reasons of efficiency, many programs buffer output, so they only
have to make as few system calls as necessary. (They default ofr the
stdio library, which most perl's use, buffer line by line if the
output is a terminal, and by blocks of several kilobytes, if it is
not.)

So you have to tell perl to flush its buffer after each write.

use IO::File;

STDOUT->autoflush(1);

$slp = 1;
for ($i =0 ; $i < 10 ; $i++) 
 {
   print "$slp\n";
   sleep $slp;
 }


-- 
Andrew Langmead


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

Date: Thu, 16 Apr 1998 10:13:20 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: unix commands in a perl
Message-Id: <6h52sk$4b5@fridge.shore.net>

Inge Soetens wrote in message <35360897.506F@se.bel.alcatel.be>...

>The code is executed until it arrives the "exec" statement.
>There it stops.

That's what exec is _supposed_ to do...

Exec launches a child process that replaces the parent. If you want to start
a child process without killing off the parent, use system().

HTH!

-grinch

--
-----
"Yes, I'm paranoid, but that doesn't mean
no one's out to get me." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





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

Date: Thu, 16 Apr 1998 10:02:28 -0600
From: droby@copyright.com
Subject: Re: unpack and physical network address
Message-Id: <6h56i4$985$1@nnrp1.dejanews.com>

In article <slrn6jam49.slh.jgloudon@manitoba.bbn.com>,
  jgloudon@bbn.com wrote:
>
> Dale Wityshyn <wityshyn@telusplanet.net> wrote:
> .
> .
> >40000253745
>
> What form is this MAC address in ?  If it's a decimal representation of the
6
> byte MAC address (ugh), then you could convert this to hex by repeated
> division.
>
> Here's a lazy way..I'm using Math::Bigint because the numbers we're dealing
> with here are 48 bit numbers, which won't fit in normal scalar integers, and
> using double's for these calculations could be messy.
>
> #!/usr/local/bin/perl
> use Math::BigInt;
> $joe = new Math::BigInt "40000253745";
> $abyte = new Math::BigInt "256";
>
> for($i=0;$i<6;$i++){
>         ($div,$quo) = $joe->bdiv($abyte);
>         # change unshift to change the byte order
>         unshift @bytes , sprintf ("%X", 0+$quo);
>         $joe = new Math::BigInt $div;
> }
>
> print join (':' , @bytes), "\n";
>
> Again, this may generate complete garbage since I don't know what that
number
> above represents.
>
> --
> Jason Gloudon
>

He has it in the internal form received from snmp.

The much simpler

	$hex_mac_address = unpack('H12', $internal_mac_address);

will give a lovely hexadecimal display.
--
Don Roby

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

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

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