[29029] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 273 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 27 21:09:52 2007

Date: Tue, 27 Mar 2007 18:09:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 27 Mar 2007     Volume: 11 Number: 273

Today's topics:
    Re: any quick and dirty code out there <tadmc@augustmail.com>
        Beginning OO help <nomail@sorry.com>
    Re: Beginning OO help <tadmc@augustmail.com>
    Re: Event Handling? <spamtrap@dot-app.org>
    Re: Event Handling? <tadmc@augustmail.com>
        how to list all loaded modules of a perl program <fei.liu@gmail.com>
    Re: how to list all loaded modules of a perl program usenet@DavidFilmer.com
    Re: how to list all loaded modules of a perl program <hjp-usenet2@hjp.at>
    Re: how to list all loaded modules of a perl program <fei.liu@gmail.com>
    Re: how to list all loaded modules of a perl program <spamtrap@dot-app.org>
    Re: parsing a tab delimited or CSV, but keep the delimi <pats@acm.org>
    Re: parsing a tab delimited or CSV, but keep the delimi <tadmc@augustmail.com>
        prototypes - use or not? <dcbecker@nospam-alcatel-lucent.com>
    Re: prototypes - use or not? <uri@stemsystems.com>
    Re: prototypes - use or not? <spamtrap@dot-app.org>
    Re: prototypes - use or not? <someone@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Mar 2007 16:57:42 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: any quick and dirty code out there
Message-Id: <slrnf0j4qm.jpa.tadmc@tadmc30.august.net>

Mr.G (@¿@) <goodm2@netzero.net> wrote:

> Now what I need is a place where I can get some quick and dirty
> cgi/peal code


Then post to the peal newsgroup.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 27 Mar 2007 13:14:20 -0800
From: Arvin Portlock <nomail@sorry.com>
Subject: Beginning OO help
Message-Id: <eubtv1$1j6f$1@agate.berkeley.edu>

I'm creating my very first object oriented module. I've read about
objects in so many perl books and online tutorials, and yet I still
can't get the hang of it. It's very frustrating. I've started by
designing a very simple class that has similar functionality to
what I eventually want to come up with, but not nearly as complex.
Just to get the hang of the basics before I get more complicated.
The class encapsulates an XML file. It has two attributes: the
file size and a linked list of the element names in the order they
are encountered in the file. Use it like this:

use Pete::MyFirstClass;

my $xmldoc = new Pete::MyFirstClass ('filename.xml');

print "The size of the document is ", $xmldoc->size, "\n";
print "Here is a list of the elements in the document:\n";

my $element = $xmldoc->elements;
while ($element) {
    print $element->{name}, "\n";
    $element = $element->{next};
}

__END__

Question 1: How do I turn {name} and {next} into accessor methods
rather than raw hash values?

Here's what I have so far:

package Pete::MyFirstClass;
require Exporter;
@ISA = qw(Exporter);
use strict 'vars';

sub new {
    my ($self, $file) = @_;
    my $size = -s $file;
    my $elements = {};
    my $last_element;
    open (FILE, $file);
    while (my $line = <FILE>) {
       while ($line =~ /<([a-z0-9]+)[^<>]*>/g) {
          my $name = $1;
          my $tag = {};
          $tag->{name} = $name;
          if ($elements) {
             $last_element->{next} = $tag;
             $last_element = $tag;
          } else {
             $elements = $tag;
             $last_element = $tag;
          }
       }
    }
    close (FILE);
    return bless [$size, $elements];
}

sub size { return $_[0]->[0]; }
sub root { return $_[0]->[1]; }

__END__

## I'm guessing I'll need to create a new Element class with methods
## "next" and "name"? But I can't seem to get it to work right

package Elements;

sub new {
    my $self = shift;
}

sub name {};
sub next {};



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

Date: Tue, 27 Mar 2007 17:20:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Beginning OO help
Message-Id: <slrnf0j662.jpa.tadmc@tadmc30.august.net>


[ Please do not send steach Cc's. It is rude.
  It is profoundly rude to do so when not using a real email address.
  Please do not do that again.
]


Arvin Portlock <nomail@sorry.com> wrote:
> I'm creating my very first object oriented module. I've read about
> objects in so many perl books 


Some books are good, some are not so good.

Which books have you tried?


> and online tutorials, 


The overwhelming majority of those are not good.


> and yet I still
> can't get the hang of it. 


