[29194] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 438 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 15 18:10:22 2007

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

Perl-Users Digest           Tue, 15 May 2007     Volume: 11 Number: 438

Today's topics:
    Re: Creating Packages <bik.mido@tiscalinet.it>
    Re: Creating Packages <thepoet_nospam@arcor.de>
    Re: Creating Packages <whoami@whereami.net>
    Re: FAQ 5.20 Why can't I just open(FH, ">file.lock")? <nobull67@gmail.com>
    Re: FAQ 5.20 Why can't I just open(FH, ">file.lock")? <bik.mido@tiscalinet.it>
    Re: FAQ 5.20 Why can't I just open(FH, ">file.lock")? <uri@stemsystems.com>
        how to create multiple zip files that are no larger tha <texasreddog@yahoo.com>
        Multiple substitutions with Regexp::Common? <adam@scan.mc.xerox.com>
    Re: Multiple substitutions with Regexp::Common? <mritty@gmail.com>
    Re: Net::SSH2 - Authentication without a password? <zentara@highstream.net>
    Re: Parsing a text file line-by-line: skipping badly-fo (Greg Bacon)
    Re: Parsing a text file line-by-line: skipping badly-fo denis.papathanasiou@gmail.com
    Re: Parsing a text file line-by-line: skipping badly-fo denis.papathanasiou@gmail.com
        running dot files <vnr1995@gmail.com>
    Re: running dot files usenet@DavidFilmer.com
    Re: running dot files <vnr1995@gmail.com>
        Using "Perl Best Practices" inside-out objects <mhearne808@gmail.com>
    Re: Using "Perl Best Practices" inside-out objects <mritty@gmail.com>
    Re: Using "Perl Best Practices" inside-out objects <mhearne808@gmail.com>
    Re: Using "Perl Best Practices" inside-out objects <mritty@gmail.com>
    Re: Using "Perl Best Practices" inside-out objects <cwilbur@chromatico.net>
    Re: Using "Perl Best Practices" inside-out objects <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 15 May 2007 17:07:45 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Creating Packages
Message-Id: <n3jj43djkvb66dsrqf7j2dgniloghve7gr@4ax.com>

On Tue, 15 May 2007 14:22:15 +0200, Christian Winter
<thepoet_nospam@arcor.de> wrote:

>> http://perlmonks.org/?node_id=592240
>
>The turials there aren't the newest and don't mention some
>newer developments. For anyone starting with Perl module development,

Are you a user there too? You may consider writing a tutorial or a
mini-tutorial yourself, with updated information. Unfortunately I
don't have the expertise to do so. Worse luck those documents are not
wiki-like...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 15 May 2007 17:21:12 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Creating Packages
Message-Id: <4649cfde$0$20289$9b4e6d93@newsspool3.arcor-online.net>

Michele Dondi wrote:
> On Tue, 15 May 2007 14:22:15 +0200, Christian Winter
> <thepoet_nospam@arcor.de> wrote:
> 
>>> http://perlmonks.org/?node_id=592240
>> The turials there aren't the newest and don't mention some
>> newer developments. For anyone starting with Perl module development,
> 
> Are you a user there too? You may consider writing a tutorial or a
> mini-tutorial yourself, with updated information. Unfortunately I
> don't have the expertise to do so. Worse luck those documents are not
> wiki-like...

Not yet, and I'm not sure if I'm aware of all the changes coming
with 5.10, though I'm trying to follow everything on p5p. Maybe
I'll find a few spare hours, with a long weekend coming up (Thursday's
a holiday here and hopefully I'll have Friday off), but no guarantees,
as I've got a lot of projects already waiting in the queue.
Though the updated information would be best placed into perlmodstyle
and perlnewmod.

-Chris


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

Date: Tue, 15 May 2007 23:03:32 +0100
From: "IanW" <whoami@whereami.net>
Subject: Re: Creating Packages
Message-Id: <f2dang$17it$1@energise.enta.net>


"Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message 
news:4648fd9e$0$26514$afc38c87@news.optusnet.com.au...

