[30186] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1429 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 7 14:10:16 2008

Date: Mon, 7 Apr 2008 11: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           Mon, 7 Apr 2008     Volume: 11 Number: 1429

Today's topics:
    Re: About perl closure. xhoster@gmail.com
    Re: Create two-dimensional Array from string <pjfalbe@gmail.com>
        funzy.com http://geocities.com/it_super_manager/ it_super_manager@hotmail.com
    Re: Looking for GT::CGI and GT::Template <alexchorny@gmail.com>
    Re: mismatch between Perl 5.6 and Perl 5.8 in printing  <sisyphus359@gmail.com>
    Re: perl should be improved and perl6 <O_TEXT@nospam.fr>
    Re: perl should be improved and perl6 <abigail@abigail.be>
    Re: perl should be improved and perl6 (aka ? the Platypus)
    Re: perl should be improved and perl6 (aka ? the Platypus)
    Re: perl should be improved and perl6 <abigail@abigail.be>
    Re: perl should be improved and perl6 <get@bentsys.com>
    Re: perl should be improved and perl6 <get@bentsys.com>
    Re: perl should be improved and perl6 <1usa@llenroc.ude.invalid>
    Re: Returning a dataset with arrays <alexchorny@gmail.com>
    Re: Shortcut for if(defined($var) && $var ne "") ? <abigail@abigail.be>
        somewhat unusual way to define a sub <ro.naldfi.scher@gmail.com>
        Using module whith name stored in variable <alien.cosmos@gmail.com>
    Re: Using module whith name stored in variable <noreply@gunnar.cc>
    Re: Using module whith name stored in variable <alien.cosmos@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 07 Apr 2008 16:34:25 GMT
From: xhoster@gmail.com
Subject: Re: About perl closure.
Message-Id: <20080407123426.710$Q5@newsreader.com>

"pswd" <lofenee@gmail.com> wrote:
> I have little idea about what are closures for perl?
> Is it just a function maker that returns a reference of subroutine?

I think the thing that makes a code-ref a "closure" is that any
enclosing-scoped lexical variables appearing in them have their ref-counts
incremented, and thus can't be freed until after the closure itself is
destroyed.

>
> Could anybody tell me what it is and show me some examples?

try perldoc -q closure

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Mon, 7 Apr 2008 06:50:46 -0700 (PDT)
From: "pjfalbe@gmail.com" <pjfalbe@gmail.com>
Subject: Re: Create two-dimensional Array from string
Message-Id: <08af09af-6108-4539-9fa5-956876a8a7ee@b64g2000hsa.googlegroups.com>

On Apr 4, 10:52 am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Fri, 4 Apr 2008 06:32:58 -0700 (PDT) "pjfa...@gmail.com" <pjfa...@gmail.com> wrote:
>
> pc> On Apr 3, 10:49 am, jjcass...@gmail.com wrote:
>
>
>
> >> On Apr 2, 1:21 pm, "pjfa...@gmail.com" <pjfa...@gmail.com> wrote:
>
> >> > I'm looking for the most efficient way to create a two dimensional
> >> > array from strings such as
>
> >> > MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'  2948
> >> > ','SHAKER HTS','OH')}
>
> >> > In this case MULTISET is a collection of rows from a DB.  What I want
> >> > todo is efficiently
> >> > transform into a 2-dimensional array,  where each row is an array.
> >> > And then collect those arrays
> >> > into 1 array of arrays.  I'm currently doing this but not very
> >> > efficiently.  Any help would be appreciated.
>
> >> Let Perl parse it for you. You can *eval* it.
>
> >> use Data::Dumper;
>
> >> sub ROW (@) { return [ @_ ]; }
>
> >> sub MULTISET (&) { return [ sort { $a->[0] <=> $b->[0] } shift()-
>
> >> >() ];  }
>
> >> # observe:
> >> my $multi_set = eval <<END_EVAL1;
> >> MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'
> >> 2948','SHAKER HTS','OH')}
> >> END_EVAL1
>
> >> print Dumper( $multi_set ), "\n";
>
> >> You could even define the two functions as below if you simply wanted
> >> the first field for ordering.
>
> pc> This works great!  Much better than all the sed'ing and splitting I
> pc> was doing.  For reference I'm doing a query like
>
> pc> select customer, multiset(select count(*), city, state
> pc>                              from orders A
> pc>                             where A.customer = orders.customer
> pc>                               and A.order_date = orders.order_date
> pc>                             group by 2,3)
> pc>   from orders
> pc>  where order_date = today;
>
> pc> With your transform I can now take the field returned from the
> pc> multiset and write to WriteExcel spreadsheet very easily.
>
> (checking it's not April 1)
>
> Good god, you're going to use a custom parser instead of the nice DBI
> interface I suggested?
>
> my $array = $dbh->selectall_arrayref('your select statement goes here');
>
> Even worse, it's a hacked-up eval-based parser that will fail miserably
> if you look at it sideways, and performance is going to be miserable...
> The parser is clever, but you should really consider submitting to
> thedailywtf.com if you actually use it.
>
> Ted

I went ahead and tried selectall_arrayref and as I thought it did no
better than it's cousin fetchall_arrayref.
The problem is a MULTISET returned by DBI/DBD as a varchar and the
driver doesn't know how to parse
it into an array.  There are 2 solutions to this 1) separate the
mutliset into a separate query and loop through original cursor.  or
2) manipulate the varchar into an array like above with the eval or
use 's//g' and splits to manipulate
into a array.  Luckily MULTISETs are pretty reliable in what they
return so the eval approach works great.  And it's
performance problems are better than network latency by looping.

