[30538] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1781 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 9 03:09:43 2008

Date: Sat, 9 Aug 2008 00:09:08 -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           Sat, 9 Aug 2008     Volume: 11 Number: 1781

Today's topics:
    Re: CLPM - a help group? <worrall+unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall+unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall+unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall+unet@cs.bris.ac.uk>
        interesting behavior for Perl and Postgres <cartercc@gmail.com>
    Re: interesting behavior for Perl and Postgres <ben@morrow.me.uk>
    Re: Need help with perlxs and C strings <ben@morrow.me.uk>
        new CPAN modules on Sat Aug  9 2008 (Randal Schwartz)
        Newbie: Replacing double newlines <nospam_here@videotron.ca>
    Re: Newbie: Replacing double newlines <ben@morrow.me.uk>
    Re: Newbie: Replacing double newlines <benkasminbullock@gmail.com>
    Re: Newbie: Replacing double newlines <tadmc@seesig.invalid>
    Re: Trying to understand a constructor with an array. <nowhere@nowhere.com>
    Re: Trying to understand a constructor with an array. <nowhere@nowhere.com>
    Re: Trying to understand a constructor with an array. <mjcarman@mchsi.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 08 Aug 2008 18:30:53 -0700
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <%s6nk.6642$np7.4378@flpi149.ffdc.sbc.com>

Charlton Wilbur wrote:
>>>>>> "AW" == Adam Worrall <worrall+unet@cs.bris.ac.uk> writes:
> 
>     AW> Why is it you and various others who support your side can
>     AW> assert what is and isn't right yet when you see someone else
>     AW> doing the same for the opposite for what you believe, it is
>     AW> suddenly wrong? Why the double standard?
> 
> Because Tad and the "various others who support [his] side" are people
> who have spent years posting to clpm and who are responsible, in part
> for making it what it is; 

Yes, they are exactly responsible for making this ng into what it was 
become...

> and you appear, as near as I can tell, to just have shown up for 
 > this particular thread.

No, I've been around but in recent years I have refrained from checking 
this group for the same reasons many other good people stopped.

   - Adam


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

Date: Fri, 08 Aug 2008 18:37:23 -0700
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <6z6nk.6643$np7.2450@flpi149.ffdc.sbc.com>

Ron Bergin wrote:
> On Aug 7, 10:31 am, Adam Worrall <worrall+u...@cs.bris.ac.uk> wrote:
>> RedGrittyBrick wrote:
>>> Adam Worrall wrote:
>>>> RedGrittyBrick wrote:
>>>>> Adam Worrall wrote:
>>>>> When I say "the sky is blue" it is an observation, I am not
>>>>> legislating what the sky may or may not do.
>>>> But it is a known fact that the sky is blue,
>>> Today it is grey.
>> The clouds are grey, the sky is still blue.
>>
> I hope that you don't apply that same type of "logic" and observation
> to your programing.  If you do, then you're a really poor programmer.

Actually, I find appropriately attributing aspects of a given object to 
where they belong to be a vital virtue.

> Right now the sky above me is "black", and at other times I see a
> redish-orange sky.  

Ok, true, but that's an actual color of the sky. When it's cloudy, it's 
the cloud's color you see, not the sky's. When you look at a brilliant 
sun-set, that _is_ the color of the sky at that given time.

> If you didn't know and refuse to see that the sky can appear as 
 > different colors,

I never said it couldn't be different colors. Don't mix things like this.

> then you will never be able to see that CLPM is not a helpdesk.

Once again, it depends on what kind of help desk. It happens to function 
as a voluntary (or volunteer) type of help desk, and I know this from 
personal experience having participated on one.

   - Adam


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

Date: Fri, 08 Aug 2008 18:40:37 -0700
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <8C6nk.6645$np7.1021@flpi149.ffdc.sbc.com>

RedGrittyBrick wrote:
> Adam Worrall wrote:
> 
> <rant omitted>
> 
> According to Google Groups you've made no contribution to this newsgroup 
> in the last decade. You now pop up and your only action is to start 
> telling regular contributors how they should be behaving.