> I've only ever created the files manually. There is quite possibly some 
> work to be saved if one goes to the trouble of becoming familiar with one 
> of the automated procedures. I've never bothered doing that.
>
> I just manually create the files in the appropriate directory structure, 
> tar, gzip, and "Upload a file to CPAN" from the pause menu ( 
> https://pause.perl.org/pause/authenquery ).
>
> Best to first take a look at http://www.cpan.org/modules/04pause.html .

Thanks Rob. I've just been having a look at some of the recent (small) 
packages uploaded to see what they include. It does look like most people 
run at least ExtUtils::MakeMaker because there's a file META.yml that is 
apparently generated automatically by it.

Regards
Ian 




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

Date: 15 May 2007 10:51:14 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: FAQ 5.20 Why can't I just open(FH, ">file.lock")?
Message-Id: <1179251474.854681.103620@u30g2000hsc.googlegroups.com>

On May 13, 2:03 am, PerlFAQ Server <b...@stonehenge.com> wrote:

>             sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
>                     or die "can't open  file.lock: $!";

Why is it that in this day and age where we can put all sort of stuff
into the second argument of a 3-arg open we still need to resort to
sysopen() to ask for O_EXCL semantics?



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

Date: Tue, 15 May 2007 21:08:35 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 5.20 Why can't I just open(FH, ">file.lock")?
Message-Id: <681k435g97ftnll03vsf4p6ssplm70cqsl@4ax.com>

On 15 May 2007 10:51:14 -0700, Brian McCauley <nobull67@gmail.com>
wrote:

>>             sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
>>                     or die "can't open  file.lock: $!";
>
>Why is it that in this day and age where we can put all sort of stuff
>into the second argument of a 3-arg open we still need to resort to
>sysopen() to ask for O_EXCL semantics?

Although I fear the answer will be "patches welcome" as usual, ++ for
bringing this up. Good point!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 15 May 2007 19:53:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 5.20 Why can't I just open(FH, ">file.lock")?
Message-Id: <x7irat3lus.fsf@mail.sysarch.com>

>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:

  MD> On 15 May 2007 10:51:14 -0700, Brian McCauley <nobull67@gmail.com>
  MD> wrote:

  >>> sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
  >>> or die "can't open  file.lock: $!";
  >> 
  >> Why is it that in this day and age where we can put all sort of stuff
  >> into the second argument of a 3-arg open we still need to resort to
  >> sysopen() to ask for O_EXCL semantics?

  MD> Although I fear the answer will be "patches welcome" as usual, ++ for
  MD> bringing this up. Good point!

well, for one thing, perl's open is based on c's fopen and it doesn't
have an option for exclusive open either. you would need to add some new
character to the open mode that symbolizes exclusive open. i don't think
exclusive mode is used often enough (yes, i use sysopen myself for that)
that a new mode char is warranted. it is easy enough in most cases to
use sysopen if you want that. the only problem i have had with sysopen
is locating the flags (or faking them as needed) in the right modules in
order to support old versions of perl with File::Slurp.

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: 15 May 2007 12:40:55 -0700
From: texasreddog <texasreddog@yahoo.com>
Subject: how to create multiple zip files that are no larger than 2 Gb each
Message-Id: <1179258055.493419.325110@e51g2000hsg.googlegroups.com>

I have an interesting problem, where I am zipping up a large archive
of jpg images.  The zip file can be no larger than 2 Gb.  If I try to
zip up n number of images, where n can vary a lot, and if the zip file
gets to 2Gb, the zip process fails.

Would there be some way that I could track the .zip file as it is
being zipped, so when it reaches 2 Gb in size, a new zip file could be
created and the zip process could continue?  I don't think the split
command will work, because that runs after zip finishes.

Or, is there a way to possibly start another zip file, when the first
one fails, and then somehow force the zip to pick up where it left
off?

Any suggestions/ideas/tips are much appreciated!  Thanks!



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

Date: 15 May 2007 07:45:46 -0700
From: Adam <adam@scan.mc.xerox.com>
Subject: Multiple substitutions with Regexp::Common?
Message-Id: <1179240346.847180.84860@q75g2000hsh.googlegroups.com>

I've searched the web and the Regexp::Common docs and testsuite but
can't figure out how to do multiple substitutions (assuming it's
possible).  Obviously, in a normal Perl sub, I can do this:

