[23711] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5917 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 9 18:05:56 2003

Date: Tue, 9 Dec 2003 15:05:09 -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           Tue, 9 Dec 2003     Volume: 10 Number: 5917

Today's topics:
    Re: #!/usr/bin/perl <yanoff@STOP-SPAMMINGyahoo.com>
    Re: editing challenge: Perl vs. cfengine <tzz@lifelogs.com>
        How to run _init for all ancestor classes in diamond in (Amir Karger)
    Re: How to run _init for all ancestor classes in diamon <dmcbride@naboo.to.org.no.spam.for.me>
    Re: How to run _init for all ancestor classes in diamon <tassilo.parseval@rwth-aachen.de>
    Re: How to run _init for all ancestor classes in diamon <tassilo.parseval@rwth-aachen.de>
    Re: Idiom for array index that I'm foreach'ing over? <abigail@abigail.nl>
    Re: Multi-dimensional  Data Structures <richard@zync.co.uk>
    Re: Multi-dimensional  Data Structures <noreply@gunnar.cc>
    Re: Multi-dimensional  Data Structures <agbiotec@yahoo.com>
        Perl Installation Copied to Another Machine (bear)
    Re: Perl Installation Copied to Another Machine <joost@rot13-ubeghf-zrpunavphf-rot13.net>
    Re: Perl Installation Copied to Another Machine <invalid-email@rochester.rr.com>
        Please clarify lwp authentication? <r.mariotti@financialdatacorp.com>
    Re: PPM via proxy server <Allen.Windhorn@LSUSA.com>
        Regex and multiples on same line <gary@tgpmakers.com>
    Re: Regex and multiples on same line <asu1@c-o-r-n-e-l-l.edu>
    Re: What is '_' (Randal L. Schwartz)
    Re: Why does ne always work (Gary E. Ansok)
    Re: WIN32::Internet <theaney@cablespeed.com>
    Re: WIN32::Internet <usenet@dwall.fastmail.fm>
    Re: WIN32::Internet <asu1@c-o-r-n-e-l-l.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 09 Dec 2003 15:51:57 -0600
From: Scott Yanoff <yanoff@STOP-SPAMMINGyahoo.com>
Subject: Re: #!/usr/bin/perl
Message-Id: <3fd643fd$0$43847$39cecf19@news.twtelecom.net>

Roman Khutkyy wrote:

> Hi all,
> is there any ability in Perl to write the first string in script as
> alternative string for different platforms.
> I write CGI scripts on the Win32 computer, then I transport it to the Unix
> server, and each time i need to rewrite this string. Is there universal
> string for both platforms?

I'm not sure if there is one that will work for both Unix and Windows, 
but one thing I have seen in the past for the "she-bang" line is:

#!/usr/bin/env perl -w

Google groups search for "perl bin env" and you can find some examples 
of this.

-- 
-Scott
yanoff@STOP-SPAMMINGyahoo.com | http://www.yanoff.org | AOL IM: SAY KJY



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

Date: Tue, 09 Dec 2003 15:56:13 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: editing challenge: Perl vs. cfengine
Message-Id: <4niskp4snm.fsf@collins.bwh.harvard.edu>

On Mon, 08 Dec 2003, perl@my-header.org wrote:

> X-Ftn-To: Ted Zlatanov 
> 
> Ted Zlatanov <tzz@lifelogs.com> wrote:
>>The actual sequence of commands is pretty obvious - the outer
>>BeginGroup/EndGroup is an if() statement, and
>>LocateLineMatching/IncrementPointer move the editing cursor; -3
>>means to move 3 lines back in the file.
>>
>>My own attempt used an array-file tie and was definitely not
>>as elegant.
> 
> IMHO, you don't have much choice; you'll need some module with nice
> interface to stay elegant.

I think a module would be OK to answer this challenge, as long as
it's not written just to answer this challenge, but is really useful :)

In particular, Perl does not have good facilities for a logical
line-based cursor for insertion and deletion of lines.  Emacs Lisp,
for example, is very good at this.  Are there any CPAN modules that
would do this?  I know only of the one that ties a file to an array,
but that doesn't really have a logical cursor.

Ted


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

Date: 9 Dec 2003 13:39:55 -0800
From: amirkargerweb@yahoo.com (Amir Karger)
Subject: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <87671b7a.0312091339.6da80277@posting.google.com>