On the contrary, I did no such thing. I commented on my dislike for the 
regular contributors stance that they take that unless we do as _they_ 
say, we are not part of the "community." And I have good reasons for 
leaving this news group years ago. People like you and the "regular 
contributors" make it very clear why many good people left this group.

   - Adam


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

Date: Fri, 08 Aug 2008 18:48:53 -0700
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <aI6nk.20970$N87.1481@nlpi068.nbdc.sbc.com>

Charlton Wilbur wrote:
>>>>>> "AW" == Adam Worrall <worrall+unet@cs.bris.ac.uk> writes:
> 
>     >> But no matter. You're just another shithead who won't be around
>     >> in a year when I'm still answering questions and helping people.
> 
>     AW> I would expect you, the FAQ maintainer of all people, to present
>     AW> yourself in the way you yourself would like to be treated,
>     AW> rather than attempting to refute an argument with a "fuck you."
> 
> Were you making an actual argument, rather than simply a ludicrous and
> insulting attempt at proof by repeated assertion, you might be
> correct.

Are you kidding me? I was entirely civil. I presented my argument. I 
haven't simply repeated myself (but sometimes when it falls on death 
ears one has little recourse than to repeat themselves at some level.)

I'm not the one who replied, displaying argumentative skills of a 10 
year old. I've seen more intelligent rebuttals from Paris Hilton for 
pete's sake.

   - Adam


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

Date: Fri, 8 Aug 2008 15:34:41 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: interesting behavior for Perl and Postgres
Message-Id: <9fcf01e1-bf8c-47ea-bc45-b81ee97fd244@m36g2000hse.googlegroups.com>

Can anyone tell me why this happens? Here is the code, the console
output, and the results.

First, the code. This copies data from five external files into
(empty) tables in my database:

eval
{
    system('psql -U studentinfo -d studentinfo -c "\\copy student08t5
from \'/home/studentinfo/data/import_student.csv\' using delimiters \'|
\' "') or warn "I could not copy STUDENT file to table, $!";
    system('psql -U studentinfo -d studentinfo -c "\\copy section08t5
from \'/home/studentinfo/data/import_section.csv\' using delimiters \'|
\' "') or warn "I could not copy SECTION file to table, $!";
    system('psql -U studentinfo -d studentinfo -c "\\copy phone08t5
from \'/home/studentinfo/data/import_phone.csv\' using delimiters \'|
\' "') or warn "I could not copy PHONE file to table, $!";
    system('psql -U studentinfo -d studentinfo -c "\\copy email08t5
from \'/home/studentinfo/data/import_email.csv\' using delimiters \'|
\' "') or warn "I could not copy EMAIL file to table, $!";
    system('psql -U studentinfo -d studentinfo -c "\\copy address08t5
from \'/home/studentinfo/data/import_address.csv\' using delimiters \'|
\' "') or warn "I could not copy ADDRESS file to table, $!";
};
warn $@ if $@;

Next, the output. This is what is printed to the console when I run
the script:

[studentinfo@tsuse data]$ perl test02.plx
I could not copy STUDENT file to table, No such file or directory at
test02.plx line 24.
I could not copy SECTION file to table, No such file or directory at
test02.plx line 25.
I could not copy PHONE file to table, No such file or directory at
test02.plx line 26.
I could not copy EMAIL file to table, No such file or directory at
test02.plx line 27.
I could not copy ADDRESS file to table, No such file or directory at
test02.plx line 28.
[studentinfo@tsuse data]$

Finally, the results. Well, I won't bore you with the results (the
files contain about 21,000 records) but this successfully writes the
data to the database.

Question: Why do the warn statements print if the copy command works?

CC


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

Date: Sat, 9 Aug 2008 00:15:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: interesting behavior for Perl and Postgres
Message-Id: <jl0vm5-gre.ln1@osiris.mauzo.dyndns.org>


