[29592] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 836 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 10 11:09:40 2007

Date: Mon, 10 Sep 2007 08:09:07 -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           Mon, 10 Sep 2007     Volume: 11 Number: 836

Today's topics:
        Array Question <amerar@iwc.net>
    Re: Array Question <benoit.lefebvre@gmail.com>
    Re: Array Question <mritty@gmail.com>
    Re: Array Question <mritty@gmail.com>
    Re: Array Question <amerar@iwc.net>
        CPAN failed to install XML::Parser module <Michael.Yxf@gmail.com>
    Re: CPAN failed to install XML::Parser module <spamtrap@dot-app.org>
    Re: CPAN failed to install XML::Parser module <Michael.Yxf@gmail.com>
    Re: debugging and flow control <alexxx.magni@gmail.com>
    Re: debugging and flow control <anno4000@radom.zrz.tu-berlin.de>
    Re: debugging and flow control <mritty@gmail.com>
    Re: Ensuring parent/child processes <jrpfinch@gmail.com>
    Re: Net::Sftp <sagar.gadge@gmail.com>
    Re: Sharing object between threads - howto? <zentara@highstream.net>
    Re: trying to export some utility methods, and struggli <bugbear@trim_papermule.co.uk_trim>
    Re: trying to export some utility methods, and struggli <bugbear@trim_papermule.co.uk_trim>
    Re: trying to export some utility methods, and struggli <spamtrap@dot-app.org>
    Re: trying to export some utility methods, and struggli <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: What is required for perl scripts to run correct wh <anno4000@radom.zrz.tu-berlin.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 10 Sep 2007 07:38:27 -0700
From:  "amerar@iwc.net" <amerar@iwc.net>
Subject: Array Question
Message-Id: <1189435107.638473.144060@57g2000hsv.googlegroups.com>


Hi,

I need to create an array.  Each element will have 1 row and 3
columns.  So, the array would look something like this:

$x[1] = 1,2,3
$x[2] = 4,5,6
$x[3] = 7,8,9

 Basically, I have 1 row and 3 columns.........how would I store the values,
and retrieve the values???

Thanks!



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

Date: Mon, 10 Sep 2007 07:48:02 -0700
From:  Benoit Lefebvre <benoit.lefebvre@gmail.com>
Subject: Re: Array Question
Message-Id: <1189435682.967075.255050@y42g2000hsy.googlegroups.com>

On Sep 10, 10:38 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> Hi,
>
> I need to create an array.  Each element will have 1 row and 3
> columns.  So, the array would look something like this:
>
> $x[1] = 1,2,3
> $x[2] = 4,5,6
> $x[3] = 7,8,9
>
>  Basically, I have 1 row and 3 columns.........how would I store the values,
> and retrieve the values???
>
> Thanks!

You can make an array of array

$x[1][1] = 1;
$x[1][2] = 2;
$x[1][3] = 3;
$x[2][1] = 4;
 ...

see:
http://www.unix.org.ua/orelly/perl/prog3/ch09_01.htm

--Ben



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

Date: Mon, 10 Sep 2007 07:51:27 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Array Question
Message-Id: <1189435887.686054.154230@50g2000hsm.googlegroups.com>

On Sep 10, 10:38 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> I need to create an array.  Each element will have 1 row and 3
> columns.  So, the array would look something like this:
>
> $x[1] = 1,2,3
> $x[2] = 4,5,6
> $x[3] = 7,8,9

my @x = ( [1, 2, 3], [4, 5, 6], [7, 8, 9] );

OR

my @x;
$x[0] = [ 1, 2, 3 ];
$x[1] = [ 4, 5, 6 ];
$x[2] = [ 7, 8, 9 ];

>  Basically, I have 1 row and 3 columns.........how would I store
> the values, and retrieve the values???

print "(0,2) = $x[0][2]\n";

You need to read up on creating multidimensional structures in Perl:

perldoc perlreftut
perldoc perllol

Paul Lalli



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

Date: Mon, 10 Sep 2007 07:53:41 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Array Question
Message-Id: <1189436021.479083.245740@19g2000hsx.googlegroups.com>

