[26491] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8652 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 10 09:05:33 2005

Date: Thu, 10 Nov 2005 06:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 10 Nov 2005     Volume: 10 Number: 8652

Today's topics:
        how to check if some module is installed or not <I_feel_this_is_a_bad_idea@uch.net>
    Re: how to check if some module is installed or not (Anno Siegel)
        how to interpret string as code? <qjason@starhub.net.sg>
    Re: how to interpret string as code? <a.mcgregor@pobox.com>
    Re: how to interpret string as code? (Anno Siegel)
    Re: how to interpret string as code? <qjason@starhub.net.sg>
    Re: how to interpret string as code? <qjason@starhub.net.sg>
    Re: Need workaround for regex bug in 5.8.6 <nospam-abuse@ilyaz.org>
        pack /unpack issue <sonet.all@msa.hinet.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 10 Nov 2005 12:50:45 +0200
From: "Serge A. Ribalchenko" <I_feel_this_is_a_bad_idea@uch.net>
Subject: how to check if some module is installed or not
Message-Id: <20051110125045.3c3643ed.I_feel_this_is_a_bad_idea@uch.net>

--Signature=_Thu__10_Nov_2005_12_50_45_+0200_aH_BMBhq=PykgDdw
Content-Type: text/plain; charset=US-ASCII
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Hi there,

I want to check if some module, say, CGI, is installed in system, before I 
decide to use it or to do some workarounds. Should I check @INC or there 
is a more simple solution?

-- 
Best wishes,
~       Serge.           pubkeys: http://uch.net/~fisher/keys.asc
~fingerprint : 4346 2766 BC96 E77F 5BFF  1E7C 12C2 3852 E5FD DC34

--Signature=_Thu__10_Nov_2005_12_50_45_+0200_aH_BMBhq=PykgDdw
Content-Type: application/pgp-signature

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFDcyYNX9BKv7kKDR0RAtoiAKCXygknSN2oCLQM76X/qDpJD/eCIwCdH8yf
j+nnwbFqnvIYGNtWX1Zr/MQ=
=1FZu
-----END PGP SIGNATURE-----

--Signature=_Thu__10_Nov_2005_12_50_45_+0200_aH_BMBhq=PykgDdw--


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

Date: 10 Nov 2005 11:46:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to check if some module is installed or not
Message-Id: <dkvbvd$8u8$4@mamenchi.zrz.TU-Berlin.DE>

Serge A. Ribalchenko <I_feel_this_is_a_bad_idea@uch.net> wrote in comp.lang.perl.misc:
> -=-=-=-=-=-
> 
> Hi there,
> 
> I want to check if some module, say, CGI, is installed in system, before I 
> decide to use it or to do some workarounds. Should I check @INC or there 
> is a more simple solution?

If you want to load the module if it is installed (as opposed to deciding
if it is installed without loading it), wrap a require statement in an
eval to catch the error (untested):

    unless ( eval { require CGI; 1 } ) {
        # not found, do something...
    }

You can wrap a BEGIN {} around that if you need the action at compile
time, as in "use".

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 10 Nov 2005 17:33:24 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: how to interpret string as code?
Message-Id: <9u46n1pd0d4tdt818k593nh8ad8302h773@4ax.com>

Hi there

As the fields in my data table are not fixed, I need to do this:

# ------------------------------------------------------------
$name = 'John Doe';
$fields = '$firstname, $lastname';
($fields) = split(/\s/, $name);
print "$firstname";		# returns John
print "$lastname";		# returns Doe
# ------------------------------------------------------------

where line 3 is interpreted as:
# ------------------------------------------------------------
($firstname, $lastname) = split(/\s/, $name);
# ------------------------------------------------------------

How can this be accomplished? Any help would be appreciated. Thank
you.



Jason Q.


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

Date: Thu, 10 Nov 2005 10:15:29 GMT
From: Andrew McGregor <a.mcgregor@pobox.com>
Subject: Re: how to interpret string as code?
Message-Id: <55Fcf.4301$Xz1.2831@fe2.news.blueyonder.co.uk>

