[19745] in Perl-Users-Digest
Perl-Users Digest, Issue: 1940 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 16 18:05:38 2001
Date: Tue, 16 Oct 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003269909-v10-i1940@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 16 Oct 2001 Volume: 10 Number: 1940
Today's topics:
Re: A bug in s///e? <sguazt@infodrome.net>
Re: A bug in s///e? <joe+usenet@sunstarsys.com>
Can't get the output for shell command from CGI (Carfield Yim)
Re: Can't get the output for shell command from CGI <ron@indra.com>
Checking the remote file (Peter Sun)
Re: Does anyone happen to have a place where i could re <arnuga@yahoo.com>
Re: Don't want to invent the wheel <arnuga@yahoo.com>
Re: Don't want to invent the wheel <Tassilo.Parseval@post.rwth-aachen.de>
Re: Don't want to invent the wheel <uri@sysarch.com>
Help with write <sivaram@atlantis-consulting.com>
Re: Help with write <bart.lateur@skynet.be>
how to find memory leaks in perl 5.004_04 (Jim Anderson)
How to restore a filehandle tie correctly? <newspost@coppit.org>
Re: How to undef many vars at once <uri@sysarch.com>
how to write to different host+port on one socket? (Thomas Erskine)
Manipulating Strings Within A Text File (Mua Bao)
Re: Manipulating Strings Within A Text File (Garry Williams)
Re: Need cgi script <jurgenex@hotmail.com>
Re: Need cgi script <uri@sysarch.com>
Re: Need cgi script <bart.lateur@skynet.be>
Re: Need cgi script <uri@sysarch.com>
Re: newbie - initializing hash from a file doesn't work (remove the obvious)
Objects: Setting defaults and calling themselves?? <ekulis@apple.com>
Re: problems with autoloader <ron@indra.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Oct 2001 17:38:59 +0200
From: "Marco Guazzone" <sguazt@infodrome.net>
Subject: Re: A bug in s///e?
Message-Id: <9qhjcf$s7s$1@serv1.iunet.it>
With only one 'e' (s//e) the replacement text is treated as
Perl expression; so s/$search/"$repl"/gie is treated like
s/$search/$repl/gie or like s/$search/$repl/gi (i.e. $repl is interpolated
and its
content is used as replacement text).
With two 'e's (s//ee) the replacement text is evaluated and
then interpolated; so you can use:
s/$search/"\"$repl\""/giee
with only one 'e' you would get
"this is $1. hi there" "this is $1. hi there"
as replacement text.
Adding another 'e' $1 will be interpolated with the right value.
Marco Guazzone
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:mbhost4c2cii756ghfu2dgcj889ptpdndg@4ax.com...
> Can anybody please explain why, when I do this:
>
> my $repl='this is $1. hi there.';
> my $search='(foo)';
> my $s="X foo Y\n";
> $_ = $s; s/$search/"$repl"/gi; print;
> $_ = $s; s/$search/'"'.$repl.'"'/gie; print;
>
> I get the same result for both:
>
> X "this is $1. hi there." Y
> X "this is $1. hi there." Y
>
> but when I add an e to the modifiers, they behave differently:
>
> my $repl='this is $1. hi there.';
> my $search='(foo)';
> my $s="X foo Y\n";
> $_ = $s; s/$search/"$repl"/gie; print;
> $_ = $s; s/$search/'"'.$repl.'"'/giee; print;
> ->
> X this is $1. hi there. Y
> X this is foo. hi there. Y
>
> This is 5.6.1 (IndigoPerl, Win32)
>
> --
> Bart.
------------------------------
Date: 16 Oct 2001 13:25:09 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: A bug in s///e?
Message-Id: <m3k7xvcxai.fsf@mumonkan.sunstarsys.com>
Bart Lateur <bart.lateur@skynet.be> writes:
> Likely, with one "e", eval() doesn't even come into play.
Right- I think what happens is that the replacement text is treated
as a block of code- the last line of which is evaluted in scalar
context and used as the replacement text. Fatal errors in this
code block are *not* trapped, so eval is really not relevant here.
But a second "e" *will* eval the result as an EXPR.
> DWIM doesn't always do what you intend. :-/ I don't think this
> behaviour makes a difference, most of the time.
I always used the mnemonic that the first "e" was for "executing" (but
not exec()ing) the code, while the second was for "eval"ing the result.
I don't know where I picked this up, but it stuck.
--
Joe Schaefer "The man who sets out to carry a cat by its tail learns
something that will always be useful and which never will grow
dim or doubtful."
--Mark Twain
------------------------------
Date: 16 Oct 2001 09:57:23 -0700
From: carfield@programmer.net (Carfield Yim)
Subject: Can't get the output for shell command from CGI
Message-Id: <c40dea5f.0110160857.6a6762d8@posting.google.com>
I want to display a HTML of java code to my visitor, so I write the
following script to serve this:
#!/usr/bin/perl -w
use CGI qw(param);
print "Content-type: text/html";
$command = "/usr/local/bin/java2html <
/server/http/java_store/applet/chat/src/com/lyrisoft/auth/mysql/Mysql.java
--title \"powered by java2html from gun.org\"|";
open(IN, $command) || die "cannot open file for reading: $!";
while (<IN>) { # read a line from the command into $_
print $_; # print that line to file $b
}
close(IN) || die "can't close file: $!";
The $command can successful run at shell and display the HTML to
stdout, however in this CGI I get the following error:
/usr/local/bin/java2html: unrecognized option
`--code=http://www.carfield.com.hk/java_store/SUN_j2se_runtime_lib_src_1.4/java/lang/String.java'
can't close file: at /var/www/cgi-bin/java2html.pl line 14.
[Wed Oct 17 00:50:13 2001] [error] [client 10.0.0.1] Premature end of
script headers: /var/www/cgi-bin/java2html.pl
why will this happen?
------------------------------
Date: Tue, 16 Oct 2001 11:42:17 -0600
From: Ron Reidy <ron@indra.com>
Subject: Re: Can't get the output for shell command from CGI
Message-Id: <3BCC7179.7DE9358F@indra.com>
Carfield Yim wrote:
>
> I want to display a HTML of java code to my visitor, so I write the
> following script to serve this:
>
> #!/usr/bin/perl -w
> use CGI qw(param);
>
> print "Content-type: text/html";
>
> $command = "/usr/local/bin/java2html <
> /server/http/java_store/applet/chat/src/com/lyrisoft/auth/mysql/Mysql.java
> --title \"powered by java2html from gun.org\"|";
> open(IN, $command) || die "cannot open file for reading: $!";
>
> while (<IN>) { # read a line from the command into $_
> print $_; # print that line to file $b
> }
> close(IN) || die "can't close file: $!";
>
> The $command can successful run at shell and display the HTML to
> stdout, however in this CGI I get the following error:
>
> /usr/local/bin/java2html: unrecognized option
> `--code=http://www.carfield.com.hk/java_store/SUN_j2se_runtime_lib_src_1.4/java/lang/String.java'
> can't close file: at /var/www/cgi-bin/java2html.pl line 14.
> [Wed Oct 17 00:50:13 2001] [error] [client 10.0.0.1] Premature end of
> script headers: /var/www/cgi-bin/java2html.pl
>
> why will this happen?
You open() command is suspicious. If you want the output, you need to
open like this: open(IN, "|$command") || die ...
See perldoc perolfunc and look for open() and perldoc perlipc
--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
------------------------------
Date: 16 Oct 2001 14:20:11 -0700
From: sunpl@yahoo.com (Peter Sun)
Subject: Checking the remote file
Message-Id: <699c9db.0110161320.4b25f063@posting.google.com>
Hi,
I have created a perl script to check if the file is exist on remote
server.
Both server are Soloaris OS, and I can use rcp to copy file between
these servers. But I can't get the return correctly by :
if (-e "servername:/home/peter/file.txt") { print "The file does
exist";}
please give me some ideas.
Any help/suggestion/idea will be greatly appreciated.
Peter
------------------------------
Date: Tue, 16 Oct 2001 11:14:23 -0700
From: Arnuga <arnuga@yahoo.com>
Subject: Re: Does anyone happen to have a place where i could read up on how to do
Message-Id: <c7uostg2lns5f6caasr9i09fjd0s7nure7@4ax.com>
yeah,
check out Term::ANSIColor on CPAN
David S.
On Tue, 16 Oct 2001 10:25:45 +0200, "sefy" <sefy@bvr.co.il> wrote:
>Does anyone happen to have a place where i could read up on how to do
>#/bin/perl
>
>print ("Hello word"); # in color
>exit(0);
>
>
>Output > Hello word (the font color is change)
>
>Thanks sefy twito B.V.R systems
>
>sefy@bvr.co.il
>
>
>
------------------------------
Date: Tue, 16 Oct 2001 11:15:43 -0700
From: Arnuga <arnuga@yahoo.com>
Subject: Re: Don't want to invent the wheel
Message-Id: <r9uost03c4h8flum6rh3eqfgikns9ikodk@4ax.com>
Check out HTML::Mason...
HTH: this is .misc... dont be a dick <smile>
On Tue, 16 Oct 2001 12:09:31 +0200, Thomas Bätzler
<Thomas@Baetzler.de> wrote:
>On Tue, 16 Oct 2001, Remco van Veenendaal <remco@polderland.nl> wrote:
>[looking for a particular CGI]
>
>Wrong newsgroup. Try http://www.cgi-resources.com/
>
>HTH,
------------------------------
Date: Tue, 16 Oct 2001 20:17:52 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Don't want to invent the wheel
Message-Id: <3BCC79D0.80500@post.rwth-aachen.de>
Remco van Veenendaal wrote:
> Hi,
>
> For my company, I'd like to set up a simple CGI (Perl) WebQ&A (FAQ)
> system as a first step towards knowledge management (crud Q&A via Web
> form, publish FAQ, etc).
>
> I know Perl from a few years ago and I already implemented a very simple
> prototype with text file database. But if there are examples of such
> systems, please help me not to invent the wheel...
Perhaps a little too fullblown but might be worth a peek:
http://search.cpan.org/search?dist=FAQ-OMatic
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Tue, 16 Oct 2001 19:01:27 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Don't want to invent the wheel
Message-Id: <x7u1wz5ryq.fsf@home.sysarch.com>
>>>>> "TB" == Thomas Bätzler <Thomas@Baetzler.de> writes:
TB> On Tue, 16 Oct 2001, Remco van Veenendaal <remco@polderland.nl> wrote:
TB> [looking for a particular CGI]
TB> Wrong newsgroup. Try http://www.cgi-resources.com/
second matt wright site plug today. stop promoting that pile of stinking
manure.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 16 Oct 2001 11:56:57 -0700
From: Sivaram Krishnan <sivaram@atlantis-consulting.com>
Subject: Help with write
Message-Id: <3BCC82F9.1D88B2@atlantis-consulting.com>
I am reading an input ASCII file with the following format:
f00000000 12345678 ABCD 10 20 30
a00000000 43218765 XYZ 1 2 3
etc.
I am interested in each column. So as I parse
I get each column into $1, $2 etc.
Now I am interested in WRITING these values, e.g., $1
into a file as binary data.
$1 which is f0000000 is actually 4 bytes or 32 bits.
I am using syswrite function with the intent of
writing out the bit stream l11100000000.... etc.
But Perl thinks of $1 as ASCII and writes out the
ASCII character bit stream not the hex values.
I tried to do $1 + 4 -4 and assign this to another
variable in the hope that the result would be a
number but I was unsuccessful.
Is there a clean elegant way to do this?
Thanks.
Sivaram
------------------------------
Date: Tue, 16 Oct 2001 21:22:39 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with write
Message-Id: <lo8pst07l2i8ev4git52jj469eardm2ngm@4ax.com>
Sivaram Krishnan wrote:
>I am reading an input ASCII file with the following format:
>
>f00000000 12345678 ABCD 10 20 30
>a00000000 43218765 XYZ 1 2 3
>
>
>etc.
>
>I am interested in each column. So as I parse
>I get each column into $1, $2 etc.
>
>Now I am interested in WRITING these values, e.g., $1
>into a file as binary data.
>
>$1 which is f0000000 is actually 4 bytes or 32 bits.
>I am using syswrite function with the intent of
>writing out the bit stream l11100000000.... etc.
>But Perl thinks of $1 as ASCII and writes out the
>ASCII character bit stream not the hex values.
>Is there a clean elegant way to do this?
syswrite() is actually very closely related to print().
What you must do is first construct the byte sequence you want, and then
get it out to a file. And for that, use pack(). Don't forget to apply
binmode() on your output handle, or otherwise, on DOS/Windows, at least,
your data will still get corrupted.
For example, to turn f00000000 (I assume this is hex?) into a 4 byte
sequence, you can do:
print pack 'N', hex $1; #big endian, Motorola convention
print pack 'V', hex $1; #little endian, Intel convention
pack() allows you to create an entire binary structure in one go:
print pack 'VVvvvv', map hex, $1, $2, $3, $4, $5, $6;
writes $1 and $2 as longs, and $3 through $6 as words.
There may even be more direct ways, with pack()/unpack() and more
obscure template modes ('H' and friends), but I wouldn't go into that as
a newbe, because it generally requires extensive testing before you get
it right.
--
Bart.
------------------------------
Date: 16 Oct 2001 14:02:42 -0700
From: james.h.anderson@ssmb.com (Jim Anderson)
Subject: how to find memory leaks in perl 5.004_04
Message-Id: <2cfb060a.0110161302.40f9fe0c@posting.google.com>
I've got a socket server implemented in perl (5.004_04). It gradually
eats up more and more memory until it eventually dies trying to fork a
child, due to insufficient swap space.
When the process first starts, it takes up 23MB; just before it
crashes, it's up to 200MB :-(
Any suggestions how to isolate the problem would be greatly
appreciated! (The environment is Solaris 5.6)
Thanks very much.
------------------------------
Date: Tue, 16 Oct 2001 16:32:31 -0400
From: David Coppit <newspost@coppit.org>
Subject: How to restore a filehandle tie correctly?
Message-Id: <3BCC995F.1020708@coppit.org>
Greetings all,
I'm trying to update CGI::Cache to play well with FCGI. The problem is
that both want to tie to STDOUT. The obvious solution is to save the old
tie, do whatever I need to do, then restore the tie. However, I'm having
trouble restoring the tie. Here's a complete FCGI compatible script that
illustrates the problem:
#!/usr/bin/perl
package SomePackage;
sub TIEHANDLE
{
my $package = shift;
return bless {}, $package;
}
package main;
use strict;
use FCGI;
my $COUNTER = 0;
my $request = FCGI::Request();
while ($request->Accept() >= 0) {
my $OLD_STDOUT_TIE = tied *STDOUT;
untie *STDOUT;
tie ( *STDOUT, 'SomePackage' );
untie *STDOUT;
# Doesn't work. Causes script to exit as soon as
# FCGI::Stream::PRINT is called.
#tie ( *STDOUT, $OLD_STDOUT_TIE ) if defined $OLD_STDOUT_TIE;
# Works (taken from FCGI code)
tie *STDOUT, 'FCGI::Stream', $request, FCGI::FCGI_STDOUT;
$COUNTER++;
open F, ">>/tmp/log"; print F "Printing\n";close F;
print<<EOF;
Content-type: text/html
<html>
<head><title>Fast CGI</title></head>
<body>Counter: $COUNTER PID: $$</body>
</html>
EOF
}
So I guess my question is this: Is there a general (i.e.
package-independent) technique that I can use to get the extra arguments
for the tie ($request, FCGI::FCGI_STDOUT)?
Thanks,
David
------------------------------
Date: Tue, 16 Oct 2001 18:51:06 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How to undef many vars at once
Message-Id: <x77ktv770e.fsf@home.sysarch.com>
>>>>> "L" == Laocoon <Laocoon@eudoramail.com> writes:
L> $a = $b = undef;
L> ($a,$b) = undef;
the latter one works but not the way you think it does. it assigns the
list (undef) to the vars which causes $b to also get assigned
undef. better off just assigning an empty list:
( $a, $b ) = () ;
works for all sizes of lists of lvalues
but even better, design your code to not need explicit undef's. make the
variables go out of scope so when they are created they are always
undef. IMO assigning undef is usually a marker for poor code design.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: 16 Oct 2001 11:00:59 -0700
From: erskine-google@sourceworks.com (Thomas Erskine)
Subject: how to write to different host+port on one socket?
Message-Id: <afb40365.0110161000.4845a1bd@posting.google.com>
What am I doing wrong? Here's my attempt:
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my $sock = new IO::Socket::INET(
Proto => 'udp',
LocalPort => 10001,
Reuse => 1,
) or die "socket:$!";
$sock->send( 'xxx1', 0, '205.189.80.197:10002') or
warn "send1: $!";
$sock->send( 'xxx2', 0, '205.189.80.197:10003') or
warn "send2: $!";
$sock->send( 'xxx3', 0, '205.189.80.197:10004') or
warn "send3: $!";
------------------------------
Date: 16 Oct 2001 11:04:24 -0700
From: muabao@hotmail.com (Mua Bao)
Subject: Manipulating Strings Within A Text File
Message-Id: <f15abf0e.0110161004.34b48535@posting.google.com>
Hi All,
Let's say I have a file called version.txt that I can open with a text
editor. The file has this line:
#define BUILD_VERSION 9
I need to retrieve the string "9," increment it, write the new value
(10) back into the file.
How do I do that?
Thanks very much for any help.
MuaBao
------------------------------
Date: Tue, 16 Oct 2001 19:03:46 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Manipulating Strings Within A Text File
Message-Id: <slrn9sp14h.k3n.garry@zfw.zvolve.net>
On 16 Oct 2001 11:04:24 -0700, Mua Bao <muabao@hotmail.com> wrote:
> Let's say I have a file called version.txt that I can open with a text
> editor. The file has this line:
> #define BUILD_VERSION 9
>
> I need to retrieve the string "9," increment it, write the new value
> (10) back into the file.
>
> How do I do that?
perl -wpe 's/^(#define BUILD_VERSION )(\d+)/$1.($2+1)/e' filename
--
Garry Williams
------------------------------
Date: Tue, 16 Oct 2001 09:58:48 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Need cgi script
Message-Id: <3bcc6748$1@news.microsoft.com>
<jh123@nc.rr.com> wrote in message news:3bcb92a5.15246056@news-server...
> I need a cgi script to do the following:
webauthoring.cgi may be a better place to ask
[...]
> Could anyone refer me to such a script (or, very kindly, to write such
> a script for me)?
Maybe jobs.offered is a better place to ask?
jue
------------------------------
Date: Tue, 16 Oct 2001 18:58:04 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Need cgi script
Message-Id: <x73d4j76os.fsf@home.sysarch.com>
>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
BL> On-topic here is technical questions, like "how do you do this
BL> better?". You want a prepackaged script. You don't seem to care
BL> how it works. That is off-topic. If you're looking for free
BL> scripts, search the web for "free cgi scripts". Like, uh, here
BL> :<http://cgi.resourceindex.com/>
eww, sending him to matt wright's place? shame on you!
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 16 Oct 2001 21:12:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Need cgi script
Message-Id: <8c8pst07mepcaubjojhcjcipup54r7315p@4ax.com>
Uri Guttman wrote:
> BL> If you're looking for free
> BL> scripts, search the web for "free cgi scripts". Like, uh, here
> BL> :<http://cgi.resourceindex.com/>
>
>eww, sending him to matt wright's place? shame on you!
That ain't Matt Wright's place is it? Because this is:
<http://worldwidemart.com/scripts/>.
I admit that there's a *banner* on each page that points to Matt's
stuff.
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 21:22:45 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Need cgi script
Message-Id: <x7pu7n5lf8.fsf@home.sysarch.com>
>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
BL> Uri Guttman wrote:
BL> If you're looking for free
BL> scripts, search the web for "free cgi scripts". Like, uh, here
BL> :<http://cgi.resourceindex.com/>
>>
>> eww, sending him to matt wright's place? shame on you!
BL> That ain't Matt Wright's place is it? Because this is:
BL> <http://worldwidemart.com/scripts/>.
BL> I admit that there's a *banner* on each page that points to Matt's
BL> stuff.
> whois resourceindex.com
Registrant:
Matt's Script Archive, Inc. (RESOURCEINDEX-DOM)
4225 Cape Cod Circle
Fort Collins, CO 80525
US
Billing Contact:
Wright, Matt (MW3501) mattw@SCRIPTARCHIVE.COM
4225 Cape Cod Circle
Fort Collins, CO 80525
970-223-8465
i rest my case.
:)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 16 Oct 2001 19:20:15 GMT
From: "--Rick" <no_trick@my-de(remove the obvious)ja.com>
Subject: Re: newbie - initializing hash from a file doesn't work
Message-Id: <PL%y7.115008$3d2.3448912@bgtnsc06-news.ops.worldnet.att.net>
"Taku Tokuyasu" <tokuyasu@cc.ucsf.edu> wrote in message
news:a1dadec6.0110151612.6bb19732@posting.google.com...
| I'm trying to reproduce the example in Chapter 1 of Randal Schwartz's
| book,
| http://www.oreilly.com/catalog/lperl2/chapter/ch01.html,
The code you posted works fine on my win98 activestate version. As a
wild guess, it probably has to do with cygwin's line endings.
--
--Rick
------------------------------
Date: Tue, 16 Oct 2001 14:05:25 -0700
From: Ed Kulis <ekulis@apple.com>
Subject: Objects: Setting defaults and calling themselves??
Message-Id: <3BCCA115.AAA5A0BB@apple.com>
Hi,
I'm new at object design and I'm not sure of the conventions for an object calling itself after setting some defaults.
(Please forgive the rambling nature of this posting. I welcome any comments including the idea that this is all the entirely wrong
way to to this. Object design is not yet second nature for me.)
I've written a number of methods that do elementary operations on RCS.
The elementary operasions called from a script like this:
package main;
use lib ".";
use CrmRcs;
use CrmUtil;
my $rcsdo1 = CrmRcs->new('Testing the Auto Rcs Differ');
$rcsdo1->rcsrevdir ('RCS') ;
$rcsdo1->rcsworkdir ('.');
$rcsdo1->rcsworkspec ('GET_XML-FUNCTION.SWBAPPS.VNTVD.ora');
my $revexists =
$rcsdo1->rcsrevspec ('GET_XML-FUNCTION.SWBAPPS.VNTVD.ora,v');
(See Module Details below for a sketch of the package and how it handles the $type ref etc.)
I would like to relegate the calls in the main package to the CrmRcs.pm package or some other package so that I can create a higher
level of abstraction like:
rcscheckinchanges('GET_XML-FUNCTION.SWBAPPS.VNTVD.ora')
which would use the elementary methods to check for the existence of the RCS files and then check in the working file only if
rcsdiff showed a change. I've got all the modules to do the rcs operations and then to detect the responses from rcs
THE QUESTION:
"Where should I put a method that calls other methods within the same instantiation?"
Should I do this:
package main;
my $rcsdo1 = CrmRcs->new('Testing the Auto Rcs Differ');
$rcschgs =
$rcsdo->rcscheckinchanges('GET_XML-FUNCTION.SWBAPPS.VNTVD.ora')
then in the package CrmRcs;
sub rcscheckinchanges
{
my ($type , @args) = @_;
my $workspec = shift @args:
rcsrevdir ($type,'RCS') ; # the defaults need to be handled better.
# passing the type ref to a sub in the same module?
rcsworkdir ($type,'.');
rcsworkspec ($type,$workspec);
$do_checkin = &rcsworkdiff($type, $workspec);
if ($do_checkin)
{
&rcsworkci($type);
# rcsworkci will use values that were set in the class by previous
# method calls.
};
.....
}
Module Details:
my $silly_one_to_keep_compiler_from_barfing = 1;
return $silly_one_to_keep_compiler_from_barfing;
package CrmRcs ;
sub new
{
my ($class, @args) = @_;
my $self = {};
......
bless $self, $class;
return $self;
}
sub rcsrevdir
{
my ($type , @args) = @_;
.....
}
------------------------------
Date: Tue, 16 Oct 2001 11:37:26 -0600
From: Ron Reidy <ron@indra.com>
Subject: Re: problems with autoloader
Message-Id: <3BCC7056.9D2F3462@indra.com>
"Falk P." wrote:
>
> hi,
>
> i dont know why this code behaves different from the source out of a
> book -> i get the error:
>
> "String found where operator expected at Administration/User.pm line
> 19, near "croak "No such method: $AUTOLOAD"" (Do you need to
> predeclare croak?) syntax error at Administration/User.pm line 19,
> near "croak "No such method: $AU
> TOLOAD"" Compilation failed in require at D:\Eigene
> Dateien\HTML\freelancer\cgi\login.pl line 4.
> BEGIN failed--compilation aborted at D:\Eigene
> Dateien\HTML\freelancer\cgi\login.pl line 4."
>
> its about the User.pm, and i dont know why croak is'nt working,
> perhaps you know?
>
> thanks,
> falk
>
> ----- test.pl --------------------------------------
> #!d:/perl/bin/perl.exe -w
> use strict;
> use lib "D:/Eigene Dateien/HTML/freelancer/cgi/Administration";
> use Administration::User;
>
> my $user = Administration::User -> new("testname");
> print $user->get_vorname();
>
> ----- User.pm --------------------------------------
> package Administration::User;
> $VERSION = "0.01";
> use strict;
> use Diagnostics;
> use vars '$AUTOLOAD';
>
> sub new {
> my ($class) = @_;
> $class -> _inc_count();
> bless {_vorname => $_[1],},$class;
> }
>
> sub AUTOLOAD {
> my ($self) = @_;
> $AUTOLOAD =~ /.*::get(_\w+)/
> or croak "No such method: $AUTOLOAD";
> #exists $self->{$1}
> # or croak "No such attribute: $1";
> #return $self->{$1};
> }
>
> #sub get_vorname { $_[0] -> {_vorname} }
> 1;
Because you haven't defined it by importing Carp into the package's
namespace.
--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1940
***************************************