$var =~ s/foo/blah/g;

I'm running Regexp::Common as such:

$msg = $RE{URI}{HTTP}{-scheme => "https?"}{-keep}->subs($msg =>
"XXX");

(I'm just playing around at the moment, hence the change to "XXX")

Any way to substitute ALL occurrences as the 'g' parameter does?
Thanks for any information.



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

Date: 15 May 2007 10:51:56 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Multiple substitutions with Regexp::Common?
Message-Id: <1179251516.061153.55520@o5g2000hsb.googlegroups.com>

On May 15, 10:45 am, Adam <a...@scan.mc.xerox.com> wrote:
> I've searched the web and the Regexp::Common docs and testsuite but
> can't figure out how to do multiple substitutions (assuming it's
> possible).  Obviously, in a normal Perl sub, I can do this:
>
> $var =~ s/foo/blah/g;
>
> I'm running Regexp::Common as such:
>
> $msg = $RE{URI}{HTTP}{-scheme => "https?"}{-keep}->subs($msg =>
> "XXX");
>
> (I'm just playing around at the moment, hence the change to "XXX")
>
> Any way to substitute ALL occurrences as the 'g' parameter does?
> Thanks for any information.

This may be a stupid question, but why not just use the normal syntax
rather than OOP?

$msg =~ s/$RE{URI}{HTTP}{-scheme=>"https?"}{-keep}/XXX/g;

Paul Lalli



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

Date: Tue, 15 May 2007 15:59:22 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Net::SSH2 - Authentication without a password?
Message-Id: <oulj43dol554ln0clqug24i8kl7qh86f3u@4ax.com>

On 14 May 2007 12:31:11 -0700, CsB <CSB001@gmail.com> wrote:

>I have installed Net::SSH2 installed and use it to connect to 90% of
>the networking equipment I need to access.  It works great, thank you
>to zentara for the suggestion.
>
>However, I'm trying to find a solution for one vendor that decided to
>be different from the others.
>
>For arguments sake, we'll call the vendor 'alpha'.
>
>Alpha equipment apparently requires an SSH login name but no password.

Does it use keys authorization?

>
>When I use SecureCRT to connect to one of the alpha boxes, (using
>Keyboard Interactive or Password as the authentication method) I am
>prompted for a username.  Once I enter the proper username, the SSH2
>session is established, a shell is started, and I am then presented
>with a new set of userid and password requests which are authenticated
>against our RADIUS servers.  It never prompts me for a password to
>accompany the initial username request.  I have confirmed (with the
>administrator of this equipment) that it doesn't require a password to
>establish the SSH2 session.
>
>I cannot find many examples of Net::SSH2 so I have struggled to find
>an answer.  While reading through the docs, I have tried various
>options including:
>
>$ssh2->auth_password( 'username' ) or die "Unable to login $@ \n";
>
>$ssh2->auth_password( 'username', '' ) or die "Unable to login $@ \n";
>
>$ssh2->auth_keyboard( 'username' ) or die "Unable to login $@ \n";
>
>$ssh2->auth_list( username );
>   (then checking the value of $ssh->auth_ok
>
>All have failed.  I cannot seem to figure out how to emulate the login
>process executed by SecureCRT.
>
>Any suggestions would be greatly appreciated.

I use this with success on my local box:

#get the password for the key
use Term::ReadKey;
print "And your key password: ";
ReadMode('noecho');
chomp(my $pass = ReadLine(0));
ReadMode('restore');
print "\n";
$ssh2->auth_publickey('z',
         '/home/z/.ssh/id_rsa.pub', #testing on localhost
         '/home/z/.ssh/id_rsa',
         $pass );


If you don't need a password for the key, maybe try setting
$pass to undef or ''.

# also see maillist  at
# http://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users
# for experts on the module

        
zentara

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


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

Date: Tue, 15 May 2007 18:04:57 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <134jti9lcg4tcbe@corp.supernews.com>

In article <1179228071.522961.169250@y80g2000hsf.googlegroups.com>,
     <denis.papathanasiou@gmail.com> wrote:

: I'd thought that using "eval { }; warn $@ if $@;" would do that, but
: since it didn't I'm asking here.

Which lines did you wrap in an eval?

Greg
-- 
Until these powers are restored -- and the Fed, the income tax, and
the Seventeenth Amendment abolished -- Americans have no hope of ever
returning to a regime of constitutional liberty.
    -- Thomas DiLorenzo


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

Date: 15 May 2007 13:09:10 -0700
From: denis.papathanasiou@gmail.com
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <1179259750.483378.83000@o5g2000hsb.googlegroups.com>


> : I'd thought that using "eval { }; warn $@ if $@;" would do that, but
> : since it didn't I'm asking here.
>
> Which lines did you wrap in an eval?

Initially, the entire file-handling block, i.e. from "open(IN,...) ...
close(IN);".

Since neither opening nor closing the file handle was the problem, I
tried putting the "while( $ln=<IN> ) { }" loop inside "eval{}; warn"
as well.

But the problem seems to be perl's <> construct: regardless of how I
define $/ (I used both the default and Josef's suggestion), if there's
an i/o error of any kind, the "$ln=<IN>" evaluates to false and the
loop ends.

So the way I solved the problem was to use a different file read
strategy: instead of using a line-by-line loader like <>, I load n
bytes at a time into a vector.

Since the file is fixed-width, I can treat the vector conceptually as
a 2d array and pull out any "line" I need.

Also, I can wrap the byte reads inside a condition-handler, so that
when I see the i/o error ("when", not "if" because the file *is*
corrupted), I can log the error lines, yet keep going all the way to
the end.

I wound up coding this in CL, not perl, though, because I couldn't
find any references to file reads in perl that did not involve the <>
construct, and also because the CL condition/exception handling logic
seems more robust than perl's.

If there's a way to do the same thing -- i.e., read byte blocks into a
vector, allowing for the possibility of an i/o error without stopping
-- in perl (and I'm sure there is), I'd be interested in learning how.



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

Date: 15 May 2007 13:15:47 -0700
From: denis.papathanasiou@gmail.com
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <1179260147.426576.299850@e65g2000hsc.googlegroups.com>


> open(my $in, '<', $IN_FILE) or die "\n\terror: Could not open $IN_FILE: $!";
> # I like that part after the \n\ ;-)

Ha! the unintended consequences of labeling and visible formatting
combinations!

> $/ = "\r\n";
> my $thowawayfirstline = <$in>;    # skip the header line
> # Here you could check if the header line looks like what you'd expect
> while (<$in>) {
>     # Process rest of data}
>
> close $in;
>
> If I can't get the processing to succeed, I usually print out the first
> line and stop:
>
> while (<$in>) {
>      print "$_\n"; last
>      # Process rest of data
>
> }
>
> Once I've figured out what's going on, I comment or delete that line.

The issue seems to be that perl's <> construct is that it stops (i.e.,
"while (<$in>)" evaluates to false) in the event of an i/o error
regardless of how $/ is defined.

And that's exactly what I *don't* want it to do (my last reply to Greg
has more details).



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

Date: 15 May 2007 12:05:13 -0700
From: heylow <vnr1995@gmail.com>
Subject: running dot files
Message-Id: <1179255913.110700.130760@e51g2000hsg.googlegroups.com>

Gurus,

I have a dot file that contains the following.


$pwd
/home/oracle
$cat .edp
export ORACLE_HOME=/home/oracle/product/10.2.0/db
export SID=EDP

I have one line perl script.

$cat 1.pl
#!/usr/local/bin/perl
 . ~/.edp

$./1.pl

syntax error at ./1.pl line 2, near "."
Execution of ./1.pl aborted due to compilation errors.


How to get rid of this error?

Thanks



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

Date: 15 May 2007 12:16:44 -0700
From: usenet@DavidFilmer.com
Subject: Re: running dot files
Message-Id: <1179256604.399914.149900@y80g2000hsf.googlegroups.com>

On May 15, 12:05 pm, heylow <vnr1...@gmail.com> wrote:
> export ORACLE_HOME=/home/oracle/product/10.2.0/db
> export SID=EDP

This is a shell environment configuration file.  Perl doesn't grok
such a file.  There are several possibilities to configure your
environment in Perl, including these:

You could source the file and then run the Perl program (all from a
bash script); the Perl program will inherit the shell's environment.
It's kinda ugly, but I do this with cron jobs - the cron invokes a
ksh, which sources the env and runs the Perl program.

Or you can import the settings using a module such as
Shell::EnvImporter (I've never tried this, but it looks like it ought
to do the trick):
   http://search.cpan.org/~dfaraldo/Shell-EnvImporter-1.04/lib/Shell/EnvImporter.pm

Or you can configure the environment directly in the Perl program:
   $ENV{'ORACLE_HOME'} = '/home/oracle/product/10.2.0/db';
   $ENV{SID} = 'EDP';

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: 15 May 2007 13:29:58 -0700
From: heylow <vnr1995@gmail.com>
Subject: Re: running dot files
Message-Id: <1179260998.397187.266930@n59g2000hsh.googlegroups.com>

On May 15, 3:16 pm, use...@DavidFilmer.com wrote:
> On May 15, 12:05 pm, heylow <vnr1...@gmail.com> wrote:
>
> > export ORACLE_HOME=/home/oracle/product/10.2.0/db
> > export SID=EDP
>
> This is a shell environment configuration file.  Perl doesn't grok
> such a file.  There are several possibilities to configure your
> environment in Perl, including these:
>
> You could source the file and then run the Perl program (all from a
> bash script); the Perl program will inherit the shell's environment.
> It's kinda ugly, but I do this with cron jobs - the cron invokes a
> ksh, which sources the env and runs the Perl program.
>
> Or you can import the settings using a module such as
> Shell::EnvImporter (I've never tried this, but it looks like it ought
> to do the trick):
>    http://search.cpan.org/~dfaraldo/Shell-EnvImporter-1.04/lib/Shell/Env...
>
> Or you can configure the environment directly in the Perl program:
>    $ENV{'ORACLE_HOME'} = '/home/oracle/product/10.2.0/db';
>    $ENV{SID} = 'EDP';
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)


Thank you.



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

Date: 15 May 2007 12:17:17 -0700
From: "mhearne808[insert-at-sign-here]gmail[insert-dot-here]com" <mhearne808@gmail.com>
Subject: Using "Perl Best Practices" inside-out objects
Message-Id: <1179256637.587826.308510@e51g2000hsg.googlegroups.com>

All:  I'm having trouble returning an array from a class implemented
using Damian Conway's inside-out object approach.

Below are two snippets of code:
1)  The test script where I am attempting to retrieve an array from an
inside-out attribute from an object.
2)  The test class.

I think the main problem is on the line where I am assigning an array
to one of these inside out attributes.  Somehow I think the attribute
is only getting the last element of the array that I am attempting to
assign it to.

I would have tested Conway's code verbatim, except that the
File::System->list_files() method in his text does not seem to exist.
I assume from context that list_files() returns an array of files...

Does anyone have (simple) examples of inside-out classes with a method
that returns an array?

#Test script
use PAGER::Test;
use strict;

my $test = PAGER::Test->new();
my @array = $test->getData();
my $n;
foreach $n (@array){
		print "$n\n";
}
#end of test script

#Test module
#!/usr/bin/perl

package MYPACKAGE::Test;
use Class::Std::Utils;
use strict;
{
		my %data;  #the absolute path where pager.pl is located

		sub new{
				my ($class) = @_;
				my $new_object = bless anon_scalar(),$class;
				$data{ident $new_object} = (1,2,3,4,5);
				return $new_object;
		}

		sub getData{
				my ($self) = @_;
				return @{$data{ident $self}};
		}

		sub DESTROY{
				my ($self) = @_;
				delete $data{ident $self};
				return;
		}
}
1;
#end of Test module



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

Date: 15 May 2007 12:35:18 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <1179257717.978469.116500@n59g2000hsh.googlegroups.com>

On May 15, 3:17 pm, "mhearne808[insert-at-sign-here]gmail[insert-dot-
here]com" <mhearne...@gmail.com> wrote:
> All:  I'm having trouble returning an array from a class implemented
> using Damian Conway's inside-out object approach.
>
> Below are two snippets of code:
> 1)  The test script where I am attempting to retrieve an array from an
> inside-out attribute from an object.
> 2)  The test class.
>
> I think the main problem is on the line where I am assigning an array
> to one of these inside out attributes.  Somehow I think the attribute
> is only getting the last element of the array that I am attempting to
> assign it to.