Jason Quek wrote:
> 
> How can this be accomplished? Any help would be appreciated. Thank
> you.

I'm not sure what the question is.  What is line 2 attempting to do? 
What happens when you replace line 3 with the last example of line 3?

#!/usr/bin/perl

use strict;
use warnings;

my $name = 'John Doe';

my ($firstname, $lastname) = split(/\s/, $name);

print "$firstname";             # returns John
print "$lastname";              # returns Doe


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

Date: 10 Nov 2005 11:21:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to interpret string as code?
Message-Id: <dkvaes$8u8$1@mamenchi.zrz.TU-Berlin.DE>

Jason Quek  <qjason@starhub.net.sg> wrote in comp.lang.perl.misc:
> Hi there
> 
> As the fields in my data table are not fixed, I need to do this:
> 
> # ------------------------------------------------------------
> $name = 'John Doe';
> $fields = '$firstname, $lastname';
> ($fields) = split(/\s/, $name);
> print "$firstname";		# returns John
> print "$lastname";		# returns Doe
> # ------------------------------------------------------------
> 
> where line 3 is interpreted as:
> # ------------------------------------------------------------
> ($firstname, $lastname) = split(/\s/, $name);
> # ------------------------------------------------------------
> 
> How can this be accomplished? Any help would be appreciated. Thank
> you.

Are you saying you want to determine the variable names ($firstname and
$lastname) at runtime?  So that they could be $vorname and $nachname in
another run of the same program?  You don't really want to do that.
How would you *use* those elusive variables in the rest of the program
if you don't know their names?

Instead, use a hash (untested):

    my $name = 'John Doe';
    my @fields = qw( firstname lastname);
    my %person;
    @person{ @fields} = split ' ', $name;
    print "$person{ firstname}\n";
    print "$person{ lastname}\n";

If in another run you set @fields = qw( vorname nachname) you can access
the parts under $person{ vorname} etc.  But now the variable bits are
program data, not parts of the program proper.  That is a much better
design.

Annp
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 10 Nov 2005 21:41:48 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: Re: how to interpret string as code?
Message-Id: <bfj6n1prtu2bs9v8cdsoiibs8bgggqj4b6@4ax.com>

Andrew McGregor <a.mcgregor@pobox.com> wrote:

>Jason Quek wrote:
>> 
>> How can this be accomplished? Any help would be appreciated. Thank
>> you.
>
>I'm not sure what the question is.  What is line 2 attempting to do? 
>What happens when you replace line 3 with the last example of line 3?

>my ($firstname, $lastname) = split(/\s/, $name);

This works but the problem is the field order of my data is not fixed.
Sometimes it is ($firstname, $lastname), sometimes it is ($lastname,
$firstname) so I need specify the order of the fields only during
script execution.



Jason Q.

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

>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>my $name = 'John Doe';
>
>my ($firstname, $lastname) = split(/\s/, $name);
>
>print "$firstname";             # returns John
>print "$lastname";              # returns Doe


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

Date: Thu, 10 Nov 2005 21:44:16 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: Re: how to interpret string as code?
Message-Id: <5hj6n1l53232a26oan202v0665fejukpai@4ax.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

>Jason Quek  <qjason@starhub.net.sg> wrote in comp.lang.perl.misc:
>> Hi there
>> 
>> As the fields in my data table are not fixed, I need to do this:
>> 
>> # ------------------------------------------------------------
>> $name = 'John Doe';
>> $fields = '$firstname, $lastname';
>> ($fields) = split(/\s/, $name);
>> print "$firstname";		# returns John
>> print "$lastname";		# returns Doe
>> # ------------------------------------------------------------
>> 
>> where line 3 is interpreted as:
>> # ------------------------------------------------------------
>> ($firstname, $lastname) = split(/\s/, $name);
>> # ------------------------------------------------------------
>> 
>> How can this be accomplished? Any help would be appreciated. Thank
>> you.
>
>Are you saying you want to determine the variable names ($firstname and
>$lastname) at runtime?  So that they could be $vorname and $nachname in
>another run of the same program?  You don't really want to do that.
>How would you *use* those elusive variables in the rest of the program
>if you don't know their names?
>
>Instead, use a hash (untested):
>
>    my $name = 'John Doe';
>    my @fields = qw( firstname lastname);
>    my %person;
>    @person{ @fields} = split ' ', $name;
>    print "$person{ firstname}\n";
>    print "$person{ lastname}\n";
>
>If in another run you set @fields = qw( vorname nachname) you can access
>the parts under $person{ vorname} etc.  But now the variable bits are
>program data, not parts of the program proper.  That is a much better
>design.
>
>Annp