I've got a simple diamond class hierarchy (code below).  In order to
bore people, I've chosen to use Vehicle as the base class.
SolarVehicle and WheeledVehicle inherit from Vehicle, and SolarCar
inherits from both of those child classes. (But you could have a
SolarSeaPlane that's a SolarVehicle and not a WheeledVehicle.)

I want to specify a new and an _init for the base class. 

new just blesses {} and calls _init.

_init should call _init for every parent class, so that you initialize
all the attributes of the object, including attributes of the parent
classes along with this class.

So how do I write Vehicle::_init such that SolarCar::_init will
inherit it and call Vehicle::_init, SolarVehicle::_init, and
WheeledVehicle::_init?  (Writing SolarCar::_init so that it overloads
Vehicle::_init and calls the parent class _init's separate would be
unelegant, it seems to me.)

I've written code below that does everything except the step of
getting the base classes.  I feel like my problem here isn't that Perl
can't do it, but just a syntax problem.  I really just want a "foreach
(@ISA)" - but how do I write an inheritable Vehicle::_init and refer
to @ISA such that the @ISA of the package in which _init is currently
running is used, instead of always @Vehicle::ISA or @{ref($self) .
"::ISA"}.

I don't *think* this problem is due to diamond inheritance per se as
much as multiple inheritance in general. Also, I have a feeling Damian
Conway's Objects book answers this but I no longer have it. Long
story.

HELP!

-Amir Karger
amirkargerweb@yahoo.com

=cut

##################
package Vehicle;
@Vehicle::ISA = ();

sub new {
    my ($class, %args) = @_;
    print "new $class\n";
    my $self = {};
    bless $self, $class;
    $self->_init(%args);
}

sub _init {
    my ($self, %args) = @_;
    my $class = ref $self or die "no class for $self\n";
    print "_init for class $class.";
    # Note: can't use $class . "::ISA", because $class will
    # always be the class of the original object.
    my @bases = EVERYTHING IN THIS CLASS' @ISA;
    foreach my $base (@bases) {
	my $c = $base . "::_init";
	$self->$c(%args);
    }
    $self->_class_init(%args);
}

sub _class_init {
    my ($self, %args) = @_;
    $self->{"name"} = "Default vehicle name";
}

package WheeledVehicle;
@WheeledVehicle::ISA = qw(Vehicle);

sub _class_init {
    my ($self, %args) = @_;
    $self->{"wheels"} = 4;
}

package SolarVehicle;
@SolarVehicle::ISA = qw(Vehicle);

sub _class_init {
    my ($self, %args) = @_;
    $self->{"panels"} = 2;
}

package SolarCar;
@SolarCar::ISA = qw(WheeledVehicle SolarVehicle);

sub _class_init {
    my ($self, %args) = @_;
    $self->{"panels"} = 2;
}
#######################


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

Date: Tue, 09 Dec 2003 22:06:22 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <yHrBb.621994$6C4.592609@pd7tw1no>

Amir Karger wrote:

> I've got a simple diamond class hierarchy (code below).  In order to
> bore people, I've chosen to use Vehicle as the base class.
> SolarVehicle and WheeledVehicle inherit from Vehicle, and SolarCar
> inherits from both of those child classes. (But you could have a
> SolarSeaPlane that's a SolarVehicle and not a WheeledVehicle.)
> 
> I want to specify a new and an _init for the base class.
> 
> new just blesses {} and calls _init.
> 
> _init should call _init for every parent class, so that you initialize
> all the attributes of the object, including attributes of the parent
> classes along with this class.

Easiest way is to use NEXT (on CPAN) the same way you would use SUPER,
except that NEXT follows the ISA chain the way you want.

If you can't use NEXT directly, you may be able to steal some ideas
from it... which is what I did.

sub _init
{
    my $class = shift;
    my $orig_class = shift;

    no strict 'refs'; # there be dragons here
    # do ancestors first, allowing subclasses to "override" changes.
    foreach my $super (@{"${class}::ISA"})
    {
        $super->_init();
    }

    if (
        *{"${class}::class_init"}{CODE} and
        ref *{"${class}::class_init"}{CODE} eq 'CODE' # should always be 
true?
       )
    {
        *{"${class}::initialise_parser"}{CODE}->();
    }
}

There is probably a nicer way of saying some of this, but that's
basically the idea.  Note that this doesn't take care of the diamond
shape where it may call the top-level class multiple times.


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

Date: 9 Dec 2003 22:05:51 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <br5gvv$pai$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Amir Karger:

> I've got a simple diamond class hierarchy (code below).  In order to
> bore people, I've chosen to use Vehicle as the base class.
> SolarVehicle and WheeledVehicle inherit from Vehicle, and SolarCar
> inherits from both of those child classes. (But you could have a
> SolarSeaPlane that's a SolarVehicle and not a WheeledVehicle.)
> 
> I want to specify a new and an _init for the base class. 
> 
> new just blesses {} and calls _init.
> 
> _init should call _init for every parent class, so that you initialize
> all the attributes of the object, including attributes of the parent
> classes along with this class.
> 
> So how do I write Vehicle::_init such that SolarCar::_init will
> inherit it and call Vehicle::_init, SolarVehicle::_init, and
> WheeledVehicle::_init?  (Writing SolarCar::_init so that it overloads
> Vehicle::_init and calls the parent class _init's separate would be
> unelegant, it seems to me.)

I don't agree here. Vehicle is the most generic of all your classes and
its _init Method should really only arrange for those things that every
vehicle has. Furthermore, Vehicle shouldn't have to bother whether it is
used as a superclass or not. Ideally, it doesn't even realize it.

> I've written code below that does everything except the step of
> getting the base classes.  I feel like my problem here isn't that Perl
> can't do it, but just a syntax problem.  I really just want a "foreach
> (@ISA)" - but how do I write an inheritable Vehicle::_init and refer
> to @ISA such that the @ISA of the package in which _init is currently
> running is used, instead of always @Vehicle::ISA or @{ref($self) .
> "::ISA"}.
> 
> I don't *think* this problem is due to diamond inheritance per se as
> much as multiple inheritance in general. Also, I have a feeling Damian
> Conway's Objects book answers this but I no longer have it. Long
> story.
> 
> HELP!
> 
> -Amir Karger
> amirkargerweb@yahoo.com
> 
>=cut
> 
> ##################
> package Vehicle;
> @Vehicle::ISA = ();
> 
> sub new {
>     my ($class, %args) = @_;
>     print "new $class\n";
>     my $self = {};
>     bless $self, $class;
>     $self->_init(%args);
> }
> 
> sub _init {
>     my ($self, %args) = @_;
>     my $class = ref $self or die "no class for $self\n";
>     print "_init for class $class.";
>     # Note: can't use $class . "::ISA", because $class will
>     # always be the class of the original object.
>     my @bases = EVERYTHING IN THIS CLASS' @ISA;
>     foreach my $base (@bases) {
> 	my $c = $base . "::_init";
> 	$self->$c(%args);
>     }
>     $self->_class_init(%args);
> }

So trim this down to the minimum of what is required for a plain
Vehicle. Would become:

    sub _init {
        my ($self, %args) = @_;
        $self->{name} = "Default vehicle name";
    }

Your subclasses probably want to call the superclass' _init as well, I
assume. So they become:

> package WheeledVehicle;
> @WheeledVehicle::ISA = qw(Vehicle);
> 
> sub _class_init {
>     my ($self, %args) = @_;
>     $self->{"wheels"} = 4;
> }

    sub _init {
        my ($self, %args) = @_;
        $self->SUPER::_init;
        $self->{wheels} = 4;
    }

> package SolarVehicle;
> @SolarVehicle::ISA = qw(Vehicle);
> 
> sub _class_init {
>     my ($self, %args) = @_;
>     $self->{"panels"} = 2;
> }

    sub _init {
        my ($self, %args) = @_;
        $self->SUPER::_init;
        $self->{panels} = 2;
    }

> package SolarCar;
> @SolarCar::ISA = qw(WheeledVehicle SolarVehicle);
> 
> sub _class_init {
>     my ($self, %args) = @_;
>     $self->{"panels"} = 2;
> }

This class has more than one ancestor:

    sub _class_init {
        my ($self, %args) = @_;
        for (@SolarCar::ISA) {
            my $init = $_->can("_init")
                and $self->$init;
        }
        $self->{panels} = 2;
    }

You can use this foreach loop in every _init method actually since it
checks whether each class in @ISA has (either through inheritance or by
providing it) an _init method.

The only problem with this is that Vehicle's _init method is now called
twice because both WheelVehicle::_init and SolarVehicle::_init will call
it.

> #######################

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 9 Dec 2003 22:10:18 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <br5h8a$pie$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Amir Karger:

> I've got a simple diamond class hierarchy (code below).  In order to
> bore people, I've chosen to use Vehicle as the base class.
> SolarVehicle and WheeledVehicle inherit from Vehicle, and SolarCar
> inherits from both of those child classes. (But you could have a
> SolarSeaPlane that's a SolarVehicle and not a WheeledVehicle.)
> 
> I want to specify a new and an _init for the base class. 
> 
> new just blesses {} and calls _init.
> 
> _init should call _init for every parent class, so that you initialize
> all the attributes of the object, including attributes of the parent
> classes along with this class.
> 
> So how do I write Vehicle::_init such that SolarCar::_init will
> inherit it and call Vehicle::_init, SolarVehicle::_init, and
> WheeledVehicle::_init?  (Writing SolarCar::_init so that it overloads
> Vehicle::_init and calls the parent class _init's separate would be
> unelegant, it seems to me.)

I don't agree here. Vehicle is the most generic of all your classes and
its _init Method should really only arrange for those things that every
vehicle has. Furthermore, Vehicle shouldn't have to bother whether it is
used as a superclass or not. Ideally, it doesn't even realize it.

> I've written code below that does everything except the step of
> getting the base classes.  I feel like my problem here isn't that Perl
> can't do it, but just a syntax problem.  I really just want a "foreach
> (@ISA)" - but how do I write an inheritable Vehicle::_init and refer
> to @ISA such that the @ISA of the package in which _init is currently
> running is used, instead of always @Vehicle::ISA or @{ref($self) .
> "::ISA"}.
> 
> I don't *think* this problem is due to diamond inheritance per se as
> much as multiple inheritance in general. Also, I have a feeling Damian
> Conway's Objects book answers this but I no longer have it. Long
> story.
> 
> HELP!
> 
> -Amir Karger
> amirkargerweb@yahoo.com
> 
>=cut
> 
> ##################
> package Vehicle;
> @Vehicle::ISA = ();
> 
> sub new {
>     my ($class, %args) = @_;
>     print "new $class\n";
>     my $self = {};
>     bless $self, $class;
>     $self->_init(%args);
> }
> 
> sub _init {
>     my ($self, %args) = @_;
>     my $class = ref $self or die "no class for $self\n";
>     print "_init for class $class.";
>     # Note: can't use $class . "::ISA", because $class will
>     # always be the class of the original object.
>     my @bases = EVERYTHING IN THIS CLASS' @ISA;
>     foreach my $base (@bases) {
> 	my $c = $base . "::_init";
> 	$self->$c(%args);
>     }
>     $self->_class_init(%args);
> }

So trim this down to the minimum of what is required for a plain
Vehicle. Would become:

    sub _init {
        my ($self, %args) = @_;
        $self->{name} = "Default vehicle name";
    }

Your subclasses probably want to call the superclass' _init as well, I
assume. So they become:

> package WheeledVehicle;
> @WheeledVehicle::ISA = qw(Vehicle);
> 
> sub _class_init {
>     my ($self, %args) = @_;
>     $self->{"wheels"} = 4;
> }

    sub _init {
        my ($self, %args) = @_;
        $self->SUPER::_init;
        $self->{wheels} = 4;
    }

> package SolarVehicle;
> @SolarVehicle::ISA = qw(Vehicle);
> 
> sub _class_init {
>     my ($self, %args) = @_;
>     $self->{"panels"} = 2;
> }

    sub _init {
        my ($self, %args) = @_;
        $self->SUPER::_init;
        $self->{panels} = 2;
    }

> package SolarCar;
> @SolarCar::ISA = qw(WheeledVehicle SolarVehicle);
> 
> sub _class_init {
>     my ($self, %args) = @_;
>     $self->{"panels"} = 2;
> }

This class has more than one ancestor:

    sub _class_init {
        my ($self, %args) = @_;
        for (@SolarCar::ISA) {
            my $init = $_->can("_init")
                and $self->$init;
        }
        $self->{panels} = 2;
    }

You can use this foreach loop in every _init method actually since it
checks whether each class in @ISA has (either through inheritance or by
providing it) an _init method.

The only problem with this is that Vehicle's _init method is now called
twice because both WheelVehicle::_init and SolarVehicle::_init will call
it.

> #######################

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 09 Dec 2003 21:52:10 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <slrnbtch09.sj9.abigail@alexandra.abigail.nl>

Michele Dondi (bik.mido@tiscalinet.it) wrote on MMMDCCLII September
MCMXCIII in <URL:news:q0sotv49cr080v9mvnvu5vk6rohpkdvhea@4ax.com>:
{}  On 07 Dec 2003 21:56:41 GMT, Abigail <abigail@abigail.nl> wrote:
{}  
{} >Well, yes, of course. This is after all Perl5, which like every other
{} >main stream language I know about allows optional whitespace between
{} >tokens. The whitespace isn't significant.
{} >
{} >Unlike Perl6, which just throws out 50 years of programming language
{} >design out of the window, passes Python on the wrong side and makes
{} >whitespace significant in new painful and revolting ways.
{}  
{}  Just out of curiosity: is this definitive or are there chances that
{}  such "features" may be removed/changed before before Perl6 is actually
{}  released in productive form?


Nothing is definitive, but Larry and Damian seem to be convinced that
the gain of saving 2 characters on an if() are worth sacrificing the
non-significance of whitespace, that I say the chances are small.

On the other hand, I'm more and more convinced that I will be retired
before Larry finishes the language specification. ;-)



Abigail
-- 
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))


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

Date: Tue, 09 Dec 2003 19:18:06 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Multi-dimensional  Data Structures
Message-Id: <br575f$mj8$1@news.freedom2surf.net>

In article <br51u4$clp$1@solaris.cc.vt.edu>, "Konstantinos"
<agbiotec@yahoo.com> wrote:

> The problem arises from the fact, that the
> first time I call the sub, a parent node splits to the left and right
> daughter ones which are stored as Multi-D structure CREATED INSIDE THE
> SUB. 

This isn't quite correct, conceptually. You only have one data structure
(you _should_ only have one, otherwise you _will_ have the kind of
problems I'm about to say that you don't), your sub is placing data into
that data structure, and extending the data structure where necessary.
Your sub is not _creating_ the daughter structures in the sense you mean.
It is creating them in another sense, but once they are assigned to a
location in the parent structure they will survive until the parent
structure is undef'ed, unless you try really hard to make them disappear
before that.

Perl deals in scalar values (SVs) and refcounts. A scalar value is a
container for a datum. This datum could be a number, a string, the
undefined value, or a reference to another scalar value, or a reference
to hash or array or ... etc. A variable name is a way of referencing that
scalar value. But there are other ways. Consider:

$c = aaa();
print $$c;

sub aaa {
	my @a = (1,2);
	$b = \$a[1]; # <--- interesting bit
	return $b;
}

This code will output "2". Why? Because the interesting bit creates
another way to get at the data stored in the array. It creates another
reference to the scalar value which is accessible as the second element
of the array, therefore the refcount of this SV is increased by one. When
the array @a goes out of scope when the sub exits, the refcount of $a[0],
the first element, is decreased by one and ends up 0, so that SV goes
away. The refcount of $a[1] is decreased by one, but this time it ends up
1, because of the reference the interesting bit created, so it is not
destroyed.

If all of this is confusing then read "perldoc perlref" until your head
hurts. Then read it some more.

HTH
Rich


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

Date: Tue, 09 Dec 2003 22:10:05 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Multi-dimensional  Data Structures
Message-Id: <br5edq$29l9ts$1@ID-184292.news.uni-berlin.de>

[ Please don't top post! ]

Konstantinos wrote:
> Gunnar Hjalmarsson wrote:
>> Konstantinos wrote:
>>> I create a Multi-dimensional Data Structure within a
>>> subroutine, and I want to keep calling this subroutine
>>> recursively, passing each time the MD-data structure. How am I
>>> gonna achieve this ? Since the references to memory adresses
>>> for this MD-data structure are created within the scope of the
>>> subroutine, aren't these memory slots emptied each time the sub
>>> ends ? (I think that is my problem, and my script does not
>>> work).
>> 
>> Which script? Would you mind sharing a minimal program that 
>> illustrates the problem?
>> 
>> Until we have seen that, the only thing I can say is that you
>> should probably declare a reference to the data structure
>> somewhere outside the sub.
> 
>    It a program that you can say ...

<long description in English snipped>

Why on earth can't you speak Perl??

This script matches your first description. It might be of some help:

     my $mdref;                      # variable declaration

     $mdref = addarray($mdref);      # initial structure created
     print "@{$mdref->[$_]}\n" for (0..$#$mdref);
     print "\n";

     $mdref = addarray($mdref);      # another anonymous array added
     print "@{$mdref->[$_]}\n" for (0..$#$mdref);

     sub addarray {
         my $ref = ( shift or [] );
         my ($i, $x);
         if ($ref->[0]) {
             $i = $#$ref + 1;
             $x = $ref->[$#$ref][2] + 1;
         } else {
             $i = 0;
             $x = 1;
         }
         $ref->[$i] = [$x, $x+1, $x+2];
         $ref
     }

It outputs:
1 2 3

1 2 3
4 5 6

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 09 Dec 2003 16:41:03 -0500
From: Konstantinos <agbiotec@yahoo.com>
To: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Multi-dimensional  Data Structures
Message-Id: <3FD6416F.4090803@yahoo.com>

A. Sinan Unur wrote:

> Do not top post
> Do not blindly quote messages in full
> Do read the posting quidelines:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
> 
> And it seems like you might benefit from reading:
> http://www.catb.org/~esr/faqs/smart-questions.html
> as well.
> 
> ...

Thank you. That was very educative.

Konstantinos



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

Date: 9 Dec 2003 14:05:10 -0800
From: bear@san.rr.com (bear)
Subject: Perl Installation Copied to Another Machine
Message-Id: <605e2aad.0312091405.4ac715a4@posting.google.com>

Can I make and install Perl and install all the Perl modules on one machine 
and then copy the Perl directory to a second machine and have it work correctly?
I 've got all the Perl modules installed correctly on the first machine including
Apache, mysql DBI, DBD, etc.  After copying the perl directory to the second 
machine I can not start Apache httpd.  I get the message 
"Can't locate loadable object for module DBI in @INC"

Should I make Perl or DBI on the second machine?

thanks


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

Date: Tue, 09 Dec 2003 23:28:23 +0100
From: "Joost Diepenmaat" <joost@rot13-ubeghf-zrpunavphf-rot13.net>
Subject: Re: Perl Installation Copied to Another Machine
Message-Id: <pan.2003.12.09.22.28.23.350997@rot13-ubeghf-zrpunavphf-rot13.net>

On Tue, 09 Dec 2003 14:05:10 -0800, bear wrote:

> Can I make and install Perl and install all the Perl modules on one
> machine and then copy the Perl directory to a second machine and have it
> work correctly? 

Which Perl directory?

If your machines are exactly alike (for some definition of "exactly"; you
need a binary compatible perl, so that means you need the same
CPU architecture, the "same" OS, and probably the same perl version,
compiled with the same config options) this might work. But then you have
to copy all (some?) of the stuff from /usr/lib/perl5/site_perl or equivalent
(and maybe more).

I'd recommend just installing the whole shebang from source on the new
machine using perl -MCPAN -eshell. But I'm just lazy :-)

Joost.



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

Date: Tue, 09 Dec 2003 22:34:51 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Perl Installation Copied to Another Machine
Message-Id: <3FD649D7.6060106@rochester.rr.com>

bear wrote:

> Can I make and install Perl and install all the Perl modules on one machine 
> and then copy the Perl directory to a second machine and have it work correctly?
> I 've got all the Perl modules installed correctly on the first machine including
> Apache, mysql DBI, DBD, etc.  After copying the perl directory to the second 
> machine I can not start Apache httpd.  I get the message 
> "Can't locate loadable object for module DBI in @INC"
> 
> Should I make Perl or DBI on the second machine?
 ... 

You probably just need to define a couple of environment variables and 
specify where Perl is on your path.  You don't say what your platform is 
-- you might need to add some symlinks as well, depending, and maybe 
copy some man pages, and maybe some other install type things.  On 
Windoze, you can copy Perl to a CD and it runs fine from the CD on a 
machine on which Perl is not installed -- and you can copy the CD to 
another computer's hard drive, and it will run fine there too.

HTH.
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Tue, 09 Dec 2003 14:08:34 -0500
From: Bob Mariotti <r.mariotti@financialdatacorp.com>
Subject: Please clarify lwp authentication?
Message-Id: <6u6ctvcie540vhrnhoimo3vfoddqhulpuh@4ax.com>

First, I have lwpcook, Perl & LWP, Web Client Programming, Perl in a
Nutshell and Network Programming with Perl ALL in front of me.  And, I
have read and reread the sections on LWP.  I've also scoured usenet
with google groups but I am still confused because none of these
sources (including perldoc.org) actually explain.

I have a program that must send authentication as a basic header.
This is being accomplished with the following instructions:

$REQ= POST $URL2;                                                 
$REQ->authorization_basic("$USERID","$PASSWD");

At this level the content of the USERID and PASSWD are plain text.  It
appears that when the $RSP=$UA->request($REQ); is executed, the
modules must be base64_encoding the values because when I dump the
request itself I can see the encoded string.

However, it seems that the encoded string is encoded TWICE.
If I take the encoded string from the logged request and pass it
through a decoder it return the phrase:

BASIC -another_encoded_string-

If I then take the -another_encoded_string- and pass it through the
decoder by itself it returns my plain text USERID and PASSWD string.

Go figure!

Am I understanding this correctly?  Because this is not what one is
led to believe when reading all the reference docs.

I just want to understand so we can forever more use it correctly.

Please comment advise?

Thanks,


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

Date: Tue, 09 Dec 2003 19:34:32 GMT
From: Allen Windhorn <Allen.Windhorn@LSUSA.com>
Subject: Re: PPM via proxy server
Message-Id: <u1xrdvl7d.fsf@LSUSA.com>

"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> writes:

> Allen Windhorn <Allen.Windhorn@LSUSA.com> wrote in 
> news:u4qwb3w0o.fsf@LSUSA.com:
> 
> > PPM doesn't work on my office machine, apparently because it can't get
> > through our firewall.  HTTP and FTP are normally no problem here.  Is
> > there a setting I need to make?
> > ...
> 
> Did you check the ActivePerl FAQ? Is there a problem with the explanation 
> provided there?

Sorry, should have said I had set the variables, but it turns out the
proxy had been moved since.  Thanks for your help.

Regards,
Allen


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

Date: Tue, 09 Dec 2003 20:53:34 +0000
From: Gary Mayor <gary@tgpmakers.com>
Subject: Regex and multiples on same line
Message-Id: <br5ckb$c0q$1@news6.svr.pol.co.uk>

Hi,
Thanks for everyone in my earlier message. Now i've got a problem with 
regex. I've got a file with lines like this,

CATETITLE1 CATETITLE2 CATETITLE3 CATETITLE4
CATETITLE5 CATETITLE6 CATETITLE7 CATETITLE8

while(<FILE>) {
   if ($_=~ /CATETITLE/) {
      $counter++;
   }
}

if I then run through the file and match each time there is a CATETITLE 
I only get a count of 2. How do I find out the total amount of CATETITLE?

Thanks

Gary



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

Date: 9 Dec 2003 21:14:38 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Regex and multiples on same line
Message-Id: <Xns944CA53E09398asu1cornelledu@132.236.56.8>

Gary Mayor <gary@tgpmakers.com> wrote in news:br5ckb$c0q$1
@news6.svr.pol.co.uk:

> Hi,
> Thanks for everyone in my earlier message. Now i've got a problem with 
> regex. I've got a file with lines like this,

Your problem is relates not to the regex itself, but the matching 
operator. Do read perldoc perlop.

> 
> CATETITLE1 CATETITLE2 CATETITLE3 CATETITLE4
> CATETITLE5 CATETITLE6 CATETITLE7 CATETITLE8
> 
> while(<FILE>) {
>    if ($_=~ /CATETITLE/) {
>       $counter++;
>    }
> }

Please post code that we can run with no effort.

C:\Home> cat hababa.pl
use strict;
use warnings;

my $counter = 0;
while(<DATA>) {
    $counter += (my @m = $_ =~ /(CATETITLE)/g);
}
print $counter, "\n";

__DATA__
CATETITLE1 CATETITLE2 CATETITLE3 CATETITLE4
CATETITLE5 CATETITLE6 CATETITLE7 CATETITLE8

C:\Home> perl hababa.pl
8

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Tue, 09 Dec 2003 20:26:45 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: What is '_'
Message-Id: <b556d3741ef8606141a20a128ebf8529@news.teranews.com>

>>>>> "Richard" == Richard Gration <richard@zync.co.uk> writes:

Richard> When you get perl to stat a file (ie you ask perl for
Richard> information about the file, eg is it a directory, how long is
Richard> the file, what is its mod time, etc) perl uses a system
Richard> function called stat, which returns a lot of information
Richard> about the file. The results of the stat are cached. The '_'
Richard> causes perl to consult the stored stat results instead of
Richard> statting the file again.

Yup.  One of the few features of Perl I can claim to have invented.
Two others that come to mind are the literal-slice notation and the
use of arrow for dereferencing code refs.  And the JAPH. :)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Tue, 9 Dec 2003 19:24:38 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Why does ne always work
Message-Id: <br57hm$iia$1@naig.caltech.edu>

In article <br4hu3$mbq$6@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Gary Mayor  <gary@tgpmakers.com> wrote in comp.lang.perl.misc:
>> > Gary Mayor  <gary@tgpmakers.com> wrote in comp.lang.perl.misc:
>> > 
>> >>Hi,
>> >>Whilst i'm here i might as well see if anyone else has noticed strange 
>> >>things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 
>> 
>> This message is probably useless without a real example. When I come 
>> accross it again i'll post it up. I was just wondering if anyone else 
>> had seen this problem.
>
>I think you are confusing "ne" with "!=".  If you compare two different
>strings *numerically*, the result may be that they're equal because
>they represent the same number, as in "003" and "3".  String comparison
>(with "eq", "ne" and friends) always compares strings "as-is".

Another possibility is that one of the strings has leading or
trailing whitespace.  A common cause of this is forgetting to
chomp() a line read from a file, so that the string read from
the file still has the newline at the end, but the string it
is being compared to has no newline.

If I get strings that do not compare when I think they should,
my first step is to do something like

    if ($blah ne $blah1) {
       print "OOPS -- not equal '$blah' and '$blah1'\n";
    }

Having the single quotes there helps to see any unexpected
spaces or newlines.  You may prefer something more visible, like
">>>$blah<<<".

Yes, a real example would definitely help us help you.

Gary Ansok
-- 
Practice random acts of intelligence and senseless acts of self-control.


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

Date: Tue, 09 Dec 2003 15:32:47 -0500
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: WIN32::Internet
Message-Id: <87wu9520ls.fsf@mrbun.watterson>

BOHIM <BOHIM789@AOL.COM> writes:
>
> I want to change local directory (lcd in dos) and no reference to
> this method in the documentation ?

You don't need an lcd method, since you can use Perl's own chdir to
change the local directory.

  chdir $dir or die "Cannot change to directory $dir: $!\n";

I hope this helps,

Tim


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

Date: Tue, 09 Dec 2003 20:37:34 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: WIN32::Internet
Message-Id: <Xns944C9EF111AB7dkwwashere@216.168.3.30>

BOHIM <BOHIM789@AOL.COM> wrote:

> I want to change local directory (lcd in dos) and no reference to
> this method in the documentation ?

I don't recall DOS ever having an lcd command.  Perhaps you mean the 
lcd command in ftp?  If so, use the built-in function chdir().

Why Win32::Internet?  I glanced through the docs for it, and offhand I 
don't see anything that you can't do just as easily with other modules 
which don't have the disadvantage of only working on one operating 
system.

-- 
David Wall


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

Date: 9 Dec 2003 21:17:11 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: WIN32::Internet
Message-Id: <Xns944CA5AC3D735asu1cornelledu@132.236.56.8>

BOHIM <BOHIM789@AOL.COM> wrote in news:2003129-133253-41466@foorum.com:

> I want to change local directory (lcd in dos) and no reference to this
> method in the documentation ?

You subject line seems to be completely irrelevant to your question. What 
does changing a directory in DOS have to do with Win32 or the Internet. (I 
can guess what you mean, but I do not like being put in the role of the 
mind reader).

Please explain your problem. (Also, please read the posting quidelines 
before your next post).

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

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


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