I snipped the class structure, because inside-out objects have nothing
at all to do with this problem.  Giant Red Herring.  The problem is
this line:

$data{ident $new_object} = (1,2,3,4,5);

If you print $data{ident $new_object}, you will see it contains the
value 5.  That is because you cannot assign a list of values to a
scalar.  What you're actually doing is using the comma operator in
scalar context.  (see perldoc perlop for more info on that).

Instead, you need to assign a reference to an anonymous array to that
scalar value.  The construct for creating such a reference is square
brackets, not parentheses.

$data{ident $new_object} = [ 1, 2, 3, 4, 5];

Once again, this has nothing to do with objects, be they 'normal' or
inside-out.  This is the same issue as if you had errantly done:

my $foo = (1, 2, 3, 4, 5);
In that case, $foo would get the value 5.  Whereas if you'd correctly
done:
my $foo = [1, 2, 3, 4, 5];
then $foo would get a reference to an anonymous array that contains
the values (1, 2, 3, 4, 5).

Hope this helps,
Paul Lalli



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

Date: 15 May 2007 12:44:58 -0700
From: "mhearne808[insert-at-sign-here]gmail[insert-dot-here]com" <mhearne808@gmail.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <1179258298.007568.284710@w5g2000hsg.googlegroups.com>

Paul - Thanks very much!  I didn't know about the [] syntax for
creating references to arrays.  I presume now that the mythical
list_files() method returns a reference to an array, not an array.
Might have been helpful if Conway had used a real method in his
example.

