[29037] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 281 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 29 16:10:09 2007

Date: Thu, 29 Mar 2007 13:09:11 -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           Thu, 29 Mar 2007     Volume: 11 Number: 281

Today's topics:
        Any "consumer review generators" available? aralsky@aol.com
    Re: Any "consumer review generators" available? <uri@stemsystems.com>
    Re: Beginning OO help <nomail@sorry.com>
    Re: Beginning OO help <rvtol+news@isolution.nl>
    Re: Heroes of the FAQ <please@nospam.net>
        How best to "fix" a bug in a standard module? <socyl@987jk.com.invalid>
    Re: HowTo parse huge Files <paduille.4060.mumia.w+nospam@earthlink.net>
    Re: HowTo parse huge Files <someone@example.com>
        Leading Space with REGEX jerryacoleman@gmail.com
    Re: Leading Space with REGEX <mritty@gmail.com>
    Re: Leading Space with REGEX jgraber@ti.com
    Re: Leading Space with REGEX <someone@example.com>
    Re: multiple inheritance and instance data? <paduille.4060.mumia.w+nospam@earthlink.net>
        Perh Hash of Hash of Array structure <shirazk@gmail.com>
    Re: Perh Hash of Hash of Array structure <someone@example.com>
    Re: Perh Hash of Hash of Array structure <thepoet_nospam@arcor.de>
        Shifting Away <please@nospam.net>
    Re: Shifting Away <someone@example.com>
    Re: Shifting Away <rvtol+news@isolution.nl>
    Re: Troubleshooting cpan <socyl@987jk.com.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 29 Mar 2007 13:19:52 -0500
From: aralsky@aol.com
Subject: Any "consumer review generators" available?
Message-Id: <NYidnYp6I5PVnpHbnZ2dnUVZ_sqdnZ2d@giganews.com>

I am looking for a fake consumer review generator that could generate realistic looking reviews for any products, kind of like on amazon.com but generated by Artificial Intelligence. Is there a package available in your favorite programing language... thx alan


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

Date: Thu, 29 Mar 2007 14:00:17 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Any "consumer review generators" available?
Message-Id: <x7ejn7dge6.fsf@mail.sysarch.com>

>>>>> "a" == aralsky  <aralsky@aol.com> writes:

  a> I am looking for a fake consumer review generator that could
  a> generate realistic looking reviews for any products, kind of like
  a> on amazon.com but generated by Artificial Intelligence. Is there a
  a> package available in your favorite programing language... thx alan

it's called a human being. and hope you find some with ethics which you
don't seem to have.

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: Thu, 29 Mar 2007 09:14:17 -0800
From: Arvin Portlock <nomail@sorry.com>
Subject: Re: Beginning OO help
Message-Id: <eugoks$1rcp$1@agate.berkeley.edu>

Abigail wrote:

> Arvin Portlock (nomail@sorry.com) wrote on MMMMCMLVII September MCMXCIII
> in :
> ..  Jamie wrote:
> ..
> .. > In ,
> .. > Arvin Portlock  mentions:
> .. >
> .. > >Unlearning is definitely necessary to learn this stuff. OO
> .. > >really is just grafted onto perl. It's plain old references
> .. > >used in clever ways with the help of bless.
> .. >
> .. >
> .. > Yep. :-)
> ..
> ..  I need help again! $obj = Package->new (args) works but I can't
> ..  get $obj = new Package (args) to work. The actual program is too
> ..  long to post here and I *tried* to reproduce it in a smaller simpler
> ..  program and failed.
> ..
> ..  Interestingly, if I simply declare the package name anywhere before
> ..  the current package then change it back, then the indirect method
> ..  works. In pseudo code, this does not work:
> ..
> ..  package MyPackage;
> ..
> ..  sub subname {
> ..      new OtherPackage (args);
> ..  }
> ..
> ..  package OtherPackage;
> ..
> ..  sub new {
> ..      print "OtherPackage here!\n";
> ..  }
> ..
> ..  But if I stick a bare package declaration at the top then the
> ..  indirect method works:
> ..
> ..  package OtherPackage;
> ..  package MyPackage;
> ..
> ..  sub subname {
> ..      new OtherPackage (args);
> ..  }
> ..
> ..  package OtherPackage;
> ..
> ..  sub new {
> ..      print "OtherPackage here!\n";
> ..  }
> ..
> ..  This reminds me very much of a forward declaration except it's a
> ..  package name!
> ..
> ..  Like I said, I cannot reproduce this problem in simpler code. But
> ..  can anyone tell me from the little I sketched above what might
> ..  be going on?
>
>
> Yes.
>
>
> This unexpected behavious is *exactly* why you shouldn't use the
> indirect object method.
>
> Stick to CLASS -> method ().
>
>
>
> Abigail

