[10897] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4498 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 26 16:07:26 1998

Date: Sat, 26 Dec 98 13:00:20 -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           Sat, 26 Dec 1998     Volume: 8 Number: 4498

Today's topics:
        "^M" with no ASCII Transfer (Thomas Brian Holdren)
    Re: ------What should I use as a Win32 perl interpreter <gmj@netaxis.com>
    Re: >>>> A Singaporean Girl looking for more penpals!!< (Don Groves)
    Re: a nicer way? <tchrist@mox.perl.com>
    Re: a nicer way? (Alan Barclay)
    Re: a nicer way? (Jason Costomiris)
    Re: a nicer way? <tchrist@mox.perl.com>
    Re: a nicer way? <tchrist@mox.perl.com>
        Accessing Databases <gpeake@wt.net>
    Re: Best Perl Book for a "Not Yet" Perl Programmer <shane@exis.net>
        Boolean search facility (Steven Barbash)
    Re: Compiling Win32 (Randy Kobes)
    Re: Convert textarea line wraps to print (Ronald J Kimball)
    Re: faster than regexp (Alan Barclay)
        Need sample TCP code <dharris@dlconsulting.com>
    Re: Need sample TCP code (Mike Schechter)
    Re: Need sample TCP code (Tad McClellan)
        PERL OO: Function overloading hoangngo@usa.net
    Re: PERL OO: Function overloading <tchrist@mox.perl.com>
        PERL's bug ?? why different ??? <tbsky@ms7.url.com.tw>
    Re: PERL's bug ?? why different ??? (Mike Schechter)
    Re: PERL's bug ?? why different ??? (Andrew M. Langmead)
    Re: PERL's bug ?? why different ??? (Ronald J Kimball)
    Re: PERL's bug ?? why different ??? (Mike Schechter)
    Re: PERL's bug ?? why different ??? (Mike Schechter)
        Problem with Active Perl hi@there.com
    Re: REGex that doesn't work, why? <rgoeggel@atos-group.com>
        split resultspages <cb2001@hotmail.com>
    Re: split resultspages (Matthew Bafford)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 26 Dec 1998 20:33:24 GMT
From: irc_addict@hotmail.com (Thomas Brian Holdren)
Subject: "^M" with no ASCII Transfer
Message-Id: <763h6k$9ut$1@cletus.bright.net>

Shalom and good evening,

I have a rather embarassing question.  You know that little "^M" character that 
Windows just loves to put at the end of lines?  Well, I know that doing an FTP 
ASCII transfer will take care of it, but this is a problem that can't be solved 
that way.

I have a script on my page that takes a form (text box) and formats the entry 
nice and pretty for viewing (in theory).  I don't immediately put entries into 
the production guestbook page because I like to review them, then 
cut-and-paste the code perl formats for me into the production page from the 
flat file.  The HTML code comes out right (it ignores the "^M" I think), but 
when I look at the source code, in has ^M at the end of each stinking line for 
a multi-line text-box "comments" entry.  So ASCII won't help me here.  I've 
tried substituting for newlines, I've tried chomping, nothing seems to be 
working.  Example code follows.  I surely would appreciate anyone who has the 
time to help a new guy.

###-----------------------------------
if ($Form{Comment}) {

	# Printing to flat file for review of guestbook entries
	print GBFILE "<p><b>Comment:</b> ";            

	#Splitting each line
	@susanna = split(/^/m, $Form{Comment});

	# Here is my desperate attempt to kill the "^M"
	foreach $line (@susanna) {
		chomp $line;
		chomp $line;
		$line =~ s/(\s+)?\n+(\s+)?//g;
		print GBFILE $line;
	}

	# Double-space to separate entries
	print GBFILE "\n\n";
}
print GBFILE "<hr WIDTH=\"100%\">\n\n";
###-----------------------------------



Sorry to waste anyone's time, but thanks if you help.
--
tbholdren

p.s. Some of you may notice that his is my butchered version of part of Matt's 
Script Archive FormMail.pl



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

Date: Sat, 26 Dec 1998 18:02:50 +0000
From: "Geir Magnusson Jr." <gmj@netaxis.com>
Subject: Re: ------What should I use as a Win32 perl interpreter-----
Message-Id: <368524C9.C4FA4BAA@netaxis.com>