Quoth cartercc <cartercc@gmail.com>:
> Can anyone tell me why this happens? Here is the code, the console
> output, and the results.
> 
> First, the code. This copies data from five external files into
> (empty) tables in my database:
> 
> eval
> {
>     system('psql -U studentinfo -d studentinfo -c "\\copy student08t5
> from \'/home/studentinfo/data/import_student.csv\' using delimiters \'|
> \' "') or warn "I could not copy STUDENT file to table, $!";

system returns 0 if the command succeeds, so your 'or' is the wrong
test. $! is only valid after a syscall has failed, so it will contain
something completely irrelevant here: the ENOENT you get is probably the
result of searching $PATH for psql.

Correctly determining if and why system failed is rather tricky: there
are lots of failure modes, and on some systems (notably Win32) some of
them actually report success. I would suggest using a module, like
IPC::Run or IPC::System::Simple.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Fri, 8 Aug 2008 23:33:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Need help with perlxs and C strings
Message-Id: <p6uum5-9vc.ln1@osiris.mauzo.dyndns.org>


Quoth Thomas <th@example.invalid>:
> xhoster@gmail.com wrote:
> 
> > Yep, I was just exploring that option.  In my first attempt I had to copy
> > the .h file into the __C__ section.  But then I got it to "source" the .h
> > directly:
> > 
> > use Inline 'C' => qq{#include "setdata.c"\n} . `cat setdata.h`
> >                => ENABLE => 'AUTOWRAP';
> > 
> > And it works fine.
> 
> I have to interface with compiled C code. I got Inline C to work (ran 
> the http://search.cpan.org/dist/Inline/C/C-Cookbook.pod#Hello,_world 
> sample program successfully), but my modified version of runme.pl 
> doesn't seem to recognize where the compiled object file of setdata.c is 
> located. I followed the example at 
> http://search.cpan.org/dist/Inline/C/C-Cookbook.pod#Automatic_Function_Wrappers 
> and came up with this:
> 
> == runme.pl
> use Inline C => Config =>
>                 ENABLE => AUTOWRAP =>
>                 LIBS => "-L. -lsetdata";
> use Inline C => q{ void set_data(char *); };
> 
> my $x="xxxxxxxx";
> set_data($x);
> print "Data from C function:\n$x";
> ==
> 
> The compiled version of setdata.c (setdata.obj) is placed in the same 

-lsetdata is looking for a *library*, not an object file. On Win32 it
would probably be called setdata.lib, and made from setdata.obj using
LIB.EXE. 

Alternatively, you could try

    LIBS => "-L. setdata.obj"

or even

    LIBS => '-L. setdata$(OBJ_EXT)'

for portability (but I don't know how much of MakeMaker Inline::C uses:
try it and see).

> I have to add that I use nmake and cl as compiler and link as linker 
> under Windows. The information from LIBS never seems to get included (I 
> only know the -l<lib> syntax from Unix, it may be the problem; I don't 
> know the alternative). I'd appreciate any further help on how to get 
> this running.

It is the correct syntax on Win32 as well (fortunately, since Microsoft
in there great wisdom have renamed -lfoo from libfoo.a to foo.lib), but
for libraries.

Note that the information in LIBS is considered 'optional': MM will link
the libraries if it can find them, and not if it can't.

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.                                                   ben@morrow.me.uk


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

Date: Sat, 9 Aug 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sat Aug  9 2008
Message-Id: <K5BH2L.1oFz@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Apache-SWIT-0.37
http://search.cpan.org/~bosu/Apache-SWIT-0.37/
mod_perl based application server with integrated testing. 
----
Apache-SWIT-Security-0.03
http://search.cpan.org/~bosu/Apache-SWIT-Security-0.03/
security subsystem for Apache::SWIT 
----
Apache-Session-1.87
http://search.cpan.org/~chorny/Apache-Session-1.87/
A persistence framework for session data 
----
App-ZofCMS-Plugin-Comments-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-Comments-0.0101/
drop-in visitor comments support. 
----
App-ZofCMS-Test-Plugin-0.0104
http://search.cpan.org/~zoffix/App-ZofCMS-Test-Plugin-0.0104/
test module for testing ZofCMS plugins 
----
CPAN-Mini-Webserver-0.33
http://search.cpan.org/~lbrocard/CPAN-Mini-Webserver-0.33/
Search and browse Mini CPAN 
----
CPAN-Mini-Webserver-0.34
http://search.cpan.org/~lbrocard/CPAN-Mini-Webserver-0.34/
Search and browse Mini CPAN 
----
Catalyst-Controller-FlashRemoting-0.02
http://search.cpan.org/~typester/Catalyst-Controller-FlashRemoting-0.02/
Catalyst controller for Flash Remoting 
----
Class-Member-1.6
http://search.cpan.org/~opi/Class-Member-1.6/
A set of modules to make the module developement easier 
----
Config-Simple-Extended-0.06
http://search.cpan.org/~hesco/Config-Simple-Extended-0.06/
Extend Config::Simple w/ Configuration Inheritance, chosen by URL 
----
DBIx-Class-QueryLog-1.1.1
http://search.cpan.org/~gphat/DBIx-Class-QueryLog-1.1.1/
Log queries for later analysis. 
----
DBIx-ContentChecksum-mysql-1.0
http://search.cpan.org/~cjones/DBIx-ContentChecksum-mysql-1.0/
Extension to DBIx::ContentChecksum, enables more detailed comparison of MySQL databases. 
----
Data-Plist-0.1
http://search.cpan.org/~kyoki/Data-Plist-0.1/
object representing a property list 
----
Getopt-Chain-0.001_1
http://search.cpan.org/~rkrimen/Getopt-Chain-0.001_1/
svn- and git-style option and subcommand processing 
----
Getopt-Chain-0.001_2
http://search.cpan.org/~rkrimen/Getopt-Chain-0.001_2/
svn- and git-style option and subcommand processing 
----
HTML-TurboForm-0.24
http://search.cpan.org/~camelcase/HTML-TurboForm-0.24/
----
HTTP-Server-Simple-Bonjour-0.02
http://search.cpan.org/~miyagawa/HTTP-Server-Simple-Bonjour-0.02/
Bonjour plugin for HTTP::Server::Simple 
----
IO-Lambda-0.24
http://search.cpan.org/~karasik/IO-Lambda-0.24/
non-blocking I/O in lambda style 
----
Module-Extract-Namespaces-0.11_01
http://search.cpan.org/~bdfoy/Module-Extract-Namespaces-0.11_01/
extract the package declarations from a module 
----
Module-Install-0.77
http://search.cpan.org/~adamk/Module-Install-0.77/
Standalone, extensible Perl module installer 
----
MooseX-DOM-0.00001
http://search.cpan.org/~dmaki/MooseX-DOM-0.00001/
Simplistic Object XML Mapper 
----
Net-Zemanta-0.2
http://search.cpan.org/~avian/Net-Zemanta-0.2/
----
ORLite-0.10
http://search.cpan.org/~adamk/ORLite-0.10/
Extremely light weight SQLite-specific ORM 
----
OpenVZ-BC-0.01
http://search.cpan.org/~wilsond/OpenVZ-BC-0.01/
Perl access to OpenVZ Beancounter Data 
----
Padre-0.04
http://search.cpan.org/~szabgab/Padre-0.04/
Perl Application Development and Refactoring Environment 
----
Remote-Use-0.02
http://search.cpan.org/~casiano/Remote-Use-0.02/
Using modules from a remote server 
----
Scalar-Defer-0.17
http://search.cpan.org/~jesse/Scalar-Defer-0.17/
Lazy evaluation in Perl 
----
Squatting-0.52
http://search.cpan.org/~beppu/Squatting-0.52/
A Camping-inspired Web Microframework for Perl 
----
Sub-Nary-0.03
http://search.cpan.org/~vpit/Sub-Nary-0.03/
Try to count how many elements a subroutine can return in list context. 
----
Template-Toolkit-2.19_02
http://search.cpan.org/~abw/Template-Toolkit-2.19_02/
Template Processing System 
----
Test-Aggregate-0.32_04
http://search.cpan.org/~ovid/Test-Aggregate-0.32_04/
Aggregate *.t tests to make them run faster. 
----
Unix-Process-1.31
http://search.cpan.org/~jettero/Unix-Process-1.31/
Perl extension to get pid info from (/bin/ps). 
----
WWW-Favicon-0.03001
http://search.cpan.org/~typester/WWW-Favicon-0.03001/
perl module to detect favicon url 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Fri, 08 Aug 2008 18:37:27 -0400
From: Jensen <nospam_here@videotron.ca>
Subject: Newbie: Replacing double newlines
Message-Id: <jV3nk.6808$II.4935@weber.videotron.net>

Hello:

This works for me to replace single newline characters with spaces:

perl -pe 's/\n/ /g' test2

in a file.

However, when I want to replace just the double newlines (two of them in 
sequence), with:

perl -pe 's/\n\n/ /g' test2

it doesn't work. Same if I'm using \012 for the newline (shown by the od 
command in UNIX).

And they're there, I see them with say:

od -cb test2

or with OpenOffice or other editors.

What gives?

Thanks.


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

Date: Sat, 9 Aug 2008 00:17:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Newbie: Replacing double newlines
Message-Id: <bp0vm5-gre.ln1@osiris.mauzo.dyndns.org>


Quoth Jensen <nospam_here@videotron.ca>:
> Hello:
> 
> This works for me to replace single newline characters with spaces:
> 
> perl -pe 's/\n/ /g' test2
> 
> in a file.
> 
> However, when I want to replace just the double newlines (two of them in 
> sequence), with:
> 
> perl -pe 's/\n\n/ /g' test2
> 
> it doesn't work. Same if I'm using \012 for the newline (shown by the od 
> command in UNIX).

-p reads files line-by-line by default, so no one line will ever contain
two newline characters. Try

    perl -0777 -pe 's/\n\n/ /g' test2

-0777 is equivalent to BEGIN { $/ = undef }: see perlrun.

Ben

-- 
You poor take courage, you rich take care:
The Earth was made a common treasury for everyone to share
All things in common, all people one.
'We come in peace'---the order came to cut them down.       [ben@morrow.me.uk]


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

Date: Sat, 9 Aug 2008 01:26:47 +0200 (CEST)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Newbie: Replacing double newlines
Message-Id: <g7iknm$co6$1@aioe.org>

On Fri, 08 Aug 2008 18:37:27 -0400, Jensen wrote:

> Hello:
> 
> This works for me to replace single newline characters with spaces:
> 
> perl -pe 's/\n/ /g' test2
> 
> in a file.
> 
> However, when I want to replace just the double newlines (two of them in 
> sequence), with:
> 
> perl -pe 's/\n\n/ /g' test2
> 
> it doesn't work. 

This reads it line by line, so since there isn't a single line with two \n
on it, it doesn't work.

The best solution I could think of for your problem was something like this:

 perl -pe's/\n/\\n/g' test.txt|perl -pe 's/(\\n){2,}/\\n/g' | perl -pe 's/\\n/\n/g'

Here I'm assuming that you didn't really want to turn \n\n into a space.

But someone else can probably do it better than that.


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

Date: Fri, 8 Aug 2008 18:47:58 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Newbie: Replacing double newlines
Message-Id: <slrng9pmpe.ic2.tadmc@tadmc30.sbcglobal.net>

Jensen <nospam_here@videotron.ca> wrote:
> Hello:
>
> This works for me to replace single newline characters with spaces:
>
> perl -pe 's/\n/ /g' test2
>
> in a file.
>
> However, when I want to replace just the double newlines (two of them in 
> sequence), with:
>
> perl -pe 's/\n\n/ /g' test2
>
> it doesn't work.


Of course not. 

Have you read the documentation for the switches you are using?

   perldoc perlrun

        causes Perl to assume the following loop around your program, which
        makes it iterate over filename arguments somewhat like B<sed>:
        
        
          LINE:
            while (<>) {
                ...             # your program goes here
            } continue {
                print or die "-p destination: $!\n";
            }


( While you are in perlrun, have a look at the -0 (zero) switch also. )


> What gives?


Your program never has more than one line in $_, so it cannot possibly
match a multiline string.


   perldoc -q

        I'm having trouble matching over more than one line.  What's wrong?


If the file is small enough to fit in memory, then:

   perl -0777pe 's/\n\n/ /g' test2


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Fri, 08 Aug 2008 20:12:01 -0500
From: Overt <nowhere@nowhere.com>
Subject: Re: Trying to understand a constructor with an array.
Message-Id: <6tWdnchN1_p8cwHVnZ2dnUVZ_hKdnZ2d@oco.net>

Thanks for all the replies, everyone.  I am going through them one by
one and trying to corrilate them with what I am trying and what I am
getting.

Thanx 
Overt


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

Date: Fri, 08 Aug 2008 21:00:58 -0500
From: Overt <nowhere@nowhere.com>
Subject: Re: Trying to understand a constructor with an array.
Message-Id: <q8mdnXbuPZvHZwHVnZ2dnUVZ_uCdnZ2d@oco.net>

> I think what you want to do is:
> 
> my $self = [ @{+shift} ];
> 

Thank you. That fixed it. After the constructor executes with ...

my $displayobj = Display->new(\@tarray);

sub new {
	$DB::single = 1;
 	my $class = shift;
	my $self = [ @{+shift} ];
  	bless($self, $class);
 	return $self;
}

 ... $self has the normal multi-element array that it is called with and
that I wanted.



I would not have discovered it on my own (at least for a long while),
because I can't find that construction in any of my documentation.  I am
using Programming Perl, Perl Cookbook and Dan Conways Perl Object manual,
plus about a dozen more (mostly useless) that I picked up on the discount
bookshelf at Books-a-Million.  Plus the PerlDocs on my system.

Note that I say I can't find it - not that I say it isn't there.

Now the important questions. 
I am just a hobbyist programmer (so far), but where do you learn this type
of info?  I keep tripping across neat stuff like the above and wonder just
how many zillions of other good items that I will never learn and can't
use because I don't know they exist. Possibly you went to a professional
school to learn.

Googling mostly gets the same basic Perl OOP stuff over and over (and
over and over ad nauseum) that is in all the books.  Then the few hits left
are usually so far out that I don't even understand what they are trying
to do.  I can't seem to locate a resource that carries on from basic OOP
knowledge into the intermediate levels.

Mucho thanks again.
Overt


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

Date: Sat, 09 Aug 2008 03:32:14 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Trying to understand a constructor with an array.
Message-Id: <2d8nk.235298$TT4.174420@attbi_s22>

Overt wrote:
>> 
>> my $self = [ @{+shift} ];
> 
> I would not have discovered it on my own (at least for a long while),
> because I can't find that construction in any of my documentation.

That's probably because it's not one construct but several written together:

* The [...] creates a reference to an anonymous array. This is what
  gets assigned to $self.
* The @{...} is an array dereference.
* The shift() function removes and returns the first element from an
  array. If no array is specified (and you're inside a subroutine) it
  operates on @_.
* @_ is the array used to pass arguments to subs.
* The + is the unary sign operator. It forces the "shift" to be
  interpreted as a function call instead of as a bareword. Without it
  the expression would parse as the array @shift instead of as
  @{ shift(@_) }

Personally, I wouldn't write it this way, because I think it's very
obscure. I would write

  my $self = shift;

as Peter suggested. You could add a check for C<ref($self) eq 'ARRAY'>
if you share Leon's concern and want to ensure that the user didn't pass
in the wrong thing as an argument.

> I am just a hobbyist programmer (so far), but where do you learn this
> type of info?

The best way to learn is by doing. Keep programming and keep learning
new things as you go. I learned gobs of Perl by lurking in this
newsgroup. Read the docs. Read (good) books. Whenever you see something
new, try to understand it and think of how and where you might use it.
Go back to your old code and rewrite it as you learn new and better idioms.

> I keep tripping across neat stuff like the above and wonder just how
> many zillions of other good items that I will never learn and can't
> use because I don't know they exist.

I don't know. I've been using Perl for more than a decade and I still
learn new things occasionally. There are some dusty corners that I've
never really had a reason to explore.

> Possibly you went to a professional school to learn.

Some of the people here have had a formal education in computer science,
but I don't think many have had formal schooling in Perl. There are
training courses though, and many of the more prominent posters here
teach them.

-mjc


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

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


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