Thank you for your suggestion got me to look at selectall_arrayref,
I've had a habit of using fetchall_arrayref
but will use selectall_arrayref more in the future.


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

Date: Mon, 7 Apr 2008 00:21:17 -0700 (PDT)
From: it_super_manager@hotmail.com
Subject: funzy.com http://geocities.com/it_super_manager/
Message-Id: <f2dc8ed1-e038-4e21-86f2-8b9d7280d5e5@g1g2000pra.googlegroups.com>

funzy.com http://geocities.com/it_super_manager/


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

Date: Mon, 7 Apr 2008 06:10:27 -0700 (PDT)
From: chorny <alexchorny@gmail.com>
Subject: Re: Looking for GT::CGI and GT::Template
Message-Id: <6c6bc4ea-f2ba-4032-8099-c1221fb9a1f6@e39g2000hsf.googlegroups.com>

On 3 Apr, 05:07, poolboi <ilovedarlingpika...@gmail.com> wrote:

> does anyone know of any good repository for perl 5.10?
You mean ppm repository for Windows? Look at http://win32.perl.org/

> i'm currently looking for a module for GT::CGI and GT::Template
There are no such modules on CPAN.

---
Alexandr Ciornii, http://chorny.net


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

Date: Mon, 7 Apr 2008 06:12:15 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: mismatch between Perl 5.6 and Perl 5.8 in printing high precision  values.
Message-Id: <49a54b35-3fc5-40ff-86fa-e74d52f87663@l28g2000prd.googlegroups.com>

On Apr 3, 10:08=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
=2E
=2E
> Is it not simply calling your atof?

I don't think so - and I see, further down, that Ilya has reported it
calls a "home-brewed" implementation.

I tried out ActiveState's builds of perl 5.6.1, 5.8.8 and 5.10.0 - all
three of which use the same underlying C library (Visual Studio 6.0).

Again, with their 5.6 build I get:

C:\_32\pscrpt>perl -e "printf(\"%.32g\n\",9.9999999976716936e-1);"
0.99999999976716936

Yet, with their builds of 5.8 and 5.10 I get:

C:\_32\pscrpt>perl -e "printf(\"%.32g\n\",9.9999999976716936e-1);"
0.99999999976716925

I think that rules out differences in the C library as the cause of
the discrepancy.

As regards atof() itself, the following C program outputs
0.99999999976716936:

int main( void )
{
   double x;

   x =3D atof("0.99999999976716936");
   printf( "%.17f\n", x );

}

Cheers,
Rob


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

Date: Mon, 07 Apr 2008 10:47:21 +0200
From: O_TEXT <O_TEXT@nospam.fr>
Subject: Re: perl should be improved and perl6
Message-Id: <ftcnma$o30$1@biggoron.nerim.net>

>   j> * some portability issue, notably with function «system».
>   >> 
>   >> proof of the last comment. system is the way to call external
>   >> programs. how could that POSSIBLY BE PORTABLE if the external programs
>   >> vary from box to box?
> 
>   j> I assume that what you call the external program is the shell.
> 
> no, you can call directly to any external program bypassing the
> shell. learn more about qx, system and exec from the docs.
> 
>   j> In my opinion, call to external programs should be done based on one of
>   j> the two following ideas:
> 
>   j> idea 1/ A function which provides pipes for stdin, stdout, stderr and
>   j> (if possible) portable access to exit values.
> 
> and perl has those in IPC::Run and many other modules. hmm, IPC modules!