--Mike

On May 15, 1:35 pm, Paul Lalli <mri...@gmail.com> wrote:
> On May 15, 3:17 pm, "mhearne808[insert-at-sign-here]gmail[insert-dot-
>
> here]com" <mhearne...@gmail.com> wrote:
> > All:  I'm having trouble returning an array from a class implemented
> > using Damian Conway's inside-out object approach.
>
> > Below are two snippets of code:
> > 1)  The test script where I am attempting to retrieve an array from an
> > inside-out attribute from an object.
> > 2)  The test class.
>
> > I think the main problem is on the line where I am assigning an array
> > to one of these inside out attributes.  Somehow I think the attribute
> > is only getting the last element of the array that I am attempting to
> > assign it to.
>
> I snipped the class structure, because inside-out objects have nothing
> at all to do with this problem.  Giant Red Herring.  The problem is
> this line:
>
> $data{ident $new_object} = (1,2,3,4,5);
>
> If you print $data{ident $new_object}, you will see it contains the
> value 5.  That is because you cannot assign a list of values to a
> scalar.  What you're actually doing is using the comma operator in
> scalar context.  (see perldoc perlop for more info on that).
>
> Instead, you need to assign a reference to an anonymous array to that
> scalar value.  The construct for creating such a reference is square
> brackets, not parentheses.
>
> $data{ident $new_object} = [ 1, 2, 3, 4, 5];
>
> Once again, this has nothing to do with objects, be they 'normal' or
> inside-out.  This is the same issue as if you had errantly done:
>
> my $foo = (1, 2, 3, 4, 5);
> In that case, $foo would get the value 5.  Whereas if you'd correctly
> done:
> my $foo = [1, 2, 3, 4, 5];
> then $foo would get a reference to an anonymous array that contains
> the values (1, 2, 3, 4, 5).
>
> Hope this helps,
> Paul Lalli




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