I was able to reproduce the behavior in a small test program. It
also turns out I can make the indirect notation work by doing
this: new Package:: (args). I'm rereading about packages now. This
is behavior I've never encountered. Especially that weirdness about
the "forward declaration."

use  Pete::MyFirstClass;
new Pete::MyFirstClass ('filename.xml');

# package Event;  # Strangely, it works if I put this here!
package Pete::MyFirstClass;

sub new {
    my ($self, $file) = @_;
    my ($filename)  = $file =~ /([^\/\\]+)$/;
    &event_start;
}

sub event_start {
    my ($element, $self) = @_;
    # my $elt = new Event:: ($element); # This works
    # my $elt = Event->new ($element); # This works
    my $elt = new Event ($element); # This does not
}

package Event;

sub new {
    print "New event encountered!\n";
}





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

Date: Thu, 29 Mar 2007 21:28:12 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Beginning OO help
Message-Id: <euhb23.90.1@news.isolution.nl>

Arvin Portlock schreef:

> I was able to reproduce the behavior in a small test program. It
> also turns out I can make the indirect notation work by doing
> this: new Package:: (args).

As Abigail ordered:
>> Stick to CLASS -> method (). 

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Thu, 29 Mar 2007 01:12:05 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: Heroes of the FAQ
Message-Id: <please-7DBDC5.01120529032007@free.teranews.com>

In article <200320071110201952%brian.d.foy@gmail.com>,
 brian d  foy <brian.d.foy@gmail.com> wrote:

> You don't have to wait for me though. These come with Perl as the
> perlfaq docs, and you can also see them at http://faq.perl.org/.

Everything either comes with the distro or is available online. I wallow 
in docs. Then there are the books, which I'm too cheap to buy; but I 
skunk around until I get a good read anyway. The problem is not "not 
enough docs" and your signal service is not posting them to Usenet. 

The really valuable part about the FAQ posts -- for me -- is that 
they're short and cut into logical chunks. I'm attracted, without 
deliberate thought, to read *one* bite-sized FAQ, opening without 
hesitation or fear that I'll get sidetracked into another four-hour 
journey through the stacks. I benefit from the implicit assurance that I 
will get out of the FAQ in a minute or two and maybe actually go back to 
work. I can, of course, indulge by munching one post after another but 
to do that, I must explicitly exit one post and return to a level 
somewhat closer to the Real World (as in *not* sitting at the screen). 

It's sort of like a crack dealer who will only sell one rock at a time. 
You may still be a crackhead but at least you have the *opportunity* to 
leave the dope house without taking a horizontal taxi ride.
-- 
Xiong Changnian
xiong102ATxuefangDOTcom

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Thu, 29 Mar 2007 16:17:52 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: How best to "fix" a bug in a standard module?
Message-Id: <eugorg$mvp$1@reader2.panix.com>




I frequently run into minor bugs in modules downloaded from CPAN.
Aside from the issue of reporting the bug to the modules' maintainers,
there's still the immediate problem of fixing the bug for our own
use.

AFAIC, it is out of the question to replace the installed module
with one I have fixed.  Therefore I have settled on just redefining
the buggy sub(s) in the calling code.  For example, CGI::Carp::die
does not behave like CORE::die with respect to $@.  To correct
this, I have this snippet at the beginning of my CGI script:

BEGIN {
  no warnings 'redefine';
  my $ccdie = \&CGI::Carp::die;
  sub CGI::Carp::die {
    @_ = $@ if !@_ and $@;
    goto &$ccdie;
  }
}