I installed libipc-run-perl on a debian system.

This makes  perldoc IPC::Run  to work.
and me discovering IPC::Run.

According to this documentation, is it seams possible to start a process 
accessing stdin, stdout and stderr,
             my $h = start \@cat, \$in, \$out, \$err, timeout( 10 ) ;
and see the result value at
              finish $h or die "cat returned $?" ;
in a non portable way with:
        full_result
and in a portable way with
        result

However I am wondering how this will work under ActiverPerl, Cygwin 
Perl, and StrawberryPerl.




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

Date: 07 Apr 2008 09:30:37 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: perl should be improved and perl6
Message-Id: <slrnfvjqdt.pj.abigail@alexandra.abigail.be>

                                       _
Gordon Etly (get@bentsys.com) wrote on VCCCXXXIII September MCMXCIII in
<URL:news:65t6g3F2huv6jU1@mid.individual.net>:
||  
||  This last quote is contradicted by the main Perl document, that gives 
||  the "NAME" of the language as:
||  
||  "perl - Practical Extraction and Report Language"
||  
||  Which IS an acronym.

No, it's not. 

The first line of a manual page is the name of the binary (not the
language, the binary), followed by a one line description.

Take for instance "man man":

    man - an interface to the on-line reference manuals

Would you claim, "man" is an acronym of "an interface to the on-line
reference manuals"? Of course not. 

Just because the author of the manual page came up with an amusing line
whose starting letters make up the name of the binary doesn't make the
binary an acronym. 

The technical term for it (the *description*) is Acrostic.

http://en.wikipedia.org/wiki/Acrostic

||                       Or at the very least allows one to write "perl" or 
||  "PERL" to abbreviate that.

Well, if you want to abbreviate a one line description, feel free to do 
so, but then you could say "AITTORM" when you want to discuss man as well.
Would you then also start to rant if people ask what the hell you mean?

||                             Again, you just cannot ignore the main 
||  document.

No one is. But you're drawing unfounded conclusions.


Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


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

Date: Mon, 07 Apr 2008 12:37:02 GMT
From: "David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au>
Subject: Re: perl should be improved and perl6
Message-Id: <slrnfvk677.b50.dformosa@localhost.localdomain>

On Sun, 6 Apr 2008 21:26:35 -0500, Tad J McClellan
<tadmc@seesig.invalid> wrote:

> David Formosa (aka ? the Platypus) <dformosa@usyd.edu.au> wrote:
>> On Sun, 6 Apr 2008 09:25:02 -0700, Gordon Etly <get@bentsys.com> wrote:
[...]
>> They carry the same waight as perl's own man page because perl's man
>> page incorperates the FAQ for this group.
>
>
> There is no FAQ for this newsgroup.
>
> There is a FAQ for Perl, that ships with perl (but not with PERL).

You mean the FAQ who's content is basically the comp.lang.perl.*
FAQ with the serial numbers filed off.  You mean the FAQ that is
periodically posted in parts to this newsgroup?  You mean the FAQ that
answers questions frequently asked in this newsgroup?



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

Date: Mon, 07 Apr 2008 12:48:14 GMT
From: "David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au>
Subject: Re: perl should be improved and perl6
Message-Id: <slrnfvk6s6.b50.dformosa@localhost.localdomain>

On Mon, 07 Apr 2008 00:26:21 +0200, jm <jm@nospam.fr> wrote:
> Uri Guttman a écrit :
[...]
>>   j> In the bad things, such as:
>>   j> * bytes/unicode confusion
>>   j> * stack overflow within bad regular expression
>> 
>> huh?? then don't write bad regexes. most likely if it blows up in perl
>> it will do worse in other langs. 
>
> I have yet read that Perl regexs are best than every other ones.
>
> What I mean here is there is no way (I know) to check a coder did not
> write bad regexes.

Sure, but there is no way in general to check a coder did not write bad
code.  The only thing one can do is to have a good set of tests that will
weed out the good from the bad.

> When Perl 5 encourages use of regexs,

Perl5 allows the use of regexs where its approprate.



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

Date: 07 Apr 2008 15:45:30 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: perl should be improved and perl6
Message-Id: <slrnfvkgcq.98g.abigail@alexandra.abigail.be>

                                             _
