[25229] in Perl-Users-Digest
Perl-Users Digest, Issue: 7474 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 2 06:05:47 2004
Date: Thu, 2 Dec 2004 03:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 2 Dec 2004 Volume: 10 Number: 7474
Today's topics:
Re: <FORM> Submit question with perl cgi scripts <tadmc@augustmail.com>
Re: <FORM> Submit question with perl cgi scripts <bernard.el-haginDODGE_THIS@lido-tech.net>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
FAQ 4.6: Why doesn't & work the way I want it to? <comdog@panix.com>
First attempt at a module fails <gwschenk@fuzz.socal.rr.com>
Re: First attempt at a module fails <jwillmore@fastmail.us>
Re: First attempt at a module fails <gwschenk@fuzz.socal.rr.com>
Re: First attempt at a module fails mccahanry@gmail.com
Re: First attempt at a module fails <spamtrap@dot-app.org>
Re: First attempt at a module fails mccahanry@gmail.com
Re: First attempt at a module fails <spamtrap@dot-app.org>
Re: PAR problems Win32 (Can't Spawn, line 372) (solved) <postmaster@castleamber.com>
parent of an orphaned process-info about perl and OS ve madhav_a_kelkar@hotmail.com
Re: parent of an orphaned process-info about perl and O <spamtrap@dot-app.org>
Perl classes NOT in separate files <andy.glew@intel.com>
Re: Perl classes NOT in separate files <regner@dievision.de>
Re: Perl classes NOT in separate files (Anno Siegel)
Re: Perl classes NOT in separate files <regner@dievision.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 1 Dec 2004 23:50:04 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: <FORM> Submit question with perl cgi scripts
Message-Id: <slrncqtb8c.993.tadmc@magna.augustmail.com>
Sherm Pendley <spamtrap@dot-app.org> wrote:
> Tad McClellan wrote:
>
>> STOP THE TOP-POSTING already!
>
> What are you talking about? His quoting may have been a bit excessive,
> but his reply was at the bottom. He didn't top-post. In fact, I can't
> see that he's done any top-posting in this whole thread.
Oops. Sorry.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 2 Dec 2004 09:24:18 +0100
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: <FORM> Submit question with perl cgi scripts
Message-Id: <Xns95B35FAC81118elhber1lidotechnet@62.89.127.66>
Tad McClellan <tadmc@augustmail.com> wrote:
> Sherm Pendley <spamtrap@dot-app.org> wrote:
>> Tad McClellan wrote:
>>
>>> STOP THE TOP-POSTING already!
>>
>> What are you talking about? His quoting may have been a bit
>> excessive, but his reply was at the bottom. He didn't top-post.
>> In fact, I can't see that he's done any top-posting in this whole
>> thread.
>
>
> Oops. Sorry.
To paraphrase "Sixth Sense" - "I see top-posting."
;-)
--
Cheers,
Bernard
------------------------------
Date: 02 Dec 2004 05:19:26 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1101964729@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
and XEmacs port
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
http://math.berkeley.edu/~ilya/software/emacs/
by Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Thu, 2 Dec 2004 11:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.6: Why doesn't & work the way I want it to?
Message-Id: <comsp5$95n$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
4.6: Why doesn't & work the way I want it to?
The behavior of binary arithmetic operators depends on whether they're
used on numbers or strings. The operators treat a string as a series of
bits and work with that (the string "3" is the bit pattern 00110011).
The operators work with the binary form of a number (the number 3 is
treated as the bit pattern 00000011).
So, saying "11 & 3" performs the "and" operation on numbers (yielding
3). Saying "11" & "3" performs the "and" operation on strings (yielding
"1").
Most problems with "&" and "|" arise because the programmer thinks they
have a number but really it's a string. The rest arise because the
programmer says:
if ("\020\020" & "\101\101") {
# ...
}
but a string consisting of two null bytes (the result of ""\020\020" &
"\101\101"") is not a false value in Perl. You need:
if ( ("\020\020" & "\101\101") !~ /[^\000]/) {
# ...
}
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Thu, 02 Dec 2004 05:26:02 GMT
From: Gary Schenk <gwschenk@fuzz.socal.rr.com>
Subject: First attempt at a module fails
Message-Id: <KHxrd.1691$nP1.85@twister.socal.rr.com>
Exercise 6.8 of "Perl How to Program" asks the student to create
a simple module to use in making a web page. I've failed
miserably at this, and don't know why. The subroutines work when
they are in the source file, but when I call them from a
package, they return an error.
I've gone to learn.perl.org for examples of return statements and
mine seem to be OK. I'm using fully qualified names properly, I
believe. The llama book doesn't go into this deeply, and the
camel book makes my head hurt.
Hopefully someone will spot my error right away. I do appreciate
any help. Here is the source file:
#################################
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
use MINE;
print "Create a simple webpage using my HTML package.\n";
my $start = MINE::start_document();
my $para = MINE::create_paragraph();
my $ending = MINE::end_document();
open( WEB, ">web.html" ) or die("Can't open a new file: $!" );
print( WEB "$start $para $ending");
close WEB;
#####################################
Here is the module MINE.pm:
#####################################
#!/usr/bin/perl
package HTML;
sub start_document
{
print "Enter the title of your webpage: ";
chomp( my $title = <STDIN> );
my $start_statement =
"<html><head><title>$title</title></head><body>\n";
return $start_statement;
}
sub create_paragraph
{
print "Enter a string for a paragraph: ";
chomp( my $string = <STDIN> );
my $para_statement = "<p>$string</p>";
return $para_statement;
}
sub end_document
{
my $end_statement = "</body></html>\n";
return $end_statment;
}
########################################
Here is the error:
-bash-2.05b$ ./web.pl
MINE.pm did not return a true value at ./web.pl line 6.
BEGIN failed--compilation aborted at ./web.pl line 6 (#1)
(F) A required (or used) file must return a true value to
indicate that
it compiled correctly and ran its initialization code
correctly. It's
traditional to end such a file with a "1;", though any true
value would
do. See perlfunc/require.
Uncaught exception from user code:
MINE.pm did not return a true value at ./web.pl line 6.
BEGIN failed--compilation aborted at ./web.pl line 6.
--
Gary Schenk
remove "fuzz" to reply
------------------------------
Date: Thu, 02 Dec 2004 00:49:34 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: First attempt at a module fails
Message-Id: <pan.2004.12.02.05.49.30.612940@fastmail.us>
On Thu, 02 Dec 2004 05:26:02 +0000, Gary Schenk wrote:
<...>
> #####################################
> Here is the module MINE.pm:
>
> #####################################
> #!/usr/bin/perl
>
> package HTML;
Change the above line to ....
package MINE;
This construct isn't any different than some other languages (like Java;
the compiler will complain if the class name and the file name are
different).
> sub start_document
> {
> print "Enter the title of your webpage: "; chomp( my $title =
> <STDIN> );
> my $start_statement =
> "<html><head><title>$title</title></head><body>\n";
> return $start_statement;
> }
> }
> sub create_paragraph
> {
> print "Enter a string for a paragraph: "; chomp( my $string =
> <STDIN> );
> my $para_statement = "<p>$string</p>"; return $para_statement;
> }
> }
> }
> sub end_document
> {
> my $end_statement = "</body></html>\n"; return $end_statment;
> }
#you need this!
1;
> ########################################
> Here is the error:
>
> -bash-2.05b$ ./web.pl
> MINE.pm did not return a true value at ./web.pl line 6.
> BEGIN failed--compilation aborted at ./web.pl line 6 (#1)
> (F) A required (or used) file must return a true value to
> indicate that
> it compiled correctly and ran its initialization code
> correctly. It's
> traditional to end such a file with a "1;", though any true
> value would
> do. See perlfunc/require.
>
> Uncaught exception from user code:
> MINE.pm did not return a true value at ./web.pl line 6.
> BEGIN failed--compilation aborted at ./web.pl line 6.
I'm not going to comment further on this code. The comments I made should
get you started. However, you really should read perlboot and perltoot.
HTH
Jim
------------------------------
Date: Thu, 02 Dec 2004 06:33:38 GMT
From: Gary Schenk <gwschenk@fuzz.socal.rr.com>
Subject: Re: First attempt at a module fails
Message-Id: <6Hyrd.4619$OS3.3870@twister.socal.rr.com>
James Willmore wrote:
> On Thu, 02 Dec 2004 05:26:02 +0000, Gary Schenk wrote:
>
> <...>
>> #####################################
>> Here is the module MINE.pm:
>>
>> #####################################
>> #!/usr/bin/perl
>>
>> package HTML;
>
> Change the above line to ....
>
> package MINE;
Yes, I did this. A typo while trying things just to try things.
Still the same error.
>
> This construct isn't any different than some other languages
> (like Java; the compiler will complain if the class name and
> the file name are different).
>
>> sub start_document
>> {
>> print "Enter the title of your webpage: "; chomp( my
>> $title = <STDIN> );
>> my $start_statement =
>> "<html><head><title>$title</title></head><body>\n";
>> return $start_statement;
>> }
>> }
>> sub create_paragraph
>> {
>> print "Enter a string for a paragraph: "; chomp( my
>> $string = <STDIN> );
>> my $para_statement = "<p>$string</p>"; return
>> $para_statement;
>> }
>> }
>> }
>> sub end_document
>> {
>> my $end_statement = "</body></html>\n"; return
>> $end_statment;
>> }
>
> #you need this!
> 1;
This makes no difference. My returns are valid, from the examples
I've seen, so 1; shouldn't be necessary should it?
Thanks, Jim. Every comment helps!
--
Gary Schenk
remove "fuzz" to reply
------------------------------
Date: 1 Dec 2004 22:51:43 -0800
From: mccahanry@gmail.com
Subject: Re: First attempt at a module fails
Message-Id: <1101970302.996501.290000@z14g2000cwz.googlegroups.com>
Gary Schenk wrote:
> James Willmore wrote:
>
> > On Thu, 02 Dec 2004 05:26:02 +0000, Gary Schenk wrote:
> >
> > <...>
> >> #####################################
> >> Here is the module MINE.pm:
> >>
> >> #####################################
> >> #!/usr/bin/perl
> >>
> >> package HTML;
> >
> > Change the above line to ....
> >
> > package MINE;
>
> Yes, I did this. A typo while trying things just to try things.
>
> Still the same error.
>
> >
> > This construct isn't any different than some other languages
> > (like Java; the compiler will complain if the class name and
> > the file name are different).
> >
> >> sub start_document
> >> {
> >> print "Enter the title of your webpage: "; chomp( my
> >> $title = <STDIN> );
> >> my $start_statement =
> >> "<html><head><title>$title</title></head><body>\n";
> >> return $start_statement;
> >> }
> >> }
> >> sub create_paragraph
> >> {
> >> print "Enter a string for a paragraph: "; chomp( my
> >> $string = <STDIN> );
> >> my $para_statement = "<p>$string</p>"; return
> >> $para_statement;
> >> }
> >> }
> >> }
> >> sub end_document
> >> {
> >> my $end_statement = "</body></html>\n"; return
> >> $end_statment;
> >> }
> >
> > #you need this!
> > 1;
>
> This makes no difference. My returns are valid, from the examples
> I've seen, so 1; shouldn't be necessary should it?
>
> Thanks, Jim. Every comment helps!
>
> --
> Gary Schenk
> remove "fuzz" to reply
------------------------------
Date: Thu, 02 Dec 2004 01:57:20 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: First attempt at a module fails
Message-Id: <aKidnVZP06JMITPcRVn-1w@adelphia.com>
Gary Schenk wrote:
> James Willmore wrote:
>
>>#you need this!
>>1;
>
> This makes no difference.
Yes it will.
> My returns are valid
The return() functions in your subroutines are irrelevant. They return
values from your subs, when those subs are called. What James' addition
does is return a true value from the *module*.
If a module returns a false value, or none, the use() that loaded it
will think the module failed to load, and exit with the error message
you're seeing:
> MINE.pm did not return a true value at ./web.pl line 6.
PS: Did you at least *try* following James' advice before you decided he
was wrong? Why did you omit the rest of the warning - did you even read it?
> (F) A required (or used) file must return a true value to indicate that
> it compiled correctly and ran its initialization code correctly. It's
> traditional to end such a file with a "1;", though any true value would
> do. See perlfunc/require.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 1 Dec 2004 22:57:45 -0800
From: mccahanry@gmail.com
Subject: Re: First attempt at a module fails
Message-Id: <1101970665.542021.120900@f14g2000cwb.googlegroups.com>
Gary~~
The "1;" at the end of the file will not affect your subroutines at
all, it just tells Perl that it has successfully loaded the module.
When Perl does an include() or a related call, it wants a "true"
response, so we add 1; usually to the last line of code or thereabouts
to assure that it doesn't fail.
Ryan
------------------------------
Date: Thu, 02 Dec 2004 02:00:46 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: First attempt at a module fails
Message-Id: <aKidnVBP06ICIDPcRVn-1w@adelphia.com>
mccahanry@gmail.com wrote:
> When Perl does an include() or a related call
Perl has no include() function.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 2 Dec 2004 05:06:22 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: PAR problems Win32 (Can't Spawn, line 372) (solved)
Message-Id: <Xns95B2EB0C3D337castleamber@130.133.1.4>
wrote:
> John Bokma <postmaster@castleamber.com> writes:
>
>> ASPerl: v5.8.3 built for MSWin32-x86-multi-thread
>>
> <snip trying to install PAR 0.85>
>>
>> After many attempst, I kept getting 0.75, so I did the following:
>
> Had the same problem, but I had to remove PAR 0.75 with
> ppm> remove PAR-Dist
> ppm> remove PAR
Yes, I did the same, apologies for being incomplete :-D.
> first to get it to work.
> And then the following worked as expected.
Yes. I can recommend people to have a peek at PAR. It works very nice, if
you get it working :-D. Now I can give people some Perl stuff without
having them downloading and installing Perl (which they consider too
difficult).
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 1 Dec 2004 22:25:26 -0800
From: madhav_a_kelkar@hotmail.com
Subject: parent of an orphaned process-info about perl and OS version.
Message-Id: <338e571.0412012225.43846983@posting.google.com>
Hi,
I am using perl 5.8.0 compiled with threads. I am using Linux
Redhat 9.0. Is there anything else that you may need?
Regards,
Madhav.
------------------------------
Date: Thu, 02 Dec 2004 01:58:07 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: parent of an orphaned process-info about perl and OS version.
Message-Id: <aKidnVFP06JiITPcRVn-1w@adelphia.com>
madhav_a_kelkar@hotmail.com wrote:
> I am using perl 5.8.0 compiled with threads. I am using Linux
> Redhat 9.0. Is there anything else that you may need?
A question would be a good start.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 01 Dec 2004 22:01:29 -0800
From: Andy Glew <andy.glew@intel.com>
Subject: Perl classes NOT in separate files
Message-Id: <q5i3byputl2.fsf@plxc0250.pdx.intel.com>
Q: is the below the right way to
place Perl classes "inline", near to where
they are being used?
E.g. in file bar.pl
----------------------------------
use strict
print "Code befre interleaved package/classes\n";
{
package A;
sub new { bless {}; }
sub bar { print "A"; }
}
print "Code between interleaved package/classes\n";
{
package B;
sub new { bless {}; }
sub bar { print "B"; }
}
print "Code after interleaved package/classes\n";
A->bar();
B->bar();
my $a = A->new();
my $b = B->new();
$a->bar();
$b->bar();
----------------------------------
Putting the package statement inside the block curlies
looks wierd, but I guess it's the right way.
I know the basics of Perl classes:
A class is simply a package
A package is simply a file with "packge foo" at the top
(usually one that is on your include path)
Problem: I like to use programming patterns that
create lots of light-weight classes. Typically
they derive from some base class and override
one or two methods as close as possible to the
point of use.
E.g. in C++
int foo() {
class spec1 : public base {
public: int bar() { return 45; }
} s1;
return blif( s1 );
class spec2 : public base {
public: int bar() { return 67; }
} s2;
return blif( s2 );
}
I like this pattern because it puts the
classes right next to the point of use.
(Sometimes language restrictions make you move
them outside a function, but still they are
closer to the point of use than they would be
in a separate function.)
I.e. I use classes almost as a way of creating
lambda functions.
Q: is there any way to do this in Perl?
Placing these classes in separate files
makes them much less lightweight.
I've tried putting package more than once
in a file, with no luck. E.g. how do you
"use" multiple packages from the same file?
Perl seems to tightly couple classes and files.
---
Andy Glew
PREFERRED EMAIL: andy.glew@intel.com
Although I am trying to quit Outlook,
I fetchmail all of my Outlook/Exchange email
to UNIX to read
FALLBACK EMAIL: glew@ichips.intel.com
503-264-4119
Potential bias: employed now by Intel
past by AMD, Intel, Motorola, Gould ...
This post is personal, and is not the opinion of
any of my employers, past or present.
------------------------------
Date: Thu, 02 Dec 2004 11:21:44 +0100
From: Tom Regner <regner@dievision.de>
Subject: Re: Perl classes NOT in separate files
Message-Id: <41aeec68$0$14136$4d3ebbfe@news1.pop-hannover.net>
Hi Andy,
Andy Glew wrote:
> Q: is the below the right way to
> place Perl classes "inline", near to where
> they are being used?
First guess: remove the curlies and return to a surrounding package (main in
this case):
in file bar.pl
----------------------------------
use strict
print "Code befre interleaved package/classes\n";
package A;
sub new { bless {}; }
sub bar { print "A"; }
package B;
sub new { bless {}; }
sub bar { print "B"; }
package main; # or whatever package is correct here
A->bar();
B->bar();
my $a = A->new();
my $b = B->new();
$a->bar();
$b->bar();
----------------------------------
this compiles and prints
[1117]tom@margo ~ $ perl scratch/scratch.pl
Code befre interleaved package/classes
ABAB
[...]
>
> Q: is there any way to do this in Perl?
> Placing these classes in separate files
> makes them much less lightweight.
>
> I've tried putting package more than once
> in a file, with no luck. E.g. how do you
> "use" multiple packages from the same file?
> Perl seems to tightly couple classes and files.
You don't _use_ them with *use()*, you just *use* them ;-); I think your
only problem was putting the packages/classes in curlies and not returning
to the main-package (or superclass-package).
BTW, I like this approach for small _lambda_-Classes :)
hth,
Tom
------------------------------
Date: 2 Dec 2004 10:46:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl classes NOT in separate files
Message-Id: <comrpg$a5f$1@mamenchi.zrz.TU-Berlin.DE>
Andy Glew <andy.glew@intel.com> wrote in comp.lang.perl.misc:
> Q: is the below the right way to
> place Perl classes "inline", near to where
> they are being used?
>
> E.g. in file bar.pl
> ----------------------------------
> use strict
> print "Code befre interleaved package/classes\n";
> {
> package A;
> sub new { bless {}; }
> sub bar { print "A"; }
> }
> print "Code between interleaved package/classes\n";
> {
> package B;
> sub new { bless {}; }
> sub bar { print "B"; }
> }
> print "Code after interleaved package/classes\n";
> A->bar();
> B->bar();
> my $a = A->new();
> my $b = B->new();
> $a->bar();
> $b->bar();
> ----------------------------------
>
> Putting the package statement inside the block curlies
> looks wierd, but I guess it's the right way.
It's fine. If there are run-time actions in the class definition,
you may even want to make the bare block a BEGIN block.
[snip]
> I.e. I use classes almost as a way of creating
> lambda functions.
>
> Q: is there any way to do this in Perl?
> Placing these classes in separate files
> makes them much less lightweight.
>
> I've tried putting package more than once
> in a file, with no luck. E.g. how do you
What's the problem? "No luck" is right there with "doesn't work".
Be specific.
> "use" multiple packages from the same file?
> Perl seems to tightly couple classes and files.
The coupling is between *modules* and file names, and it pertains
only to exportation. Perl decides which ->import method to
(try to) call by looking at the package in the use() statement.
That one corresponds to the file name.
For non-exporting packages, as are classes, the difference is
irrelevant. You can have as many of them in a file as you want.
Anno
------------------------------
Date: Thu, 02 Dec 2004 11:53:15 +0100
From: Tom Regner <regner@dievision.de>
Subject: Re: Perl classes NOT in separate files
Message-Id: <41aef3cb$0$14136$4d3ebbfe@news1.pop-hannover.net>
reading Anno Siegels Post (<comrpg$a5f$1@mamenchi.zrz.TU-Berlin.DE>), I
realized that the original code already worked as expected, I just assumed
a problem -- silly me.
So I wish I could 'unwrite' most of my original answer :)
Tom Regner wrote:
[lots of silly things]
> You don't _use_ them with *use()*, you just *use* them ;-);
[...]
>
> BTW, I like this approach for small _lambda_-Classes :)
>
> hth,
> Tom
:-)
kind regards,
Tom
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7474
***************************************