QnJldHQgU3VtbWVyZXIgd3JvdGU6DQoNCj4gICAgICAgICBSaWdodCBub3cgSSB1c2UgQWN0
aXZlUGVybCwgYmVjYXVzZSBpdCdzIGZyZWUuICBBbnkgb3RoZXINCj4gaWRlYXM/ICBBbHNv
LCBkb2VzIGFueW9uZSBrbm93IHdoZXJlIEkgY2FuIGZpbmQgYSBkZWNlbnQgYm9vayBvbg0K
PiBnZXR0aW5nIHBlcmwgc2NyaXB0cyB0byBydW4gb24gYSBOVCBib3g/ICBBbGwgb2YgdGhl
IG9uZXMgdGhhdCBJIGZvdW5kDQo+IGFyZSB3cml0dGVuIHdpdGggVU5JWCBpbiBtaW5kLiAg
SSBkbyBteSBkZXZlbG9wbWVudCBvbiBTcGFycXMsIGJ1dCBvdXINCj4gd2ViIHNlcnZlciBp
cyBEb21pbm8gb24gTlQuDQo+DQo+ICAgICAgICAgLUJyZXR0IFN1bW1lcmVyDQo+IHN1bW1l
cmUxQHBpbG90Lm1zdS5lZHUNCg0KV2hhdCBhYm91dCBnZXR0aW5nIGFuZCBjb21waWxpbmcg
dGhlIHJlZ3VsYXIgZGlzdHJpYnV0aW9uPyAgSSBkbyB0aGF0LA0KYW5kIEkgYW0gaGFwcHkg
YXMgYSAgY2xhbS4NCg0KZ2Vpcg0KDQotLQ0KR2VpciBNYWdudXNzb24gSnIuDQpnbWpAbmV0
YXhpcy5jb20NClBlcmwncyBnYXJiYWdlIGNvbGxlY3RvciBhYmhvcnMgYSBuYWtlZCBjaXJj
dWxhcml0eS4gLXRjDQpDaGFzZSB0aGUgZHJlYW0sIG5vdCB0aGUgY29tcGV0aXRpb24uDQoN
Cg0K


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

Date: Sat, 26 Dec 1998 11:07:34 -0800
From: see@my.sig (Don Groves)
Subject: Re: >>>> A Singaporean Girl looking for more penpals!!<<<<<
Message-Id: <MPG.10eed3d4f966b28e989758@news.europa.com>

In article <3684C04A.F3405D02@xs4all.nl>, debot@xs4all.nl says...
> I thought this was a newgroup for questions about PERL not about
> friendships.
> Maybe you can check this site out: http://www.debot.nl/ppi/
> 
> hocker wrote:

Maybe she's Just Another Perl Hocker ;-)

-- 
Don Groves (groves_acm_org)
Replace underscores to get my email address


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