Andrew DeFaria (Andrew@DeFaria.com) wrote on VCCCXXXIII September
MCMXCIII in <URL:news:47fa2eb4$0$87069$815e3792@news.qwest.net>:
))  The author clearly meant it to be an acronym. Are you suggesting
))  that he is wrong?


Marjorie: [ ... ]  How'd you come up with that name?

Larry: I wanted a short name with positive connotations. (I would never
       name a language "Scheme" or "Python", for instance.) I actually
       looked at every three- and four-letter word in the dictionary and
       rejected them all. I briefly toyed with the idea of naming it after
       my wife, Gloria, but that promised to be confusing on the domestic
       front. Eventually I came up with the name "pearl", with the gloss
       Practical Extraction and Report Language. The "a" was still in
       the name when I made that one up. But I heard rumors of some
       obscure graphics language named "pearl", so I shortened it to
       "perl". (The "a" had already disappeared by the time I gave Perl
       its alternate gloss, Pathologically Eclectic Rubbish Lister.)

       Another interesting tidbit is that the name "perl" wasn't
       capitalized at first. UNIX was still very much a lower-case-only OS
       at the time. In fact, I think you could call it an anti-upper-case
       OS. It's a bit like the folks who start posting on the Net and
       affect not to capitalize anything. Eventually, most of them come
       back to the point where they realize occasional capitalization is
       useful for efficient communication. In Perl's case, we realized
       about the time of Perl 4 that it was useful to distinguish
       between "perl" the program and "Perl" the language. If you find
       a first edition of the Camel Book, you'll see that the title
       was Programming perl, with a small "p". Nowadays, the title is
       Programming Perl.


http://www.linuxjournal.com/article/3394



Abigail
-- 
sub A::TIESCALAR{bless\my$x=>'A'};package B;@q=qw/Hacker Perl
Another Just/;use overload'""',sub{pop @q};sub A::FETCH{bless
\my $y=>B};tie my$shoe=>'A';print"$shoe $shoe $shoe $shoe\n";


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

Date: Mon, 7 Apr 2008 09:21:36 -0700
From: "Gordon Etly" <get@bentsys.com>
Subject: Re: perl should be improved and perl6
Message-Id: <65v00iF2i1cpsU1@mid.individual.net>

Abigail wrote:
>                                       _
> Gordon Etly (get@bentsys.com) wrote on VCCCXXXIII September MCMXCIII
> in <URL:news:65t6g3F2huv6jU1@mid.individual.net>:
>>>
>>>  This last quote is contradicted by the main Perl document, that
>>>  gives the "NAME" of the language as:
>>>
>>>  "perl - Practical Extraction and Report Language"
>>>
>>>  Which IS an acronym.
>
> No, it's not.

I'm sorry, but you are mistaken. (Please see below.)

> The first line of a manual page is the name of the binary (not the
> language, the binary), followed by a one line description.
>
> Take for instance "man man":
>
>    man - an interface to the on-line reference manuals
>
> Would you claim, "man" is an acronym of "an interface to the on-line
> reference manuals"? Of course not.


There is a huge difference here. It is not the same as,

  "perl - Practical Extraction and Report Language",

which is written defining each letter in the word "perl", which is what 
an acronym is. And notice how the NAME line in most man entries are 
lowercase (except for proper nouns)?


>>>                       Or at the very least allows one to write
>>>  "perl" or "PERL" to abbreviate that.
>
> Well, if you want to abbreviate a one line description

Ok, notice how the first letter of each word in the name line for 'man 
perl' is capitalized, and how each of the capitalized letters 
corresponds to a letter in the word "perl"? This is a common way for 
defining an acronym. There really isn't anymore to it.

-- 
G.Etly 




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

Date: Mon, 7 Apr 2008 09:39:47 -0700
From: "Gordon Etly" <get@bentsys.com>
Subject: Re: perl should be improved and perl6
Message-Id: <65v12kF2ifbk0U1@mid.individual.net>

Abigail wrote:

> Just because the author of the manual page came up with an amusing
> line whose starting letters make up the name of the binary doesn't
> make the binary an acronym.

You do realize the document in question //ships// //with// Perl, right? 
So it's not so much of a question of a random man-page author, but the 
authors of Perldoc. Remember, the same pages are accessible via perldoc 
and man, perldoc being the more official interface for the Perl 
documentation, of course.