Date: 15 May 2007 12:49:49 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <1179258589.669198.161380@l77g2000hsb.googlegroups.com>

On May 15, 3:44 pm, "mhearne808[insert-at-sign-here]gmail[insert-dot-
here]com" <mhearne...@gmail.com> wrote:
>
> On May 15, 1:35 pm, Paul Lalli <mri...@gmail.com> wrote:
>
> > On May 15, 3:17 pm, "mhearne808[insert-at-sign-here]gmail[insert-dot-
>
> > here]com" <mhearne...@gmail.com> wrote:
> > > All:  I'm having trouble returning an array from a class implemented
> > > using Damian Conway's inside-out object approach.
>
> > > Below are two snippets of code:
> > > 1)  The test script where I am attempting to retrieve an array from an
> > > inside-out attribute from an object.
> > > 2)  The test class.
>
> > > I think the main problem is on the line where I am assigning an array
> > > to one of these inside out attributes.  Somehow I think the attribute
> > > is only getting the last element of the array that I am attempting to
> > > assign it to.
>
> > I snipped the class structure, because inside-out objects have nothing
> > at all to do with this problem.  Giant Red Herring.  The problem is
> > this line:
>
> > $data{ident $new_object} = (1,2,3,4,5);
>
> > If you print $data{ident $new_object}, you will see it contains the
> > value 5.  That is because you cannot assign a list of values to a
> > scalar.  What you're actually doing is using the comma operator in
> > scalar context.  (see perldoc perlop for more info on that).
>
> > Instead, you need to assign a reference to an anonymous array to that
> > scalar value.  The construct for creating such a reference is square
> > brackets, not parentheses.
>
> > $data{ident $new_object} = [ 1, 2, 3, 4, 5];
>
> > Once again, this has nothing to do with objects, be they 'normal' or
> > inside-out.  This is the same issue as if you had errantly done:
>
> > my $foo = (1, 2, 3, 4, 5);
> > In that case, $foo would get the value 5.  Whereas if you'd correctly
> > done:
> > my $foo = [1, 2, 3, 4, 5];
> > then $foo would get a reference to an anonymous array that contains
> > the values (1, 2, 3, 4, 5).