Have you tried the tutorials that come with Perl itself?

   perldoc -q object

       Where can I learn about objectâ€oriented Perl programming?



>     open (FILE, $file);


You should always, yes *always*, check the return value from open():

    open(FILE, $file) or die "could not open '$file'  $!";


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 27 Mar 2007 16:44:25 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Event Handling?
Message-Id: <m2r6ra1knq.fsf@local.wv-www.com>

"Paul Lalli" <mritty@gmail.com> writes:

> If your question didn't get
> any responses, it's because you asked a poor question.

Maybe... Warnock applies. :-)

    <http://en.wikipedia.org/wiki/Warnock%27s_Dilemma>

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Tue, 27 Mar 2007 16:54:13 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Event Handling?
Message-Id: <slrnf0j4k5.jpa.tadmc@tadmc30.august.net>

zm5 <ryanarossi@gmail.com> wrote:
> On Mar 26, 2:36 pm, "zm5" <ryanaro...@gmail.com> wrote:
>> Could someone give me a link to a tutorial on event handling in perl?
>> I have not been able to find anything, it seems what I always find
>> when searching for event handling in perl is signal handling. 


When I googled "perl event handling" and followed the 1st 5 links,
I found none of them were related to signal handling.

How are you searching?


>> Are
>> these two things one in the same?


Signal handling is event handling, but event handling is not (only)
signal handling.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 27 Mar 2007 13:44:27 -0700
From: "Fei Liu" <fei.liu@gmail.com>
Subject: how to list all loaded modules of a perl program
Message-Id: <1175028267.609452.58160@y66g2000hsf.googlegroups.com>

Hi group, is it possible to list all loaded modules of a perl program?
For example, the perl application could have a very complicated
hierarchy of module structure where each module load different modules
on their own:

i.e
package main
use A;
use C;

package A
use B;

package C
use D;

package B
use BA;
use BB;

package D;
use DA;
use DB;
use DC;

package DA
use DAA;
use DAB;

etc, etc.

Now is it possible within the main program to list all the preloaded
modules via use statement? It's possible to do this by using a parser
to recursively parse through modules with a predefined level, but
idealy a in program complete list could be better.

Please let me know if there is an existing solution for this problem,
thanks!

Fei



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

Date: 27 Mar 2007 13:22:26 -0700
From: usenet@DavidFilmer.com
Subject: Re: how to list all loaded modules of a perl program
Message-Id: <1175026946.725251.10180@l77g2000hsb.googlegroups.com>

On Mar 27, 12:59 pm, "Fei Liu" <fei....@gmail.com> wrote:
> Hi group, is it possible to list all loaded modules of a perl program?

At any time in a program you may print the contents of %INC, which
will tell you what modules are loaded.

If you want to know every module ever loaded, use an end block, such
as:

END {
   print Dumper \%INC;
}


If you wish to know how much time your program spent inside of each
method of each module:

perl -d:Profile whatever.pl




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

Date: Tue, 27 Mar 2007 22:18:45 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: how to list all loaded modules of a perl program
Message-Id: <slrnf0iv15.etp.hjp-usenet2@yoyo.hjp.at>

On 2007-03-27 19:59, Fei Liu <fei.liu@gmail.com> wrote:
> Hi group, is it possible to list all loaded modules of a perl program?

%INC

	hp

-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


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

Date: 27 Mar 2007 13:46:34 -0700
From: "Fei Liu" <fei.liu@gmail.com>
Subject: Re: how to list all loaded modules of a perl program
Message-Id: <1175028394.269350.113940@d57g2000hsg.googlegroups.com>

My apologies for the double posts. Google groups is choking...



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

Date: Tue, 27 Mar 2007 16:49:12 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: how to list all loaded modules of a perl program
Message-Id: <m2mz1y1kfr.fsf@local.wv-www.com>

"Fei Liu" <fei.liu@gmail.com> writes:

> Hi group, is it possible to list all loaded modules of a perl program?

Have a look at %INC in 'perldoc perlvar'.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Tue, 27 Mar 2007 14:16:45 -0700
From: Patricia Shanahan <pats@acm.org>
Subject: Re: parsing a tab delimited or CSV, but keep the delimiter
Message-Id: <euc1jv$l4f$1@ihnp4.ucsd.edu>

Alex wrote:
> Lew wrote:
>> And given that the OP asked for a Java solution it is reasonable to assume 
>> that that was the space of the answer. /Of course/ I didn't think a Perl 
>> solution was intended in that context.
> 
> And why? The OP was crossposted to a Perl ng, which implies - unless
> stated otherwise - that a solution in either language is acceptable.
> Otherwise, why crosspost?