It's the very fact this document ships with Perl that validates the 
usage of Perl/perl/PERL as an acronym.
                                            _
> Andrew DeFaria (Andrew@DeFaria.com) wrote on VCCCXXXIII September
> MCMXCIII in <URL:news:47fa2eb4$0$87069$815e3792@news.qwest.net>:
> ))  The author clearly meant it to be an acronym. Are you suggesting
> ))  that he is wrong?
>
>
> Marjorie: [ ... ]  How'd you come up with that name?
>
> Larry: I wanted a short name with positive connotations. (I would
>       never name a language "Scheme" or "Python", for instance.) I
>       actually looked at every three- and four-letter word in the
>       dictionary and rejected them all. I briefly toyed with the idea
>       of naming it after my wife, Gloria, but that promised to be
>       confusing on the domestic front. Eventually I came up with the
>       name "pearl", with the gloss Practical Extraction and Report
>       Language. The "a" was still in the name when I made that one
>       up. But I heard rumors of some obscure graphics language named
>       "pearl", so I shortened it to "perl". (The "a" had already
>       disappeared by the time I gave Perl its alternate gloss,
>       Pathologically Eclectic Rubbish Lister.)
[...]

Yes, most everyone has seen this article a dozen times over, it doesn't 
change the fact that the front line document that ships with Perl writes 
it as an acronym definition. You just can't ignore this and at the same 
time act as if the documentation Perl ships with means something.

Especially after this line from the above quote:

   Eventually I came up with the name "pearl", with the
   gloss Practical Extraction and Report Language.

I don't think it gets any more authoritative than coming from Larry 
himself ;-)

-- 
G.Etly 




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

Date: Mon, 07 Apr 2008 17:54:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl should be improved and perl6
Message-Id: <Xns9A798D6745157asu1cornelledu@127.0.0.1>

"Gordon Etly" <get@bentsys.com> wrote in
news:65v00iF2i1cpsU1@mid.individual.net: 

> Abigail wrote:
>>                                       _
>> Gordon Etly (get@bentsys.com) wrote on VCCCXXXIII September
>> MCMXCIII in <URL:news:65t6g3F2huv6jU1@mid.individual.net>:
>>>>
>>>>  This last quote is contradicted by the main Perl document,
>>>>  that gives the "NAME" of the language as:
>>>>
>>>>  "perl - Practical Extraction and Report Language"
>>>>
>>>>  Which IS an acronym.
>>
>> No, it's not.
> 
> I'm sorry, but you are mistaken. (Please see below.)

No he is not.

This is reminding me of a friend who used to pronounce doughnut 
as duf-nut because he thought the '-ough' in both dough and 
tough ought to sound the same.

He was able to advance many logical arguments why he was right, 
but, alas, he was wrong.

The correct answer is the one adopted by native Perl 
speakers whether you find that logical or not:

http://perldoc.perl.org/perlfaq1.html#What's-the-difference-between-%22perl%22-and-%22Perl%22%3f

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Mon, 7 Apr 2008 06:25:15 -0700 (PDT)
From: chorny <alexchorny@gmail.com>
Subject: Re: Returning a dataset with arrays
Message-Id: <c6e032a8-1f1c-4a0b-81b9-78032a67ad18@b64g2000hsa.googlegroups.com>

On 1 Apr, 03:55, Macaruchi <jqmi...@gmail.com> wrote:

> I am  a newbie using Perl and I have a big problem , for me, and it is
> that I need to return a query result into a array but I cant do that.

Did you start your program with "use strict;use warnings;"?

Good version of your code:

 sub getcodigodb
 { my ($table,$field,$code)= @_;
    my $dbh = open_connection();

         my $sql = "SELECT * FROM $table WHERE $field=$code";
         my $sth = $dbh->prepare($sql);
         $sth->execute() or die "Unable to execute SQL query: $dbh-
>errstr
 \n";
         $ref = $sth->fetchall_arrayref;

         $sth->finish;
         $dbh->disconnect;

         return $ref;
    }

 }

> Could be this way :
> @rows=&getcodigodb('mytable','myfield',3434); Is it correct?
No
my $ref=getcodigodb('mytable','myfield',3434);

or my @recs=@{getcodigodb('mytable','myfield',3434)};

Don't use '&' to call subs.


There is a good book about Perl: "Learning Perl". 4th edition is best.
Good Perl tutorials are available here:
http://www.perlfoundation.org/perl5/index.cgi?recommended_online_tutorials