Yes you're right, the variable names are only avialable at runtime. I
understand your method and have several other work arounds, but I was
wondering if my 'method' were possible. Possibly using 'eval',
although I wasn't able to get it to work either.



Jason Q.


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

Date: Thu, 10 Nov 2005 08:37:47 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Need workaround for regex bug in 5.8.6
Message-Id: <dkv0sr$14bo$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
James Marshall 
<james@jmarshall.com>], who wrote in article <20051109142502.Y33644@jmarshall.com>:
> I found a weird bug in Perl 5.8.6:  If a variable in a CGI script (only) 
> is long enough, the script dies when it matches the variable against the 
> pattern /(.|ab)*/ .

This is a very old limitation of the Perl REx engine: it uses C stack
for backtracking-data storage; since C stack is a very scarse
resource, and running out of stack is a catastrophic process (as
opposed to running out of heap), this makes things very restrictive.

Actually, about 5 years ago I added the necessary infrastructure to
the REx engine to keep these data on Perl stacks (as opposed to C
stacks, Perl stacks can grow, and running out of stack can be caught -
at least in some situations); moreover, I converted one part of the
REx engine (out of 4 or 5 different parts) to use this infrastructure.

At this moment I had no time to convert the remaining constructs.  I
hoped that "everybody" will be able to continue and "copy" the
provided modification to the other constructs.  Apparently, nobody
volunteered.

=======================================================

Meanwhile, you have several alternatives:

  a) Make sure that your Perl is compiled with "stack checking code",
     so that running out of stack is not catastrophic (will not help
     with data processing :-(, but will help with bookkeeping ;-);

  b) Increase amount of stack so that your data can be processed (not
     always feasible);

  c) Do not use ()* on complicated constructs (likewise).

Sorry to be a bearer of a sad news,
Ilya


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

Date: Thu, 10 Nov 2005 19:48:01 +0800
From: "sonet" <sonet.all@msa.hinet.net>
Subject: pack /unpack issue
Message-Id: <dkvc4c$aph$1@netnews.hinet.net>

result:
 ...
<znul@123.com.tw>  12345  8
<znul@123.com.tw>  12345  9
<znul@123.com.tw>  12345  10
<znul@123.com.tw>  12345  2816  <==
<znul@123.com.tw>  12345  3072
 ...

if i set $i=11 or any value.

like:
$i=11;
my $packdata=pack("ia30a30", $i ,$mailaddr,$mailtitle);

the result is ok.
#---------------------------------------------------------------------------
------
#test1.pl
#---------------------------------------------------------------------------
------
#!/usr/local/bin/perl

use strict;
my $mailaddr='<znul@123.com.tw>';
my $isread=0;
my $mailtitle='12345';
my $serailno=0;

open FH,">testmdb";
for (my $i=1;$i<=1000;$i++)
{
   my $packdata=pack("ia30a30", $i ,$mailaddr,$mailtitle);
   print FH $packdata;
}
close FH;

#---------------------------------------------------------------------------
------
#test2.pl
#---------------------------------------------------------------------------
------
#!/usr/local/bin/perl
use strict;
open (FH,"testmdb");
my $r=1;

while(1)
{
  seek(FH,($r-1)*64,0);
  my $data;
  read(FH,$data,64)==64 or last;
  my($serialno,$mailaddr,$mailtitle)= unpack("ia30a30",$data);
  sleep(1);
  print "$mailaddr\t$mailtitle\t$serialno\n";
  $r++;
}
close FH;




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

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 V10 Issue 8652
***************************************


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