On Sep 10, 10:48 am, Benoit Lefebvre <benoit.lefeb...@gmail.com>
wrote:
> On Sep 10, 10:38 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> > I need to create an array.  Each element will have 1 row and 3
> > columns.  So, the array would look something like this:
>
> > $x[1] = 1,2,3
> > $x[2] = 4,5,6
> > $x[3] = 7,8,9
>
> >  Basically, I have 1 row and 3 columns.........how would I store
> > the values, and retrieve the values???

> You can make an array of array
>
> $x[1][1] = 1;
> $x[1][2] = 2;
> $x[1][3] = 3;
> $x[2][1] = 4;

You're sticking undefined values all over the place.  Arrays in Perl
start with 0, not 1.  You've made $x[0] undefined, as well as $x[1]
[0], $x[2][0], etc.

> see:<link to pirated material snipped.>

Please don't do that again.  Perl has free built-in documentation
available.  Reference that.  http://perldoc.perl.org.  Do not post
links to commercially available material that people have illegally
duplicated.

Paul Lalli



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

Date: Mon, 10 Sep 2007 07:55:24 -0700
From:  "amerar@iwc.net" <amerar@iwc.net>
Subject: Re: Array Question
Message-Id: <1189436124.265386.148240@d55g2000hsg.googlegroups.com>

On Sep 10, 9:51 am, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 10, 10:38 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
>
> > I need to create an array.  Each element will have 1 row and 3
> > columns.  So, the array would look something like this:
>
> > $x[1] = 1,2,3
> > $x[2] = 4,5,6
> > $x[3] = 7,8,9
>
> my @x = ( [1, 2, 3], [4, 5, 6], [7, 8, 9] );
>
> OR
>
> my @x;
> $x[0] = [ 1, 2, 3 ];
> $x[1] = [ 4, 5, 6 ];
> $x[2] = [ 7, 8, 9 ];
>
> >  Basically, I have 1 row and 3 columns.........how would I store
> > the values, and retrieve the values???
>
> print "(0,2) = $x[0][2]\n";
>
> You need to read up on creating multidimensional structures in Perl:
>
> perldoc perlreftut
> perldoc perllol
>
> Paul Lalli

So, if I would want to use MySQL and pull some values from a table and
store them in an array, could I use a method like this:

while (($customer_id, $report_name, $report_string) $sel-
>fetchrow_array()) {
   $y = 0;
   $info[$x][$y] = $customer_id;
   $y++
   $info[$x][$y] = $report_name;
   $y++
   $info[$x][$y] = $report_string;
   $x++;
}

And, if I wanted to use a foreach loop to process the array, can I do
something like this:

foreach $info (@info) {
   $customer_id = $info[0];
   $rpt_name = $info[1];
   $rpt_str  = $info[2];
   .
   .
   .
}




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

Date: Mon, 10 Sep 2007 08:36:06 -0000
From:  Michael Yang <Michael.Yxf@gmail.com>
Subject: CPAN failed to install XML::Parser module
Message-Id: <1189413366.524778.302270@22g2000hsm.googlegroups.com>

I am working on Debian GNU/Linux etch and have installed perl packages
5.8.8 with CPAN configured.

In the cpan shell, I was to install the module of XML::Parser, but it
always failed with many error message returned. I don't know whether
if it is the issue of source on the mirror server, OR is the tool
issue on my box.  The error msg is quite long that I can only paste
the tail part of it.

Could anybody help look at this?
It's really appreciated of your help