---
Alexandr Ciornii, http://chorny.net


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

Date: 07 Apr 2008 09:40:07 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Shortcut for if(defined($var) && $var ne "") ?
Message-Id: <slrnfvjqvm.pj.abigail@alexandra.abigail.be>

                                               _
Chris Mattern (syscjm@sumire.gwu.edu) wrote on VCCCXXXII September
MCMXCIII in <URL:news:slrnfvhvri.fg.syscjm@sumire.gwu.edu>:
{}  On 2008-04-06, vikimun@gmail.com <vikimun@gmail.com> wrote:
{} > Is there shorter equivalent of if(defined($var) && $var ne "")
{} > that doesn't fall for the "0" case, and doesn't produce warning with -
{} > w ?
{} >
{} > Thanks
{} > V.M.
{}  
{}  I tried this test program:
{}  
{}  #!/usr/bin/perl
{}  
{}  use warnings;
{}  use strict;
{}  
{}  my $var;
{}  
{}  if (defined($var) && $var ne "") {
{}    print "$var\n";
{}  }
{}  
{}  It didn't produce any warnings.  When I put in "my $var = 0;",
{}  it printed "0", just like it should.  I don't understand 
{}  your question.  If by "shorter" you mean getting rid of the
{}  defined() test, then, no, you can't get rid of that.  If you
{}  aren't sure if $var is going to be defined, you have to test
{}  for it before trying to use it.


Shorter:

    if (length ($var // "")) { .. }



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Mon, 7 Apr 2008 08:59:14 -0700 (PDT)
From: Ronny <ro.naldfi.scher@gmail.com>
Subject: somewhat unusual way to define a sub
Message-Id: <bf975a97-7637-47eb-8297-228de70c3ef9@m1g2000pre.googlegroups.com>

I found in a program a piece of code which basically looked like this:

my $n="myname";
*$n=sub { .... };

The whole think was of course guided by no strict 'refs'. My question:

Is this just a unusual way to write

  sub myname { ... }

or did I miss something here?

Ronald


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

Date: Mon, 7 Apr 2008 00:50:10 -0700 (PDT)
From: Alien <alien.cosmos@gmail.com>
Subject: Using module whith name stored in variable
Message-Id: <bdd79170-926f-4f4f-b581-a42afb838f02@a1g2000hsb.googlegroups.com>

Hello all!
Can anybody tell how can I use modele which name stored in variable?
For example, I have this code:

########################################
package MyModule;

use strict;
use Exporter;
use vars qw(@ISA @EXPORT $DEBUG);

@ISA = qw/Exporter/;
@EXPORT = qw(foo);

sub foo($)
{
  my $arg = shift;
  print "MyModule foo: my arg: '$arg'\n";
  return undef;
}

1;
########################################


Here are the code of main programm

########################################
#!/usr/local/bin/perl

use strict;
my $module = 'MyModule.pm';
require $module; # load module

my $arg = 'MyArg';

# I want call procedure by full name. How I can do this?
my $mname = 'MyModule';
$mname::foo($arg);   # This doesn't work!!!

exit 0;
########################################

Thanks for help


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

Date: Mon, 07 Apr 2008 10:49:45 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using module whith name stored in variable
Message-Id: <65u5dmF2gscpjU1@mid.individual.net>

Alien wrote:
> Can anybody tell how can I use modele which name stored in variable?

<snip>

> # I want call procedure by full name. How I can do this?
> my $mname = 'MyModule';
> $mname::foo($arg);   # This doesn't work!!!

One way is via a reference to the sub:

     my $subref = \&{$mname.'::foo'};
     $subref->($arg);

Also, you should read the FAQ entry

     perldoc -q "variable name"

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


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

Date: Mon, 7 Apr 2008 03:31:47 -0700 (PDT)
From: Alien <alien.cosmos@gmail.com>
Subject: Re: Using module whith name stored in variable
Message-Id: <3db37534-8259-4410-af4e-dca8a4b9a435@x41g2000hsb.googlegroups.com>

>
> One way is via a reference to the sub:
>
> =A0 =A0 =A0my $subref =3D \&{$mname.'::foo'};
> =A0 =A0 =A0$subref->($arg);
>
> Also, you should read the FAQ entry
>
> =A0 =A0 =A0perldoc -q "variable name"
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl

That's great!
Thank you very mutch! I didn't know where to search the answer. How
easy it was!


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

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


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