> Paul - Thanks very much!  I didn't know about the [] syntax for
> creating references to arrays.

You need to review a bunch of perliminary Perl information before you
start tackling objects (of any flavor).  Please pause for a few
minutes and read:
perldoc perlreftut
perldoc perllol
perldoc perldsc

>  I presume now that the mythical
> list_files() method returns a reference to an array, not an array.

Not necessarily.  You can return an array from a subroutine just fine.

sub foo {
   my $ref = [ 1, 2, 3, 4, 5 ];
   return @{$ref};
}

my @stuff = foo();

> Might have been helpful if Conway had used a real method in his
> example.

I have no idea what "example" you're talking about.  Can you give a
pointer to it?  Is it in PBP?  What chapter/page?  Or is it online
somewhere?

Paul Lalli



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

Date: 15 May 2007 16:04:47 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <87k5v9j1k0.fsf@mithril.chromatico.net>

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

    PL> You need to review a bunch of perliminary Perl information

Great typo!

Charlton
 

-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Tue, 15 May 2007 23:32:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <8l9k43lfi9eapmahloljl1kge07g0nkd0o@4ax.com>

On 15 May 2007 16:04:47 -0400, Charlton Wilbur
<cwilbur@chromatico.net> wrote:

>    PL> You need to review a bunch of perliminary Perl information
>
>Great typo!

I (tend to) do it all the time. In Italian 'for' is 'per' and can be
followed by a word beginning with 'l', typically a determinative
article. Imagine what happens when I write "per la miseria!"


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

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


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