This seems to work fine, but somehow I'm not entirely comfortable
with doing something like this.  What pitfalls am I overlooking?
Is there a better approach?

TIA!

kj
-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: Thu, 29 Mar 2007 16:03:25 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: HowTo parse huge Files
Message-Id: <hrROh.16204$PL.12911@newsread4.news.pas.earthlink.net>

On 03/29/2007 07:24 AM, cadetg@googlemail.com wrote:
> Dear Perl Monks, I am developing at the moment a script which has to
> parse 20GB files. The files I have to parse are some logfiles. My
> problem is that it takes ages to parse the files. I am doing something
> like this:
> 
> my %lookingFor;
> # keys => different name of one subset
> # values => array of one subset
> 
> my $fh = new FileHandle "< largeLogFile.log";
> [1:] while (<$fh>) {
>   foreach my $subset (keys %lookingFor) {
>     foreach my $item (@{$subset}) {
> [2:]      if (<$fh> =~ m/$item/) {

You are aware that line 2 reads in a new chunk from $fh, and the old 
chunk read on line 1 is forgotten, don't you?


>         my $writeFh = new FileHandle ">> myout.log"; print $writeFh <
> $fh>;

You can open the write filehandle once and keep it open til you are done.


>       }
>    }
> }
> 
> I've already tried to speed it up by using the regExp flag=>o by doing
> something like this:
> 
> $isSubSet=buildRegexp(@allSubSets);
> while (<$fh>) {
>   foreach my $subset (keys %lookingFor) {
>     if (&$isSubSet(<$fh>)) {
>       my $writeFh = new FileHandle ">> myout.log";
>       print $writeFh <$fh>;
>     }
>   }
>  }
> sub buildRegexp {
>   my @R = @_; my $expr = join '||', map { "\$_[0] =~ m/\(To\|is\)\\:\\S
> \+\\@\$R[$_ +]/io" } ( 0..$#R );
>   my $matchsub = eval "sub { $expr }";
>   if ($@) { $logger->error("Failed in building regex @R: $@"); return
> ERROR; }
>   $matchsub;
> }
> 
> I don't know how to optimize this more. Maybe it would be possible to
> do something with "map"? I think the "o" flag didn't speed it up at
> all. Also I've tried to split the one big file into a few small ones
> and use some forks childs to parse each of the small ones. Also this
> didn't help.
> 
> Thanks a lot for your help!
> 
> Cheers
> -Marco
> 

It might not be possible to get much faster with such large files, but 
try this out:

#!/usr/bin/perl
use strict;
use warnings;
use FileHandle;
use Data::Dumper;
use Alias;

my %lookingFor = (
     houseware => [qw(wallpaper hangers doorknobs)],
     );

my %lookingForRx = lookingForRx(%lookingFor);


my $fh = new FileHandle '< largeLogFile.log';
my $writeFh = new FileHandle '> myout.log';

while (my $line = <$fh>) {
     foreach my $subset (keys %lookingForRx) {
         if ($line =~ /$lookingForRx{$subset}/) {
             print $writeFh $line;
         }
     }
}


$writeFh->close;
$fh->close;

#####################################

sub lookingForRx {
     our (%oldHash, @oldArray);
     local %oldHash = @_;
     local @oldArray;

     my %hash;
     foreach my $subset (keys %oldHash) {
         alias oldArray => $oldHash{$subset};
         my $rx = do { local $" = '|'; "(@oldArray)"  };
         $hash{$subset} = qr/$rx/;
     }
     %hash;
}


__END__

I haven't really tested this other than to make sure it compiles.




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

Date: Thu, 29 Mar 2007 19:02:24 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: HowTo parse huge Files
Message-Id: <43UOh.28203$x9.8743@edtnps89>

Mumia W. wrote:
> On 03/29/2007 07:24 AM, cadetg@googlemail.com wrote:
>> Dear Perl Monks, I am developing at the moment a script which has to
>> parse 20GB files. The files I have to parse are some logfiles. My
>> problem is that it takes ages to parse the files. I am doing something
>> like this:
>>
>> my %lookingFor;
>> # keys => different name of one subset
>> # values => array of one subset
>>
>> my $fh = new FileHandle "< largeLogFile.log";
>> [1:] while (<$fh>) {
>>   foreach my $subset (keys %lookingFor) {
>>     foreach my $item (@{$subset}) {
>> [2:]      if (<$fh> =~ m/$item/) {
> 
> You are aware that line 2 reads in a new chunk from $fh, and the old
> chunk read on line 1 is forgotten, don't you?

It is the other way around.  "while (<$fh>) {" read a line and stores it in $_
so it is still around, while "if (<$fh> =~ m/$item/) {" reads another line and
binds it to the regular expression and then discards it.


>>         my $writeFh = new FileHandle ">> myout.log"; print $writeFh <
>> $fh>;

And a third line is read from the file and printed out.




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: 29 Mar 2007 09:20:11 -0700
From: jerryacoleman@gmail.com
Subject: Leading Space with REGEX
Message-Id: <1175185211.618490.252480@r56g2000hsd.googlegroups.com>

I have the following regex.  It is matching what I want( /BIG/TRUCK),
but it is also included the leading space.  Is there anyway to
suppress the leading space.

\b[^"|']/\w+/\w+\b

String:

TYPE /BIG/TRUCK



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

Date: 29 Mar 2007 10:04:38 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Leading Space with REGEX
Message-Id: <1175187877.942305.248820@n76g2000hsh.googlegroups.com>

On Mar 29, 12:20 pm, jerryacole...@gmail.com wrote:
> I have the following regex.  It is matching what I want( /BIG/TRUCK),
> but it is also included the leading space.  Is there anyway to
> suppress the leading space.
>
> \b[^"|']/\w+/\w+\b
>
> String:
>
> TYPE /BIG/TRUCK

I don't understand your question.  You're very specifically looking
for "word boundary; anything other than double quote, vertical-bar, or
single quote; slash; one or more word characters; slash; one or more
word characters; word boundary".  The space character matches the
"anything other than..." portion of that.  If you don't want to match
that space character, why are you putting that token in there?

To put it another way:  Please post a SHORT but COMPLETE script that
demonstrates both what you're doing, and the output that demonstrates
what you want to do.

Paul Lalli



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

Date: 29 Mar 2007 13:28:04 -0500
From: jgraber@ti.com
Subject: Re: Leading Space with REGEX
Message-Id: <yvnhcs3ewgb.fsf@famous02.dal.design.ti.com>


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

> On Mar 29, 12:20 pm, jerryacole...@gmail.com wrote:
> > I have the following regex.  It is matching what I want( /BIG/TRUCK),
> > but it is also included the leading space.  Is there anyway to
> > suppress the leading space.
> >
> > \b[^"|']/\w+/\w+\b
> >
> > String:
> >
> > TYPE /BIG/TRUCK
> 
> I don't understand your question.  You're very specifically looking
> for "word boundary; anything other than double quote, vertical-bar, or
> single quote; slash; one or more word characters; slash; one or more
> word characters; word boundary".  The space character matches the
> "anything other than..." portion of that.  If you don't want to match
> that space character, why are you putting that token in there?
> 
> To put it another way:  Please post a SHORT but COMPLETE script that
> demonstrates both what you're doing, and the output that demonstrates
> what you want to do.
> 
> Paul Lalli
 
Jerry, and all other people with Regex type questions;
  If you read the posting guidelines that are posted frequently
and easily googleable for this news group,  you'll see that what
Paul means by "SHOFT but COMPLETE program"
is something like this:

==cut==
 use warnings;  # see perldoc warnings
 use strict;    # see perldoc strict
 while (<DATA>){ # get a line from below __DATA__ in to $_ default var
   chomp;
   my ($saved) = (  m:(\b[^"|']/\w+/\w+\b):  );
   print "Line $. is '$_',  saved section is '$saved'\n";
} 
__DATA__
TYPE /BIG/TRUCK
ECHO /SMALL/CAR
==cut==

# Here is the output I have:
Line 1 is 'TYPE /BIG/TRUCK',  saved section is ' /BIG/TRUCK'
Line 2 is 'ECHO /SMALL/CAR',  saved section is ' /SMALL/CAR'

# Here is the output I desire:
Line 1 is 'TYPE /BIG/TRUCK',  saved section is '/BIG/TRUCK'
Line 2 is 'ECHO /SMALL/CAR',  saved section is '/SMALL/CAR'

###### 
With the above type of data, it is easy for anyone to
copy and paste your complete program with DATA and run it
to demonstrate.   Plus, it helps you find the problem yourself.

Hey look,  if I follow Paul's adice and move the ( to after
the [] section,  it generates the desired output.
was my ($saved) = (  m:(\b[^"|']/\w+/\w+\b):  );
now my ($saved) = (  m:\b[^"|'](/\w+/\w+\b):  );
                       ^------>(

-- 
Joel


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

Date: Thu, 29 Mar 2007 19:21:47 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Leading Space with REGEX
Message-Id: <flUOh.20671$6z3.2818@edtnps82>

jerryacoleman@gmail.com wrote:
> I have the following regex.  It is matching what I want( /BIG/TRUCK),
> but it is also included the leading space.  Is there anyway to
> suppress the leading space.
> 
> \b[^"|']/\w+/\w+\b
> 
> String:
> 
> TYPE /BIG/TRUCK

\b matches at six places in the above example, between the beginning of the
string and the 'T' in TYPE, between the 'E' in TYPE the ' ' following it,
between the '/' and the 'B' in BIG, between the 'G' in BIG and the '/',
between the '/' and the 'T' in TRUCK, and finally, between the 'K' in TRUCK
and the end of the string.

In your example the only place the the first \b can match is between the 'E'
in TYPE the ' ' following it and the second \b is superfluous because \w+ is
greedy so anything following it will not match \w.



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: Thu, 29 Mar 2007 16:03:26 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: multiple inheritance and instance data?
Message-Id: <irROh.16205$PL.9389@newsread4.news.pas.earthlink.net>

On 03/29/2007 08:12 AM, bugbear wrote:
> I would like to have a class which has the behviour
> of 2 more primitive classes.
> 
> I have read up on inheritance, and constructors.
> 
> I understand how the @ISA tree is traversed
> to find methods.
> 
> http://perldoc.perl.org/perltoot.html
> 
> But I can't see, if BOTH parent classes
> have constructors that return a blessed
> object (e.g. a the typical hash reference),
> what I'm meant to do in my child
> class.
> 

You might not have to do anything.

> I think I'm just in trouble,
> and that I'm up against a reasonable
> limitation of Perl's object modelling,
> but I would welcome any help
> or insight.
> 
>    BugBear

The "new" method for the first class named in @INC will be invoked when 
you perform "MySubclass->new()"; if you are not adding any new 
functionality, you're finished.

If you do need new functionality, then what you do depends upon what you 
need. You didn't show any code, so I don't know what you really want to do.



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

Date: 29 Mar 2007 11:52:45 -0700
From: "Shiraz" <shirazk@gmail.com>
Subject: Perh Hash of Hash of Array structure
Message-Id: <1175194365.594234.246060@l77g2000hsb.googlegroups.com>

I am programing with a hash structure for a cache. The code is below.
The part dont understand, is that in the output why does "'prefix4' =>
$VAR2->{'key2'}{'key3'}{'class'}{'prefix5'}," show up unlike an array.
All the others show up as arrays but not this one. Does this mean that
i am making a wrong assignment? Is my code bad in the assignments? Or
is it just a display problem with the Data::Dumper module?

Thanks for any suggestions



=CODE=====================================
use strict;
use warnings;
use Data::Dumper;

my %acctMap=();

my @r = ( "fred", "barney", "pebbles", "bamm bamm", "dino"  );

%{$acctMap{'key1'}{'key2'}{'key3'}{'class'}} = (
    prefix1        => [ "george1", "jane2", "el3roy" ],
    prefix2        => [ "george", "jane", "elroy" ],
    prefix3        => [ "george", "jane", "elroy" ],
);

$acctMap{'key1'}{'key2'}{'key3'}{'class'}{'prefix4'} = \@r;
$acctMap{'key1'}{'key2'}{'key3'}{'class'}{'prefix5'} = \@r;
$acctMap{'key1'}{'key2'}{'key3'}{'class'}{'prefix6'} = \@r;

print Dumper(%acctMap);

exit;

=CODE=====================================



=OUTPUT=====================================
$VAR1 = 'key1';
$VAR2 = {
          'key2' => {
                      'key3' => {
                                  'class' => {
                                               'prefix5' => [
                                                              'fred',
 
'barney',
 
'pebbles',
                                                              'bamm
bamm',
                                                              'dino'
                                                            ],
                                               'prefix6' => $VAR2-
>{'key2'}{'key3'}{'class'}{'prefix5'},
                                               'prefix4' => $VAR2-
>{'key2'}{'key3'}{'class'}{'prefix5'},
                                               'prefix1' => [
 
'george1',
                                                              'jane2',
                                                              'el3roy'
                                                            ],
                                               'prefix3' => [
 
'george',
                                                              'jane',
                                                              'elroy'
                                                            ],
                                               'prefix2' => [
 
'george',
                                                              'jane',
                                                              'elroy'
                                                            ]
                                             }
                                }
                    }
        };
=OUTPUT=====================================



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

Date: Thu, 29 Mar 2007 19:47:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perh Hash of Hash of Array structure
Message-Id: <ZIUOh.28220$x9.25099@edtnps89>

Shiraz wrote:
> I am programing with a hash structure for a cache. The code is below.
> The part dont understand, is that in the output why does "'prefix4' =>
> $VAR2->{'key2'}{'key3'}{'class'}{'prefix5'}," show up unlike an array.

That is because $acctMap{key1}{key2}{key3}{class}{prefix4},
$acctMap{key1}{key2}{key3}{class}{prefix5} and
$acctMap{key1}{key2}{key3}{class}{prefix6} all point to the same array so
Data::Dumper can't create three separate arrays because there is only one
array so the other two point to that array.



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: Thu, 29 Mar 2007 21:57:27 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Perh Hash of Hash of Array structure
Message-Id: <460c1a21$0$20284$9b4e6d93@newsspool3.arcor-online.net>

Shiraz wrote:
> I am programing with a hash structure for a cache. The code is below.
> The part dont understand, is that in the output why does "'prefix4' =>
> $VAR2->{'key2'}{'key3'}{'class'}{'prefix5'}," show up unlike an array.
> All the others show up as arrays but not this one. Does this mean that
> i am making a wrong assignment? Is my code bad in the assignments? Or
> is it just a display problem with the Data::Dumper module?
> 
[snipped]
> =OUTPUT=====================================
> $VAR1 = 'key1';
> $VAR2 = {
>           'key2' => {
>                       'key3' => {
>                                   'class' => {
>                                                'prefix5' => [
>                                                               'fred',
>  
> 'barney',
>  
> 'pebbles',
>                                                               'bamm
> bamm',
>                                                               'dino'
>                                                             ],
>                                                'prefix6' => $VAR2-
>> {'key2'}{'key3'}{'class'}{'prefix5'},
>                                                'prefix4' => $VAR2-
>> {'key2'}{'key3'}{'class'}{'prefix5'},

What you see here is Data::Dumper's smartness. It dumps the values
in a form that they can be recreated as close as possible by eval()ing
the output.
prefix4, prefix5 and prefix6 all point to the same array ref, so it
needs only to get dumped once, while all the other instances can be
output as a valid hash entry that returns the same ref.

Maybe you should consider a simpler example:

my $value = "hello";

my %hash = (
	"a" => \$value,
	"b" => \$value
);

You could as well write this as:

my $value = "hello";

my %hash;
$hash{a} = \$value;
$hash{b} = $hash{a};

-Chris


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

Date: Thu, 29 Mar 2007 00:58:14 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Shifting Away
Message-Id: <please-E2EB76.00581429032007@free.teranews.com>

In article <57077cF2aa31qU1@mid.dfncis.de>,
 anno4000@radom.zrz.tu-berlin.de wrote:

> BTW, shift() as such doesn't stop you from changing a parameter.

That statement baffles me. Perhaps I'm missing something. Here's my 
understanding -- not to lecture, but please tell me where I run off the 
bridge.  

All in all -- as I've thanked this poster before -- I like the lvalue 
sub syntax if I'm going to set an actual param value. I've been 
sidestepping this issue for the most part because I'm writing object 
methods, which are *expected* to take an object (hash ref) as a param 
and tinker with the referent. 

* * *

@_ contains aliases to actual params -- the "stuff" supplied as params 
by the calling context. Thus, in: 

$, = " "; $\ = "\n";
$foo = 'goodstuff'; 
$bar = 'morestuff'; 
$error = dosomething($foo, $bar);
print $foo, $bar;

SUB1:
sub dosomething {
    $_[0] = 'bang';
    print $_[0], $_[1];
    return 0;
};

The literal 'bang' clobbers the calling context's value ('goodstuff') of 
$foo -- bug, feature, or sloppy coder, you decide. In essence, it's a 
call-by-reference but no dereffing is expected. Output reads:

bang morestuff
bang morestuff

 ... $bar is untouched. 

However: 

SUB2:
sub dosomething {
    my $stuff = shift; 
    $stuff = 'bang';
    print $_[0], $_[1], '\n';
    return 0;
};

Now nothing is clobbered; output reads: 

morestuff
goodstuff morestuff

 ... because shift -- implicitly, shift(@_) -- takes on the value of 
$_[0] and then makes $_[0] an alias to $bar, so: 

SUB3:
sub dosomething {
    my $stuff = shift; 
    $_[0] = 'bang';
    print $_[0], $_[1], '\n';
    return 0;
};

gives output: 

bang
goodstuff bang

The assignment inside the sub now clobbers $bar but $foo is untouched.

This will clobber neither $foo nor $bar: 

SUB4:
sub dosomething {
    my $stuff = shift;
    $_[1] = 'bang';
    print $_[0], $_[1];
    return 0;
};

Output: 

morestuff bang
goodstuff morestuff

Explanation being that at the time of shift-ing, $_[1] became undef -- 
and stayed that way until defined by literal assignment; the alias to 
$bar is lost. 

BTW: 

SUB5:
sub dosomething {
    @_ = ('bang', 'whimper');
    print $_[0], $_[1];
    return 0;
};

Output: 

bang whimper
goodstuff morestuff

Assigning to @_ itself, as opposed to a subscripted element, does *not* 
clobber the actual params. It has to be the whole bananna: 

SUB6:
sub dosomething {
    @_[0,1] = ('bang', 'whimper');
    print $_[0], $_[1];
    return 0;
};

Output: 

bang whimper
bang whimper

Array slice isn't good enough. 

* * *

I read an argument against using @_ even in the case of throwaway actual 
params; you don't care if they get clobbered. What if your caller 
doesn't read docs? 

Calling SUB1 with:  

$error = dosomething('nixon', 'agnew');

raises a fatal exception because attempting to assign to $_[0] is an 
attempt to assign to a literal. Calling SUB2 is fine. FWIW, even SUB4 
works okay; 'nixon' is shifted off and 'agnew' ducks the bullet. 

Naturally, this is no barrier to using @_ but it's a caution. ("Do I 
know what I'm doing? Okay then.")

* * *

So, it's my understanding that if I consistently shift off all my 
params, I *can't* clobber them. If I use $_[$n] then it's up to me 
either to keep it on the right side or deliberately clobber. If I mix 
shift and $_[$n] then I'd better *really* be careful because whether I 
want to clobber or not, I won't get what I want unless either I get 
lucky or pay close attention to what I'm doing. 

Of course, I can always shift all params and then proceed to assign 
freely to $_[$n] -- but then I'm just using it as a scratch variable. 

I suppose I can always test something, maybe assign a default to $_[$n], 
then later shift something off. But tell me honestly: If you knew I'd 
done that without good and sufficient reason, would you rush to switch 
off the machine when I got my fingers caught in the gears?
-- 
Xiong Changnian
xiong102ATxuefangDOTcom

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Thu, 29 Mar 2007 19:34:57 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Shifting Away
Message-Id: <BxUOh.20674$6z3.11150@edtnps82>

Xiong Changnian wrote:
> In article <57077cF2aa31qU1@mid.dfncis.de>,
>  anno4000@radom.zrz.tu-berlin.de wrote:
> 
>> BTW, shift() as such doesn't stop you from changing a parameter.
> 
> That statement baffles me. Perhaps I'm missing something. Here's my 
> understanding -- not to lecture, but please tell me where I run off the 
> bridge.  
> 
> All in all -- as I've thanked this poster before -- I like the lvalue 
> sub syntax if I'm going to set an actual param value. I've been 
> sidestepping this issue for the most part because I'm writing object 
> methods, which are *expected* to take an object (hash ref) as a param 
> and tinker with the referent. 
> 
> * * *
> 
> @_ contains aliases to actual params -- the "stuff" supplied as params 
> by the calling context. Thus, in: 
> 
> $, = " "; $\ = "\n";
> $foo = 'goodstuff'; 
> $bar = 'morestuff'; 
> $error = dosomething($foo, $bar);
> print $foo, $bar;

[ snip ]

> However: 
> 
> SUB2:
> sub dosomething {
>     my $stuff = shift; 
>     $stuff = 'bang';
>     print $_[0], $_[1], '\n';
>     return 0;
> };
> 
> Now nothing is clobbered; output reads: 
> 
> morestuff
> goodstuff morestuff

No, the output *should* read:

 morestuff \n
goodstuff morestuff


> ... because shift -- implicitly, shift(@_) -- takes on the value of 
> $_[0] and then makes $_[0] an alias to $bar, so: 
> 
> SUB3:
> sub dosomething {
>     my $stuff = shift; 
>     $_[0] = 'bang';
>     print $_[0], $_[1], '\n';
>     return 0;
> };
> 
> gives output: 
> 
> bang
> goodstuff bang

It *should* look more like:

bang  \n
goodstuff bang


I take it you didn't test this stuff?  :-)



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: Thu, 29 Mar 2007 21:52:23 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Shifting Away
Message-Id: <euhch3.1jc.1@news.isolution.nl>

Xiong Changnian schreef:

> The literal 'bang' clobbers the calling context's value ('goodstuff')
> of $foo -- bug, feature, or sloppy coder, you decide. In essence,
> it's a call-by-reference but no dereffing is expected.

You should stop making such statements until you understand why it is
like it is.
But even if you don't, I won't notice it, goodbye.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Thu, 29 Mar 2007 16:22:29 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: Troubleshooting cpan
Message-Id: <eugp45$mvp$2@reader2.panix.com>

In <460a02d3$0$6398$9b4e6d93@newsspool2.arcor-online.net> Christian Winter <thepoet_nospam@arcor.de> writes:

>kj wrote:
>> When I try to use the cpan command, attempts to fetch files (e.g.
>> 01mailrc.txt.gz) time out.  This happens in 2 out of the 3 machines
>> I've tried it on, all of which live in the same LAN and behind the
>> same firewall.  I can't figure out why cpan works in one of the
>> machines but not in the others.  The two "failing machines" are
>> entirely different (a SuSE Linux box and an iMac).  The machine
>> where cpan works is another SuSE Linux box.
>> 
>> More confusingly still, I can download 01mailrc.txt.gz from the
>> "failing machines" if I use wget, which rules out some major
>> connection problem.  Unfortunately, cpan does not emit any diagnostic
>> to explain why its attempts to download files time out.  Why would
>> cpan fail when wget succeeds on the same machine?

>Does the machine from which it works have, by any chance, either
>an environment variable FTP_PASSIVE set or the option
>"ftp_int_passive" enabled in libnet.cfg? If not, has it got
>an ftp_proxy environment setting that the others are missing?

Thanks.  FTP_PASSIVE is unset in the working machine, and I can't
find a file named libnet.cfg in it, but, be that as it may, setting
the ftp_int_passive option in the MyConfig.pm files of the failing
machines did the trick.

kj
-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

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


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