Date: 26 Dec 1998 15:51:21 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: a nicer way?
Message-Id: <7630lp$j7g$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    jcostom@madcow.jasons.org (Jason Costomiris) writes:
:You might want to clue Lincoln Stein in on this.  In my copy of the
:man page to CGI.pm (obviously, gen'd from the embedded pod), all of
:his examples use the OO syntax.

This is what we call an historical artifact -- he wrote the documentation
before he had introduced the procedural interface.   He merely never
bothered to rewrite it.  I hereby volunteer to amend the documentation
to mirror its more customary and normal use.

:I guess Lincoln's a nut too.  Permit me to be the first to congratulate
:Lincoln on his status as a nut!  You're really getting absurd here, Tom.

Nice strawman, but I refuse to rise.  My previous statements stand,
and the words you'd like to put in my mouth do not.

:Not everything has to be an object, but many times, they are useful,
:like in conjunction with CGI.pm.  Obfuscation?  Now I could see you 
:claiming obfuscation if I had pack() and unpack()'d everything using
:some sort of funky args, and did some bit shifts to hide the meaning
:of my code.  Invoking methods of an object?  That's not obfuscation.

It can be, it can be.  And in this case, it is.  There's no reason
to use the silly object stuff when there is only one object!

:Tom's a great guy, who's done a lot for perl.  He's also human, that is,
:occasionally will be wrong.  IMHO, this is one of those occasions.

Oddly, I fail to see your alleged humility manifest.  The simple point is that
your version is needlessly redundant:

    use CGI qw(:standard);:
    my $query = new CGI;:
    my $id    = $query->param("id");:
    my $name  = $query->param("name");
    my $info  = $query->param("info");

And that the following does the same thing with less redundancy:

    use CGI qw(:standard);:
    my $id    = param("id");:
    my $name  = param("name");
    my $info  = param("info");

When a programmer sees the same code in more than one place in a program,
that redundancy is factored out.  When you see two subroutines doing
the same thing, or two variables holding the same data, or two tests
checking the same condition, this elicits the same reaction: factor out
the duplicates, merge the repetitive bits. 

Haven't you read how Larry tsk-tsks scripts with 20 lines of 
    print "whatever\n";
with all the redundant print and \n stuff?  Why do you think this seems
silly to him?  Why do you think your code seems silly to me, especially
used as a "correction" to my simple and elegant version?

Again, if you prefer to program your Perl in an unidiomatic, C--looking
way, then certainly you are free to do that in your own private code.
But to pretend that such obfuscations are natural or beneficial for
their own sake does no one any good.

So let's not do that.

--tom
-- 
Can you sum up plan 9 in layman's terms? It does everything 
    Unix does only less reliably    --Ken Thompson


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

Date: 26 Dec 1998 20:17:33 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: a nicer way?
Message-Id: <914703451.605716@elaine.drink.com>

In article <3684f2d1.157250@news.skynet.be>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Objects are fine, if you have multiple instances. You ordinarily have
>only ONE CGI object. Therefore, the necessity to have it is annoying.

Many of my CGI programs use more than one CGI object.

As an example, a program I was working on last week, there is one CGI
object for the user's current input, and one is used to read in the
past input from a file. Anything the user doesn't input is defaulted
from the second object.




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

Date: 26 Dec 1998 20:24:20 GMT
From: jcostom@madcow.jasons.org (Jason Costomiris)
Subject: Re: a nicer way?
Message-Id: <slrn78ahfk.6q8.jcostom@madcow.jasons.org>

On 26 Dec 1998 15:51:21 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
: :I guess Lincoln's a nut too.  Permit me to be the first to congratulate
: :Lincoln on his status as a nut!  You're really getting absurd here, Tom.
: 
: Nice strawman, but I refuse to rise.  My previous statements stand,
: and the words you'd like to put in my mouth do not.

No need to shove words in your mouth.  You said "Don't be a nut." when 
I suggested use of objects.  I pointed out that LDS himself, the author
of CGI.pm suggests (in his docs) the OO use of CGI.pm.  Now you're 
making up excuses for him.  Has LDS stated that he needs to update 
the docs?  If not, then why not accept the fact that his docs suggest
the OO use?  You also said he hasn't had the time.  I too wish there were
more hours in the day, but what would be so hard about:

:g/$query->/s///g

?  That would make for a good start on the way to updating the docs.

: Oddly, I fail to see your alleged humility manifest.  The simple point is that
: your version is needlessly redundant:

Be that as it may, you have done a lot for perl.

: Haven't you read how Larry tsk-tsks scripts with 20 lines of 
:     print "whatever\n";

I agree with him. A "here" doc is much more effective.

: Why do you think your code seems silly to me, especially
: used as a "correction" to my simple and elegant version?

Why is it that everyone insists that I was correcting you?  I *ASKED* if
there was any real advantage over my style.  As of this time, nobody has
answered the question I posed, so I will assume that they are equivalent
from more than just the functional standpoint.  Now, if my way cost more 
CPU cycles than yours, changing to your way, might be worth it.

Oh well, unless you've got something constructive to add, let's stop
burning cycles on this.

-- 
Jason Costomiris <><            | Linux...
jcostom@jasons.org              | "Find out what you've been missing 
http://www.jasons.org/~jcostom/ | while you've been rebooting Windows NT."
#include <disclaimer.h>         |         --Infoworld


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

Date: 26 Dec 1998 20:34:18 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: a nicer way?
Message-Id: <763h8a$520$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, gorilla@elaine.drink.com (Alan Barclay) writes:
:As an example, a program I was working on last week, there is one CGI
:object for the user's current input, and one is used to read in the
:past input from a file. Anything the user doesn't input is defaulted
:from the second object.

That's a very nice example.  I keep meaning to write it up for someone.

--tom
-- 
 Thou shalt run lint frequently and study its pronouncements with care, for
 verily its perception and judgement oft exceed thine.
   --1st commandment for C programmers


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

Date: 26 Dec 1998 20:37:16 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: a nicer way?
Message-Id: <763hds$520$2@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    jcostom@madcow.jasons.org (Jason Costomiris) writes:
:Why is it that everyone insists that I was correcting you?  I *ASKED* if
:there was any real advantage over my style.  As of this time, nobody has
:answered the question I posed, so I will assume that they are equivalent
:from more than just the functional standpoint.  

You're wrong.   I've answered many times.  It is needlessly redundant.
It says the same thing more than once.  It takes more to type
the same thing again and again and again.  It's been said before.
It's repetitive.  It is unidiomatic.  It's repetitive.

Get the point?  If not, please stop trying.

--tom
-- 
    "The usability of a computer language is inversely proportional to the
    number of theoretical axes the language designer tries to grind."
    	--Larry Wall


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

Date: 26 Dec 98 14:01:49 -0600
From: "Gary Peake" <gpeake@wt.net>
Subject: Accessing Databases
Message-Id: <300.664T2453T8414377gpeake@wt.net>

Can someone point me to a perl/cgi program that will allow me to
access mSQL database on my web host?

Many thanks!

--
Gary Peake    PLEASE NOTE NEW EMAIL ADDRESS!!

Team AMIGA - OwlNet Net
gary@owlnet.net
http://www.owlnet.net (coming soon)



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

Date: Sat, 26 Dec 1998 10:38:43 -0500
From: Shane Snedecor <shane@exis.net>
To: KJPhilbr13 <kjphilbr13@aol.com>
Subject: Re: Best Perl Book for a "Not Yet" Perl Programmer
Message-Id: <Pine.LNX.3.95.981226103758.15702A-100000@tarpon.exis.net>

I have been reading Learning Perl by O'Reilly It's really good and starts
you off from the beginning. Check it out.


------------------- Follow the Leader! - Exis Net -----------------
Shane Snedecor          Phone: (757)552-1009   Fax: (757)552-1019
Technical Support       Tech Support Email  -  support@exis.net
shane@exis.net          Billing Email       -  billing@exis.net
-------------------------------------------------------------------

On 25 Dec 1998, KJPhilbr13 wrote:

> Date: 25 Dec 1998 17:45:03 GMT
> From: KJPhilbr13 <kjphilbr13@aol.com>
> Newsgroups: comp.lang.perl.misc
> Subject: Best Perl Book for a "Not Yet" Perl Programmer
> 
> Background in C, C++, Visual Basic, sh, ksh, etc...
> 
> What is the best book to start?  Need to understand program structure, language
> references, hints/examples, etc.
> 
> Thanks in advance...Kevin P. in Charlotte, NC
> 
> 



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

Date: Sat, 26 Dec 1998 14:02:43 -0500
From: stevenba@ccpl.carr.org (Steven Barbash)
Subject: Boolean search facility
Message-Id: <MPG.10eefcdfaa7e8337989688@www.siast.sk.ca>

Hello all,

Please pardon me if this is a FAQ which I've missed.
In the name of "Not reinventing the wheel":

Is there a package or module or extension or software or link to software 
or ...
which does a boolean search?
more specifically,
not limited to AND and OR and NOT,
but doing NEAR?

(I observe several web search engines doing this.  But I haven't a clue 
if such software is obtainable.)

I plan to use it just to search documents on my own machine.

Thanks.
Steve


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

Date: 26 Dec 1998 17:01:40 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: Compiling Win32
Message-Id: <slrn78a65b.jdv.randy@theory.uwinnipeg.ca>

On Sat, 26 Dec 1998 07:57:12 +1100, Darren Ward <dward@pla.net.au> wrote:
>Hi All,
>
>Having trouble compiling perl on win98
>
>I have downloaded mingw32 and installed it correctly (the gcc 2.8.1
>version)
>
>However the compile errors with the dmake script
>It doesn't like the '&&' sections of the makefile.mk and I'
>m not sure of whats needed to fix it.
>

Hi,
   About a week ago Steven Morlock posted a couple of messages
detailing how to build perl on Win32 using cygwin; you could
search dejanews for the postings (subject: HOWTO: Building perl
under Win95). However, at least under cygwin, if you use gcc,
you should also use the make utility that comes with it, and
not dmake. The && does cause some problems in the DOS "shell",
specifically a make command of the form
	command_1 > file && command_2
This can be fixed by manually executing the two commands on 
either side of the &&, or by editing ExtUtils/MM_Unix.pm -
specifically, the xs_c and xs_o subs - to do the same. 
You may also want to look into the 4DOS shell, which is an
improvement over the DOS shell (but still has the above problem).
The bash shell that comes with the cygwin tools should handle 
the && OK - I'm not sure, though, if you can mix the cygwin
bash shell with the mingw32 tools.

-- 
		Best regards,
		Randy Kobes

Physics Department		Phone: 	   (204) 786-9399
University of Winnipeg		Fax: 	   (204) 774-4134
Winnipeg, Manitoba R3B 2E9	e-mail:	   randy@theory.uwinnipeg.ca
Canada				http://theory.uwinnipeg.ca/


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

Date: Sat, 26 Dec 1998 13:32:40 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Convert textarea line wraps to print
Message-Id: <1dknal7.1481mia11k41a8N@bos-ip-1-97.ziplink.net>

McWebber <mcwebber@my-dejanews.com> wrote:

> Except I tried what you wrote in your original reply: "<br>\n" not "\n<br>"
> and that didn't work. Maybe I wasn't placing it in the correct place.
> Doesn't matter, as it's working as I wanted now.

It doesn't matter whether it's "<BR>\n" or "\n<BR>".  The <BR> is
significant when the HTML document is formatted for display; the "\n" is
not.  But, as before, that's more of an HTML question.  :-)

-- 
 _ / '  _      /         - aka -          rjk@linguist.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: 26 Dec 1998 20:10:01 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: faster than regexp
Message-Id: <914702996.358302@elaine.drink.com>

In article <MPG.10e9e89c96e394bb9898ed@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>[Posted to comp.lang.perl.misc and a copy mailed.]
>
>In article <36802AC2.FAF1380F@gmx.de> on Wed, 23 Dec 1998 00:26:58 
>+0100, Rolf Dewitz <r2.d2@gmx.de> says...
>> I've to analyse a very long log-file line by line. So i'm looking for a
>> method to split these lines without regexp very fast. Thanks.
>
>> $logline=~/^(.+?) - (.+?) \[(.+?):(\d\d:\d\d:\d\d) .+?\] "([A-Z]+?)
>> (.*)\/[^\/]* .+?" /o;
>                     ^  Not needed -- no interpolation in the regex.
>   
>> proxy.bla.de - so [20/Aug/1998:09:31:07 +0200] "GET /images/suche.gif
>> HTTP/1.0" 304 -
>
>Here are four of the ways to split a line:
>
>substr() -- works best with fixed column widths, so not in this case.
>
>unpack() -- works best with fixed column widths, so not in this case.
>
>split() -- requires a single pattern to split on, so not in this case.
>
>regex -- works at arbitrary places, so appropriate for this case.
>
>I have found by benchmarking that instead of using lots of '.*?' and 
>'.*' patterns, it is best to be as specific as you can.  So, in your 
>case, the following might be faster (but there are no guarantees -- 
>learn how to use Benchmark.pm yourself) UNTESTED:
>
>m!^                # To get rid of "Leaning-Toothpick Syndrome"
>  ([a-z.]+)        # Domain (could just use \S+)
	
Domain names can have numbers and "_"'s in them, and even though they're
not strictly allowed, some domains have  "-"'s too.

>  \s-\s            # Space dash space (could just use \W+)
>  ([a-z]+)         # Lower-case letters (could just use \S+)
>  \s\[             # Space left-bracket
>  ([^:]+):         # Date
>  (\d\d:\d\d:\d\d) # Time
>  [^"]+"           # Stuff to double-quote
>  ([A-Z]+)\s       # Upper-case letters (could just use \S+)
>  (.*)/            # Path (could be more specific)
>  ([a-z.]+)        # Filename (could just use \S+)
	
Filenames can easily have Uppercase, digits, and other non alpha characters.





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

Date: Sat, 26 Dec 1998 11:06:11 -0800
From: "David Harris" <dharris@dlconsulting.com>
Subject: Need sample TCP code
Message-Id: <1J8h2.2022$XY6.52929@news.san.rr.com>

I would really appreciate some help on this one.  I'm trying to find some
sample code to allow me to make an http request from within a PERL script
and then process the results.  I imagine I need to open up a TCP connection
on port 80 to the host.  I would appreciate it if someone could show me some
sample code on how to do this.  Thanks.

Happy Holidays,
David





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

Date: Sat, 26 Dec 1998 18:26:27 GMT
From: mschechter@earthlink.net (Mike Schechter)
Subject: Re: Need sample TCP code
Message-Id: <36852a24.6404769@news.earthlink.net>

On Sat, 26 Dec 1998 11:06:11 -0800, "David Harris"
<dharris@dlconsulting.com> wrote:

>I would really appreciate some help on this one.  I'm trying to find some
>sample code to allow me to make an http request from within a PERL script
>and then process the results.  I imagine I need to open up a TCP connection
>on port 80 to the host.  I would appreciate it if someone could show me some
>sample code on how to do this.  Thanks.
>
>Happy Holidays,
>David

Try the libwww-perl module.  It does exactly what you are looking for,
and can be found on CPAN.

Mike Schechter



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

Date: Sat, 26 Dec 1998 13:26:56 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Need sample TCP code
Message-Id: <0ad367.7ad.ln@magna.metronet.com>

David Harris (dharris@dlconsulting.com) wrote:
: I would really appreciate some help on this one.  I'm trying to find some
: sample code to allow me to make an http request from within a PERL script
: and then process the results.  I imagine I need to open up a TCP connection
: on port 80 to the host.  I would appreciate it if someone could show me some
: sample code on how to do this.  Thanks.


use LWP::Simple;

$page = get('http://www.perl.com');

# process the results

;-)


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


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

Date: Sat, 26 Dec 1998 20:14:49 GMT
From: hoangngo@usa.net
Subject: PERL OO: Function overloading
Message-Id: <763g3n$1nm$1@nnrp1.dejanews.com>

Hello-

Can anyone out here tell me if PERL offers function overloading? I am trying
to create a function and depends on the parameter passed to it (scalar,
array, or hash) it will behave differently. One way is to detect the type of
parameter, the other way is use function overloading. Unfortunately, i
couldn't find the solutions in PERL documentation. Please drop me a line if
you have any information on this.

Thanks,
Hoang

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 26 Dec 1998 20:46:23 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: PERL OO: Function overloading
Message-Id: <763huv$520$3@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, hoangngo@usa.net writes:
:Can anyone out here tell me if PERL offers function overloading? I am trying
:to create a function and depends on the parameter passed to it (scalar,
:array, or hash) it will behave differently. One way is to detect the type of
:parameter, the other way is use function overloading. 

That only makes sense in a static language.  Perl is a dynamic one.
Perl has no need of such.  That's because Perl can determine the number
and type of arguments passed, and the return context.

:Unfortunately, i
:couldn't find the solutions in PERL documentation. Please drop me a line if
:you have any information on this.

Here you go.

1.  Return context

    if (wantarray()) {
	# list context
    } 
    elsif (defined wantarray()) {
	# scalar context
    } 
    else {
	# void context
    } 

2.  Number of arguments

    my $argc = @_;

3.  Type of arguments (string vs number)

    if ($arg =~ /^\d+$/) {
	# do the numeric thing
    } 
    else {
	# do the string thing
    } 

4.  Class of arguments (ref type)

    unless(ref $arg) {
	# handle nonref case
    } 

    for (ref $arg) {
	/^HASH$/	    && do {
				# deal with hash ref case
				last;
			       };
	/^ARRAY$/	    && do {
				# deal with array ref case
				last;
			       };
	/^SCALAR$/	    && do {
				# deal with scalar ref case
				last;
			       };
	/^CODE$/	    && do {
				# deal with code ref case
				last;
			       };
	/^IO::/	    	    && do {
				# deal with handle case
				last;
			       };
	# etc
    } 

--tom
-- 
    if (rsfp = mypopen("/bin/mail root","w")) {     /* heh, heh */
        --Larry Wall in perl.c from the perl source code


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

Date: Sun, 27 Dec 1998 00:13:35 +0800
From: sky <tbsky@ms7.url.com.tw>
Subject: PERL's bug ?? why different ???
Message-Id: <36850B2E.8EF4894E@ms7.url.com.tw>

i write a program. a.pl

#!/usr/bin/perl
sub SOT {
       print " @_" ;
       }
SOT hello ;

and when i seprate it , it refuse to work anymore  ....

a.pl
#!/usr/bin/perl
require  'b.pl';
SOT hello ;

b.pl
#!/usr/bin/perl
sub SOT {
       print "@_" ;
       }
1;


i must  fix a.pl like this  SOT (hello) ;
 to make it work....
so how can i seprate a program to several parts, and make it  work as
before ???
require() is not good enough....










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

Date: Sat, 26 Dec 1998 16:46:50 GMT
From: mschechter@earthlink.net (Mike Schechter)
Subject: Re: PERL's bug ?? why different ???
Message-Id: <368512a6.390571@news.earthlink.net>

On Sun, 27 Dec 1998 00:13:35 +0800, sky <tbsky@ms7.url.com.tw> wrote:

>i write a program. a.pl
>
>#!/usr/bin/perl
>sub SOT {
>       print " @_" ;
>       }
>SOT hello ;
>
>and when i seprate it , it refuse to work anymore  ....
>
>a.pl
>#!/usr/bin/perl
>require  'b.pl';
>SOT hello ;
>
>b.pl
>#!/usr/bin/perl
>sub SOT {
>       print "@_" ;
>       }
>1;
>
>
>i must  fix a.pl like this  SOT (hello) ;
> to make it work....
>so how can i seprate a program to several parts, and make it  work as
>before ???
>require() is not good enough....

Yes it is, you just have to declare your variables.

Try:

sub SOT {
	local ($myvar) = @_;
	print $myvar;
}

Mike Schechter



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

Date: Sat, 26 Dec 1998 18:02:32 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: PERL's bug ?? why different ???
Message-Id: <F4L3G8.3Gv@world.std.com>

sky <tbsky@ms7.url.com.tw> writes:

>and when i seprate it , it refuse to work anymore  ....

>a.pl
>#!/usr/bin/perl
>require  'b.pl';
>SOT hello ;

>b.pl
>#!/usr/bin/perl
>sub SOT {
>       print "@_" ;
>       }
>1;


>i must  fix a.pl like this  SOT (hello) ;
> to make it work....
>so how can i seprate a program to several parts, and make it  work as
>before ???


You have to remember that "require" happens at run time, so perl has
had to make lots of decisions and assumptions by the time it sees the
file specified by require.

If perl sees that a subroutine SOT exists it can assume that "SOT
hello" is a call to the subroutine when it is compiling the line. If
it is preceded by the word "do" or the symbol "&", or its arguments
are in parenthesis, it can figure that it is a call to a subroutine
even if it doesn't know about the subroutine yet. It knows that it is
a call to some subroutine, it will just worry about which one later.


I don't quite understand why you say that you "can't" use
parenthesis. It seems unreasonable as an design requirement. I can
understand a curiosity on why the change in behavior occurs.


So here are some solutions.

Perl has another external file loading function called "use". One key
feature of "use" is that as soon as perl reaches that line in its
"compilation" phase, it compiles and immediately executes its
contents. (Notice that this is unlike require, which compiles the
statement and then postpones its execution until the statement is
reached.) The semantics of "use" is slightly different, so you might
want to take a look at its entry in the perlfunc man page.

In its most basic form though, it should give the "compile time"
effects that you expected of require.


File filea.plx:
#!/usr/bin/perl -w

use FileB;
use strict;

SOT 'hello';


File FileB.pm:

sub SOT {
  print "@_\n";
}

1;


The real purpose behind the "use" is for fully featured perl modules.
A standard looking module is a little more verbose (and a little more
complex) than just external file with subroutine definitions. Luckily,
most of the extra stuff is fairly boilerplate material. You can create
the starting point to a module with the h2xs command.

      h2xs -AX -n FileB


For more about the differences between use and require, see
<URL:http://www.perl.com/CPAN/doc/FMTEYEWTK/use_vs_require>

-- 
Andrew Langmead


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

Date: Sat, 26 Dec 1998 13:32:41 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: PERL's bug ?? why different ???
Message-Id: <1dknazq.c081781vir4z0N@bos-ip-1-97.ziplink.net>

Mike Schechter <mschechter@earthlink.net> wrote:

> Yes it is, you just have to declare your variables.
> 
> Try:
> 
> sub SOT {
>   local ($myvar) = @_;
>   print $myvar;
> }

Did you try it?

I'm afraid that not only does that change the meaning of SOT(), it also
has no bearing on the original poster's problem, which is that 'SOT
hello;' does not work when the subroutine SOT is declared in another
file.


One way to fix it is to add parens, as the original poster mentioned:
SOT(hello);


Another is to predeclare SOT in a.pl:
use vars qw(SOT);


A third would be to turn b.pl into an actual module, and have SOT
imported into the main package:

B.pm:

package B;
use Exporter ();
@ISA = qw(Exporter);
@EXPORT = qw(SOT);

sub SOT {
  print "@_";
}

a.pl:

use lib 'path/to/mylib';
use B;

SOT hello;

-- 
 _ / '  _      /         - aka -          rjk@linguist.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: Sat, 26 Dec 1998 18:28:10 GMT
From: mschechter@earthlink.net (Mike Schechter)
Subject: Re: PERL's bug ?? why different ???
Message-Id: <36852a87.6503611@news.earthlink.net>

On Sat, 26 Dec 1998 16:46:50 GMT, mschechter@earthlink.net (Mike
Schechter) wrote:

>Yes it is, you just have to declare your variables.
>
>Try:
>
>sub SOT {
>	local ($myvar) = @_;
>	print $myvar;
>}

Note that sub SOT would be in file "b.pl" and would be required by
a.pl.

Mike Schechter



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

Date: Sat, 26 Dec 1998 20:24:45 GMT
From: mschechter@earthlink.net (Mike Schechter)
Subject: Re: PERL's bug ?? why different ???
Message-Id: <3685457b.13403463@news.earthlink.net>

On Sat, 26 Dec 1998 13:32:41 -0500, rjk@linguist.dartmouth.edu (Ronald
J Kimball) wrote:

>Mike Schechter <mschechter@earthlink.net> wrote:
>
>> Yes it is, you just have to declare your variables.
>> 
>> Try:
>> 
>> sub SOT {
>>   local ($myvar) = @_;
>>   print $myvar;
>> }
>
>Did you try it?
>
>I'm afraid that not only does that change the meaning of SOT(), it also
>has no bearing on the original poster's problem, which is that 'SOT
>hello;' does not work when the subroutine SOT is declared in another
>file.

Nope, didn't try it.  Guess I jumped the gun there.  Missed the "no
parens."  Had run into a similar problem before, where the sub worked
in one file, but didn't when I placed in another file, and that's how
I got it to work.  My mistake.

Mike Schechter



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

Date: Sat, 26 Dec 1998 10:17:25 GMT
From: hi@there.com
Subject: Problem with Active Perl
Message-Id: <3684b7af.8007453@news.freeserve.net>

I'm using Active Perl and I've got a problem:

When I run a program, the MS-DOS window opens as usual.  If there are
errors the appropriate error messages are displayed.  Then, the window
closes!!!  I don't get a chance to see the errors!

Does anyone know how to get around this?

Please reply to:
nc@cyberdude.com

Thanks!


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

Date: Sat, 26 Dec 1998 15:16:12 +0100
From: "Ronald Gvggel" <rgoeggel@atos-group.com>
Subject: Re: REGex that doesn't work, why?
Message-Id: <762rh9$hnf$1@news.pop-stuttgart.de>

Jim Matzdorff schrieb:
> 
> I can't figure out why this doesn't return a pattern match (or I should say a "true")...
> 
> $match = "is '^]'."

                     ;

> $looking_for =  "/is.\'\^\]\'\.|to.console./";

  $looking_for =  'is.\'\^\]\'\.|to.console.';

> 
> if ( $match =~ $looking_for )

  if ( $match =~ /$looking_for/ )

> {
>    print "yes"
> }
> 
> but if you set:
> $looking_for = " /\'\^\]\'|console"

not on my perl ! ;-(

> 
> it finds it just fine.
> 
> What am i missing?
> 
> --jim


If you have problems like that:
1. use the flag "-w"
2. print out the contents of  your variables; then you can see the
meaning ov \ and '..' "..". 

--ronald


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

Date: Sat, 26 Dec 1998 19:59:48 +0100
From: "Christian" <cb2001@hotmail.com>
Subject: split resultspages
Message-Id: <36853008.0@info.xpoint.at>

hello everybody!

who can tell me how i can split my search result, that i get from  SQL, into
pages? that means, if my perl-script returns 100 results, i wanna show the
user 10 results per page!


many thankx in advance!

chRiS




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

Date: Sat, 26 Dec 1998 14:20:39 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: split resultspages
Message-Id: <MPG.10ef0113af0001398976d@news.scescape.net>

In article <36852f69.0@info.xpoint.at>, cb2001@hotmail.com says...
=> hello everybody!

heLlO chRiS!

=> who can tell me how i can split my search result, that i get from  SQL, into
=> pages? that means, if my perl-script returns 100 results, i wanna show the
=> user 10 results per page!

This really just depends on what you want to do.

Since this has almost nothing to do with Perl, you would be better off 
asking in comp.infosystems.www.authoring.cgi.

But, you might be interested in visiting Randal Schwartz's page:

     http://www.stonehenge.com/merlyn

Especially:

     http://www.stonehenge.com/merlyn/WebTechniques

And the column you'd be interested in would be:

     Giving 'more' (May 96)
     http://www.stonehenge.com/merlyn/WebTechniques/col02.html
     
=> many thankx in advance!

Hope This Helpz!

=> chRiS

--Matthew


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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