error:
Expat.c: In function 'XS_XML__Parser__Expat_UnsetAllHandlers':
Expat.c:2609: error: 'XML_Parser' undeclared (first use in this
function)
Expat.c:2609: error: expected ';' before 'parser'
Expat.xs:2144: error: 'parser' undeclared (first use in this function)
Expat.xs:2147: error: 'CallbackVector' has no member named 'ns'
Expat.xs:2148: error: 'CallbackVector' has no member named 'p'
Expat.xs:2149: error: 'XML_StartNamespaceDeclHandler' undeclared
(first use in this function)
Expat.xs:2149: error: expected ')' before numeric constant
Expat.xs:2154: error: 'XML_StartElementHandler' undeclared (first use
in this function)
Expat.xs:2154: error: expected ')' before numeric constant
Expat.xs:2158: error: 'XML_UnknownEncodingHandler' undeclared (first
use in this function)
Expat.xs:2158: error: expected ')' before numeric constant
Expat.c: In function 'XS_XML__Parser__Expat_ElementIndex':
Expat.c:2642: error: 'XML_Parser' undeclared (first use in this
function)
Expat.c:2642: error: expected ';' before 'parser'
Expat.xs:2167: error: 'parser' undeclared (first use in this function)
Expat.xs:2168: error: 'CallbackVector' has no member named
'st_serial_stack'
Expat.xs:2168: error: 'CallbackVector' has no member named
'st_serial_stackptr'
Expat.c: In function 'XS_XML__Parser__Expat_SkipUntil':
Expat.c:2664: error: 'XML_Parser' undeclared (first use in this
function)
Expat.c:2664: error: expected ';' before 'parser'
Expat.xs:2179: error: 'parser' undeclared (first use in this function)
Expat.xs:2180: error: 'CallbackVector' has no member named 'st_serial'
Expat.xs:2182: error: 'CallbackVector' has no member named
'skip_until'
Expat.c: In function 'XS_XML__Parser__Expat_Do_External_Parse':
Expat.c:2687: error: 'XML_Parser' undeclared (first use in this
function)
Expat.c:2687: error: expected ';' before 'parser'
Expat.xs:2194: error: 'parser' undeclared (first use in this function)
make[1]: *** [Expat.o] Error 1
make[1]: Leaving directory `/home/michael/.cpan/build/XML-Parser-2.34/
Expat'
make: *** [subdirs] Error 2
  /usr/bin/make  -- NOT OK
Running make test
  Can't test without successful make

cpan>



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

Date: Mon, 10 Sep 2007 05:53:34 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: CPAN failed to install XML::Parser module
Message-Id: <m2odgag82p.fsf@dot-app.org>

Michael Yang <Michael.Yxf@gmail.com> writes:

> I am working on Debian GNU/Linux etch and have installed perl packages
> 5.8.8 with CPAN configured.
>
> In the cpan shell, I was to install the module of XML::Parser, but it
> always failed with many error message returned. I don't know whether
> if it is the issue of source on the mirror server, OR is the tool
> issue on my box.  The error msg is quite long that I can only paste
> the tail part of it.

Sorry, but that's backwards.

The tail of the build log is usually not very interesting - 99 times out of
100, a single missing header file will trigger hundreds of other errors
further down. What's far more useful is to scroll to the very top of the
build log, to see which missing header caused all this.

> Could anybody help look at this?
> It's really appreciated of your help
>
> error:
> Expat.c: In function 'XS_XML__Parser__Expat_UnsetAllHandlers':
> Expat.c:2609: error: 'XML_Parser' undeclared (first use in this
> function)
> Expat.c:2609: error: expected ';' before 'parser'
> Expat.xs:2144: error: 'parser' undeclared (first use in this function)

From the symbols, I'm guessing that expat.h wasn't found. Have you installed
the expat and expat-dev packages?

sherm--

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


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

Date: Mon, 10 Sep 2007 10:29:11 -0000
From:  Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: CPAN failed to install XML::Parser module
Message-Id: <1189420151.993682.167590@k79g2000hse.googlegroups.com>

On Sep 10, 5:53 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> Michael Yang <Michael....@gmail.com> writes:
> > I am working on Debian GNU/Linux etch and have installed perl packages
> > 5.8.8 with CPAN configured.
>
> > In the cpan shell, I was to install the module of XML::Parser, but it
> > always failed with many error message returned. I don't know whether
> > if it is the issue of source on the mirror server, OR is the tool
> > issue on my box.  The error msg is quite long that I can only paste
> > the tail part of it.
>
> Sorry, but that's backwards.
>
> The tail of the build log is usually not very interesting - 99 times out of
> 100, a single missing header file will trigger hundreds of other errors
> further down. What's far more useful is to scroll to the very top of the
> build log, to see which missing header caused all this.
>
> > Could anybody help look at this?
> > It's really appreciated of your help
>
> > error:
> > Expat.c: In function 'XS_XML__Parser__Expat_UnsetAllHandlers':
> > Expat.c:2609: error: 'XML_Parser' undeclared (first use in this
> > function)
> > Expat.c:2609: error: expected ';' before 'parser'
> > Expat.xs:2144: error: 'parser' undeclared (first use in this function)
>
> From the symbols, I'm guessing that expat.h wasn't found. Have you installed
> the expat and expat-dev packages?
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net

Thanks so much Sherm, it works after I installed the libexpat-dev.
I really appreciated of it.
Michael.



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

Date: Mon, 10 Sep 2007 00:54:04 -0700
From:  "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: Re: debugging and flow control
Message-Id: <1189410844.789860.183860@w3g2000hsg.googlegroups.com>

On 8 Set, 00:36, Anno Siegel <anno4...@radom.zrz.tu-berlin.de> wrote:
> On 2007-09-07 13:33:05 +0200, "alexxx.ma...@gmail.com"
> <alexxx.ma...@gmail.com> said:
>
> > Hi all, I need some advice:
>
> > in the past, when writing programs I often used, to help me in
> > debugging, the following style:
>
> > my $debuglevel=1;
> > ....
> > print("var value is $a\n") if ($debuglevel>0);
> > ....
> > print(LOGFILE "array values are @x\n") if ($debuglevel>2);
> > ...
>
> > you get the idea.
> > Now I'm working on a project very computational-intensive, and I'm
> > worried about the many lines "if ($debuglevel...)" to be evaluated.
>
> Especially if the program is computational-intensive, it is unlikely
> that skipping debug statements is going to make a noticeable difference.
>
> > I was wandering: if $debuglevel was a constant, not a variable, it is
> > possible that the program, when launched, evaluates those lines from
> > the beginning? In this case I should not worry about later evaluation.
>
> If needed, that can be done using the constant pragma.  The technique
> is described in "perldoc constant", so I don't have to repeat it here.
>
> Anno


Maybe I could be clearer: yes, I was talking about "use constant...".
Do you know if this:

use constant DEBUGON=>1;
if (DEBUGON>0) {...}

is evaluated, the if eliminated and the block {...} accepted, prior to
the global run?


thanks!

Alessandro



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

Date: Mon, 10 Sep 2007 13:28:29 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: debugging and flow control
Message-Id: <5kko2tF48g1iU1@mid.dfncis.de>

On 2007-09-10 09:54:04 +0200, "alexxx.magni@gmail.com" 
<alexxx.magni@gmail.com> said:

> On 8 Set, 00:36, Anno Siegel <anno4...@radom.zrz.tu-berlin.de> wrote:
>> On 2007-09-07 13:33:05 +0200, "alexxx.ma...@gmail.com"
>> <alexxx.ma...@gmail.com> said:
>> 
>>> Hi all, I need some advice:
>> 
>>> in the past, when writing programs I often used, to help me in
>>> debugging, the following style:
>> 
>>> my $debuglevel=1;
>>> ....
>>> print("var value is $a\n") if ($debuglevel>0);
>>> ....
>>> print(LOGFILE "array values are @x\n") if ($debuglevel>2);
>>> ...
>> 
>>> you get the idea.
>>> Now I'm working on a project very computational-intensive, and I'm
>>> worried about the many lines "if ($debuglevel...)" to be evaluated.
>> 
>> Especially if the program is computational-intensive, it is unlikely
>> that skipping debug statements is going to make a noticeable difference.
>> 
>>> I was wandering: if $debuglevel was a constant, not a variable, it is
>>> possible that the program, when launched, evaluates those lines from
>>> the beginning? In this case I should not worry about later evaluation.
>> 
>> If needed, that can be done using the constant pragma.  The technique
                                                            ^^^^^^^^^^^^^
>> is described in "perldoc constant", so I don't have to repeat it here.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> Maybe I could be clearer: yes, I was talking about "use constant...".
> Do you know if this:
> 
> use constant DEBUGON=>1;
> if (DEBUGON>0) {...}
> 
> is evaluated, the if eliminated and the block {...} accepted, prior to
> the global run?

There are at least two ways you could find out yourself.  Take a look at
"perldoc constant" as recommended in my last reply.  Or use the O::Deparse
function to see directly what the compiler makes of your statement.

Anno



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

Date: Mon, 10 Sep 2007 07:29:57 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: debugging and flow control
Message-Id: <1189434597.607192.326430@d55g2000hsg.googlegroups.com>

On Sep 10, 7:28 am, Anno Siegel <anno4...@radom.zrz.tu-berlin.de>
wrote:
> On 2007-09-10 09:54:04 +0200, "alexxx.ma...@gmail.com"
> <alexxx.ma...@gmail.com> said:
>
> > Do you know if this:
>
> > use constant DEBUGON=>1;
> > if (DEBUGON>0) {...}
>
> > is evaluated, the if eliminated and the block {...} accepted,
> > prior to the global run?
>
> There are at least two ways you could find out yourself.  Take a
> look at "perldoc constant" as recommended in my last reply.  Or
> use the O::Deparse function to see directly what the compiler
> makes of your statement.

Which is, of course, exactly what I did for the OP in the first reply
to this thread three days ago. . .

Paul Lalli



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

Date: Mon, 10 Sep 2007 02:06:38 -0700
From:  jrpfinch <jrpfinch@gmail.com>
Subject: Re: Ensuring parent/child processes
Message-Id: <1189415198.098144.158260@k79g2000hse.googlegroups.com>

Thanks very much for everyone's help.  My final solution was based on
the script in my previous message.

I replaced the kill 9's with kill -15, $$ and took the require/import
PAR out of the eval block and put it at the top of the script

Jon




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

Date: Mon, 10 Sep 2007 11:48:30 -0000
From:  sagar gadge <sagar.gadge@gmail.com>
Subject: Re: Net::Sftp
Message-Id: <1189424910.286187.51540@r29g2000hsg.googlegroups.com>

On Sep 8, 1:29 am, gil <gil.kov...@gmail.com> wrote:
> On Sep 7, 7:52 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:> gil <gil.kov...@gmail.com> wrote in news:1189182946.304387.5760
> > @r34g2000hsd.googlegroups.com:
>
> > > Hi,
>
> > > I'm trying to use Net::Sftp on windows XP,
> > > I already downloaded Net::SSH::W32Perl and Net::Sftp.
>
> > > the thing is - when trying to use, I get this error message yelling
> > > about the use of "getpid()" on SSH/Perl.pm, when disabling the line -
> > > some local variable $home isn't initialized.
>
> > Please read the posting guidelines and show a small example.
>
>  I.E:
>
>   use Net::SFTP;
>   my $sftp = Net::SFTP->new($host);
>
>
>
> > Does setting $ENV{HOME} to something meaningful help?
>
> Haven't tried it yet, I don't know which value should I set in
> $ENV{HOME}.
>
>
>
>
>
> > > does some one know how can I make theses two fellows (SSH, Sftp) work
> > > harmonically on windows?
>
> > ITYM "harmoniously"
>
> >http://en.wikipedia.org/wiki/Harmonic
>
> > Sinan
>
> > --
> > A. Sinan Unur <1...@llenroc.ude.invalid>
> > (remove .invalid and reverse each component for email address)
> > clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>- Hide quoted text -
>
> - Show quoted text -

Why not include - "use Env;" in your program ??? It will pick the
value correctly..



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

Date: Mon, 10 Sep 2007 12:19:49 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Sharing object between threads - howto?
Message-Id: <6adae3pj9b4lhgeel8n00sajohfudcvcvh@4ax.com>

On Sat, 08 Sep 2007 13:47:14 +0200, Lejf Diecks
<bastard_operator@gmx.li> wrote:

>Hi,
>
>is it possible to share an object between the main program and a thread?

See: 
http://perlmonks.org?node_id=637089

It's uncharted territory, and you might run into portability problems
even if you get it to work on your machine.

zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Mon, 10 Sep 2007 09:52:21 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: trying to export some utility methods, and struggling
Message-Id: <13ea1e67c791r0d@corp.supernews.com>

Sherm Pendley wrote:
> bugbear <bugbear@trim_papermule.co.uk_trim> writes:
> 
>> (reponse at bottom)
> 
> That's where we expect it to be - no need to point it out.
> 
>> Mumia W. wrote:
>>
>>> # Let's say we're back in the main program now.
>>>
>>> WidgetBasher->utility_function();
>>> WidgetManip->utility_function();
>>> WidgetDoer->utility_function();
>> Yep, that works, but that's almost exactly what I'm trying to avoid.
>> I don't want to be forced to have an instance of a class
>> just to call a utility;
> 
> Good thing that calling a class method doesn't force that.
> 
>> I am aware of the various uses of OO code (I've spent 15 years
>> on large projects in both Java and C++)
> 
> And in all that time you've never heard of class methods?
> 
> Astonishing.

It would be if true, but I *have* heard of class methods.

I am aware of the possibility of doing
BasherUtility::utility_function();

I am also aware of Perl's helpful
facility (called "Exporter", you may have heard
of it) that makes calling externally defined
function more convenient, and it is
this that I wish to exploit.

    BugBear


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

Date: Mon, 10 Sep 2007 10:10:14 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: trying to export some utility methods, and struggling
Message-Id: <13ea2fng159k512@corp.supernews.com>

Since I'm not making myself clear (enough), here's
a fairly disembodied version of what I would like to achieve.

Here's my trivial package:

#!/usr/bin/perl

package U;
use base 'Exporter';
use vars qw(@EXPORT);

@EXPORT = qw($glob1 util1 util2);

our $glob1;

sub util1 {
}

sub util2 {
}

sub new {
     my ($class, $name) = @_;
     my $self = bless {}, $class;
     return $self;
}

package X;

sub new {
     my ($class, $name) = @_;
     my $self = bless {}, $class;
     return $self;
}

sub xmethod {
     util1();
     print $glob1;
}

1;

Here's my trivial use of the package:

#!/usr/bin/perl
use strict;
use warnings;

use U;

util1();

my $u = U->new();

my $x = X->new();

$x->xmethod();

This does *NOT* run successfully; the use of util1() in xmethod gives
Undefined subroutine &X::util1 called at U.pm line 32. Everything
else is as I desire it.

What I would like is to avoid this error, whilst keeping
other properties of the module (especially single file, and no inheritence from
U to X)

I feel it should just be some lines involving EXPORT and IMPORT and BEGIN,
and possibly putting the utils into their own package, but I just can't get it.

    BugBear (who has hopefully made himself a little clearer)


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

Date: Mon, 10 Sep 2007 06:17:47 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: trying to export some utility methods, and struggling
Message-Id: <m2k5qyg6yc.fsf@dot-app.org>

bugbear <bugbear@trim_papermule.co.uk_trim> writes:

> Sherm Pendley wrote:
>> bugbear <bugbear@trim_papermule.co.uk_trim> writes:
>>
>>> (reponse at bottom)
>>
>> That's where we expect it to be - no need to point it out.
>>
>>> Mumia W. wrote:
>>>
>>>> # Let's say we're back in the main program now.
>>>>
>>>> WidgetBasher->utility_function();
>>>> WidgetManip->utility_function();
>>>> WidgetDoer->utility_function();
>>> Yep, that works, but that's almost exactly what I'm trying to avoid.
>>> I don't want to be forced to have an instance of a class
>>> just to call a utility;
>>
>> Good thing that calling a class method doesn't force that.
>>
>>> I am aware of the various uses of OO code (I've spent 15 years
>>> on large projects in both Java and C++)
>>
>> And in all that time you've never heard of class methods?
>>
>> Astonishing.
>
> It would be if true, but I *have* heard of class methods.

Then why are you making bogus claims about being "forced to have an instance
of a class just to call a utility?"

> I am aware of the possibility of doing
> BasherUtility::utility_function();

That's not a class method, it's a plain non-OO function in a package.

Between thinking you need to instantiate an object to call a class method,
and not knowing the difference between a method and a function, it appears
from where I'm sitting that you're far less aware than you claim to be, at
least where Perl's OO is concerned.

> I am also aware of Perl's helpful
> facility (called "Exporter", you may have heard
> of it)

Of course I've heard of it, and used it - might I remind you, I'm not the
one asking for help here.

> that makes calling externally defined
> function more convenient, and it is
> this that I wish to exploit.

OK then. Have a look at "perldoc Exporter" - there's an example of how to
use it at the very top:

    package YourModule;
    require Exporter;
    @ISA = qw(Exporter);
    @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request

Then, users of your module would say:

    use YourModule qw(munge frobnicate);

What part of this isn't working for you?

sherm--

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


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

Date: Mon, 10 Sep 2007 08:04:51 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: trying to export some utility methods, and struggling
Message-Id: <13eagr7emqofde1@corp.supernews.com>

On 09/10/2007 04:10 AM, bugbear wrote:
> Since I'm not making myself clear (enough), here's 
> a fairly disembodied version of what I would like to achieve.
> 
> Here's my trivial package:
> 
> #!/usr/bin/perl
> 
> package U;
> use base 'Exporter';
> use vars qw(@EXPORT);
> 
> @EXPORT = qw($glob1 util1 util2);
> 
> our $glob1;
> 
> sub util1 {
> }
> 
> sub util2 {
> }
> 
> sub new {
>     my ($class, $name) = @_;
>     my $self = bless {}, $class;
>     return $self;
> }
> 
> package X;
> 

What happens when you add this line under "package X" ?

U->import;


> sub new {
>     my ($class, $name) = @_;
>     my $self = bless {}, $class;
>     return $self;
> }
> 
> sub xmethod {
>     util1();
>     print $glob1;
> }
> 
> 1;
> [...]
> 
>    BugBear (who has hopefully made himself a little clearer)

Yes, much clearer.


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

Date: Mon, 10 Sep 2007 13:58:51 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: What is required for perl scripts to run correct when launched from rc scripts on HPUX 11?
Message-Id: <5kkprrF4a7smU1@mid.dfncis.de>

On 2007-09-10 05:10:45 +0200, deanjones7@gmail.com said:

> Anno Siegel wrote:
>> On 2007-09-06 14:05:18 +0200, deanjones7@gmail.com said:
>> 
>>> Anno Siegel wrote:
>>>> On 2007-09-06 10:17:09 +0200, usenet@DavidFilmer.com said:
>>>> 
>>>>> On Sep 6, 1:06 am, deanjon...@gmail.com wrote:
>>>>>> the perl script fails without any errors when the system is booted.
>>>>> 
>>>>> That means NOTHING.  How do you know it fails?  How do you even know
>>>>> it runs?  Why would you think it should run on a reboot?
>>>> 
>>>> Well, the subject mentions "... launched from rc scripts" which I take
>>>> to mean it is called from one of the /etc/*.rc scripts (or however these
>>>> are organized in HPUX).
>>> 
>>> That's correct. There's a start/stop script in /sbin/init.d with the
>>> usual links to the rc? directories.
>> 
>> It would have been a good idea to mention that explicitly in the body of
>> your posting.  "Launched from rc" is not part of any standard terminology.
> 
> I would have expected any experience Unix person to know what an rc
> script is and the related terminology, but no matter.

Perl is not restricted to the Unix world.  A Perl expert is no automatically
an "experienced Unix person".

[...]

>>> to read input from the pipe. Should I be using STDIN explicitly
>>> instead?
>> 
>> I have no idea.  Post the code of the script, the actual call, and
>> describe in what stage of startup the call happens.
> 
> Its a bit difficult due to commercial obligations (contracts, etc. I'm
> sure you're aware of the issues).

You're on your own then.  We can't debug code we can't see.

> Anyway, if you must know, I took an existing perl script found here -
> http://www.peppler.org/downloads/scripts (Its the one called
> log_watcher.pl.)

Yes, we "must know" the code you are trying to run to diagnose it.

[...]

Anno



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

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


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