In this particular case, it was stated otherwise. From the base message
of the thread: "I am cross posting this in the Perl and Java groups
because, my implementation is in Java, but Perl users use regexp far
more frequently."

Patricia


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

Date: Tue, 27 Mar 2007 17:05:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: parsing a tab delimited or CSV, but keep the delimiter
Message-Id: <slrnf0j58j.jpa.tadmc@tadmc30.august.net>

["Followup-To:" header set to comp.lang.perl.misc.]
Patricia Shanahan <pats@acm.org> wrote:
> Alex wrote:
>> Lew wrote:
>>> And given that the OP asked for a Java solution it is reasonable to assume 
>>> that that was the space of the answer. /Of course/ I didn't think a Perl 
>>> solution was intended in that context.
>> 
>> And why? The OP was crossposted to a Perl ng, which implies - unless
>> stated otherwise - that a solution in either language is acceptable.
>> Otherwise, why crosspost?
>
> In this particular case, it was stated otherwise. From the base message
> of the thread: "I am cross posting this in the Perl and Java groups
> because, my implementation is in Java, but Perl users use regexp far
> more frequently."


I noted that in the OP and took the appropriate action some time later.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 27 Mar 2007 16:52:19 -0400
From: "Dan Becker" <dcbecker@nospam-alcatel-lucent.com>
Subject: prototypes - use or not?
Message-Id: <46098403$1@news.alcatel.com>

Perl Best Practices (Conway), section 9.10,  has a pretty clear statement 
that subroutine prototypes should not be used. Period. (It says that the 
disadvantages generally outweigh the limited advantages.) But it's still in 
the language. So I'm confused. Is this generally accepted advice? or should 
it be applied only in specific situations? or, generally speaking, avoided 
in specific situations?

Dan Becker




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

Date: Tue, 27 Mar 2007 16:00:01 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: prototypes - use or not?
Message-Id: <x7abxyo10u.fsf@mail.sysarch.com>

>>>>> "DB" == Dan Becker <dcbecker@nospam-alcatel-lucent.com> writes:

  DB> Perl Best Practices (Conway), section 9.10, has a pretty clear
  DB> statement that subroutine prototypes should not be
  DB> used. Period. (It says that the disadvantages generally outweigh
  DB> the limited advantages.) But it's still in the language. So I'm
  DB> confused. Is this generally accepted advice? or should it be
  DB> applied only in specific situations? or, generally speaking,
  DB> avoided in specific situations?

just because PBP doesn't like something doesn't mean it will be removed
from perl5. about the only think i know that has ever been removed was
pseudo-hashes and they were very bad and evil. prototypes have a few
real uses but almost none for the average perl hacker. so the point is
just what pbp says, don't use them unless you have a very good reason to
use them. if you can't figure that out, then you don't know enough to
use them. among other dumb things newbies do is use prototypes on
methods where they have no effect at all.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 27 Mar 2007 17:12:26 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: prototypes - use or not?
Message-Id: <m2fy7q1jd1.fsf@local.wv-www.com>

"Dan Becker" <dcbecker@nospam-alcatel-lucent.com> writes:

> Perl Best Practices (Conway), section 9.10,  has a pretty clear statement 
> that subroutine prototypes should not be used. Period. (It says that the 
> disadvantages generally outweigh the limited advantages.) But it's still in 
> the language. So I'm confused. Is this generally accepted advice?

If you need to ask - don't use them.

If you know what they do, and how you might apply them to make your life
easier in some specific situation - feel free.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Tue, 27 Mar 2007 22:19:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: prototypes - use or not?
Message-Id: <QLgOh.22113$__3.13028@edtnps90>

Dan Becker wrote:
> Perl Best Practices (Conway), section 9.10,  has a pretty clear statement 
> that subroutine prototypes should not be used. Period. (It says that the 
> disadvantages generally outweigh the limited advantages.) But it's still in 
> the language. So I'm confused. Is this generally accepted advice? or should 
> it be applied only in specific situations? or, generally speaking, avoided 
> in specific situations?

See also Tom Christiansen's article "Far More Than Everything You've Ever
Wanted to Know about Prototypes in Perl" at:

http://library.n0i.net/programming/perl/articles/fm_prototypes/



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

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 V11 Issue 273
**************************************


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