[23786] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5990 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 29 18:05:43 2003

Date: Mon, 29 Dec 2003 15: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           Mon, 29 Dec 2003     Volume: 10 Number: 5990

Today's topics:
    Re: CGI: Calling C is different? (Gary E. Ansok)
        Config file for Perl install <imiller@bsd.uchicago.edu>
    Re: Determine if a process was spawed by screen <travislspencer@hotmail.com>
    Re: Determine if a process was spawed by screen <travislspencer@hotmail.com>
        Encrypting executable or embedding in C <tom@nosleep.net>
    Re: Encrypting executable or embedding in C <pkent77tea@yahoo.com.tea>
    Re: Encrypting executable or embedding in C <jwillmore@remove.adelphia.net>
    Re: Formatting a Variable (Mike)
        help with perl + MQBEGIN + MQGET and MQPUT options (Golem)
    Re: installing mod manually <aolblowz@yahoo.com>
    Re: isql in perl <kkeller-usenet@wombat.san-francisco.ca.us>
        Newbie Question on Deleting Logs Script (Clifford Bracht)
    Re: Regexp *-operator and multiple elements <noreply@gunnar.cc>
    Re: Regexp *-operator and multiple elements <gnari@simnet.is>
    Re: Regexp *-operator and multiple elements <gnari@simnet.is>
        regexp - postfix maillog <davidh@wmis.net>
    Re: regexp - postfix maillog <gnari@simnet.is>
    Re: regexp - postfix maillog <matthew.garrish@sympatico.ca>
    Re: regexp - postfix maillog <gnari@simnet.is>
        storing a hash of a hash in a DBM database <rdcolvin@erols.com>
    Re: storing a hash of a hash in a DBM database <pkent77tea@yahoo.com.tea>
    Re: storing a hash of a hash in a DBM database <gnari@simnet.is>
    Re: writting an 'in' keyword for perl <lv@aol.com>
    Re: writting an 'in' keyword for perl <xxala_qumsiehxx@xxyahooxx.com>
    Re: writting an 'in' keyword for perl <dwall@fastmail.fm>
    Re: writting an 'in' keyword for perl <jurgenex@hotmail.com>
    Re: writting an 'in' keyword for perl <pkent77tea@yahoo.com.tea>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Dec 2003 22:53:55 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: CGI: Calling C is different?
Message-Id: <bsqba3$lmu$1@naig.caltech.edu>

In article <ae92bb50.0312252101.41d323d@posting.google.com>,
Huey <huey_jiang@yahoo.com> wrote:
>Hi All,
>
>I wonder that is there any difference of calling C executable in CGI
>from the "normal"? A few days ago, with helps from Tad, Jim,
>Christian, I did make my perl scripts got returns from C executables.
>Thanks go to Jim, Christian, and Tad! However, when I put my code into
>CGI, broken! I can't figure out the kicker, thus here for help. My
>code test.pl:
>
>#!/usr/bin/perl
>print "Content-type: text/html", "\n\n\n";
>
>my $mytest = "./c_hello.exe";
>open TEST, "$mytest |" or die "Error running $mytest: $!\n";

This runs the "c_hello.exe" program located in the current directory 
(which is not necessarily the same as the directory where the Perl 
script is located).  When your script runs as a CGI script, what is 
the current directory?

Another possibility is that the CGI script runs under a different
UID (often "nobody") with very limited permissions -- perhaps this
UID does not have permission to access your C executable.

My recommendation is to use a complete path to the program when
defining $mytest.  Alternatively, if your script must look for
files in the directory where the script lives, look into the FindBin 
module.

Did your CGI script print the "Error running $mytest" message?  If it 
did, it probably went to your Web server's log files.  What message
was printed for the $! variable?  Knowing that would help us help you,
and might even help you resolve the problem without our help.  If you 
can't check your server's error log files, then either don't use die() 
or arrange for the messages to be sent somewhere where you can see them 
(use CGI::Carp qw(fatalsToBrowser) is one possibility -- 
perldoc CGI::Carp for more info).

Gary Ansok
-- 
3M suggests that to obtain the best results, one should make the bond
"while the adhesive is wet, aggressively tacky."  I did not know what
"aggressively tacky" meant until I saw a recent notice in the Bboard.
	-- Mario Barbacci


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

Date: Mon, 29 Dec 2003 14:34:21 -0600
From: "xman" <imiller@bsd.uchicago.edu>
Subject: Config file for Perl install
Message-Id: <W70Ib.11$Y4.7403@news.uchicago.edu>

Yes I am a sysadmin not a programer..
So here is the question   Is their a configuration file for which compiler
is used by perl 5.8.0   ?
I did a package install on a solaris system and is it set for cc   but I
only have the Gnu gcc.
thanks for any help.




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

Date: Mon, 29 Dec 2003 11:36:53 -0800
From: "Travis Spencer" <travislspencer@hotmail.com>
Subject: Re: Determine if a process was spawed by screen
Message-Id: <bsq82l0mln@enews3.newsguy.com>

Good suggestion, Ben.  I have only installed a CPAN module once (in August).
I can't remember exactly how I did it though.  I didn't have root privileges
then and I still don't :(  If you have any suggestions that may jog my
memory, I would appreciate it.

-- 

Regards,

Travis Spencer
Portland, OR. USA

"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:bsnbid$i45$1@wisteria.csv.warwick.ac.uk...
>
> "Travis Spencer" <travislspencer@hotmail.com> wrote:
> > I guess I should have mentioned that my solution needs to
> > run on Solaris 8+
> > and Redhat 9.
>
> Try using Proc::ProcessTable form CPAN.
>
> Ben
>
> -- 
>    If you put all the prophets,   |   You'd have so much more reason
>    Mystics and saints             |   Than ever was born
>    In one room together,          |   Out of all of the conflicts of time.
> ben@morrow.me.uk |----------------+---------------| The Levellers,
'Believers'




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

Date: Mon, 29 Dec 2003 14:03:10 -0800
From: "Travis Spencer" <travislspencer@hotmail.com>
Subject: Re: Determine if a process was spawed by screen
Message-Id: <bsq8cm0nfc@enews3.newsguy.com>

Sorry, Ben, disregard that last post.  I can be a real lazy sod sometimes.
I found the answers in the perlfaq and groups.google.

Have a nice day.

-- 

Regards,

Travis Spencer
Portland, OR. USA

"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:bsnbid$i45$1@wisteria.csv.warwick.ac.uk...
>
> "Travis Spencer" <travislspencer@hotmail.com> wrote:
> > I guess I should have mentioned that my solution needs to
> > run on Solaris 8+
> > and Redhat 9.
>
> Try using Proc::ProcessTable form CPAN.
>
> Ben
>
> -- 
>    If you put all the prophets,   |   You'd have so much more reason
>    Mystics and saints             |   Than ever was born
>    In one room together,          |   Out of all of the conflicts of time.
> ben@morrow.me.uk |----------------+---------------| The Levellers,
'Believers'




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

Date: Mon, 29 Dec 2003 13:37:57 -0800
From: "Tom" <tom@nosleep.net>
Subject: Encrypting executable or embedding in C
Message-Id: <3ff0aa69@nntp0.pdx.net>

Hi

Can someone point me to information regarding either encrypting a perl file
so it can still execute (if this is possible), or embedding a 10,000+ line
script completely into a C/C++ program.

It also needs to encapsulate all included libraries, etc.

Thanks,
Tom




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

Date: Mon, 29 Dec 2003 22:49:18 +0000
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Encrypting executable or embedding in C
Message-Id: <pkent77tea-97C5B3.22491829122003@ptb-nnrpp01.plus.net>

In article <3ff0aa69@nntp0.pdx.net>, "Tom" <tom@nosleep.net> wrote:

> Can someone point me to information regarding either encrypting a perl file
> so it can still execute (if this is possible), 

You'll need to provide a little more information, especially: should the 
perl program decrypt itself, or should the operator type in the 
decryption key, for example?

If the former is the case, then you are offering very little protection 
because the encrypted data carries along its own decryption key and 
decryption code in the clear (it must be in the clear or else the system 
couldn't execute it...) - it'll stop some people idly looking at the 
source but nothing more.

If the latter then there are many ways of encrypting things, and I think 
that you could easily write a self decrypting thing, like a 'shell 
archive' that I've seen sometimes. The easiest thing might be to have a 
simple perl script that asked for the decryption key, and then took its 
__DATA__ section, decrypted that and ran it, somehow...

> or embedding a 10,000+ line
> script completely into a C/C++ program.

try 'perldoc perlembed' for that

> It also needs to encapsulate all included libraries, etc.

This might be hard if there are .so or .dll objects involved, especially 
if this program needs to run on different machines or architectures, but 
if it's all pure perl then I think that you can just concatenate the 
whole lot together _in the right order_ and load it as one stream of 
text. OTOH you could simply encrypt a zip file or tar.gz of all the 
files required and decrypt them onto the filesystem, but that has its 
own vulnerabilities. [ Also, you probably don't need to encrypt all the 
modules do you? ]

Note that there are other ways to investigate your program which do not 
necessarily require a human to read and print out your source code, for 
example using debuggers, a 'special' version of perl, tools such as 
strace or truss, etc... if you can provide more info about your 
requirements we might be able to focus on better suggestions.


I'm assuming that you are running this on a fairly normal computer - I 
would guess that some specialist platforms have support for encrypted 
binary image execution, etc, but they're probably military, and the 
kinds of people who use those systems probably wouldn't be asking for 
advice here :-)

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Mon, 29 Dec 2003 22:55:40 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Encrypting executable or embedding in C
Message-Id: <20031229175539.7aca9178.jwillmore@remove.adelphia.net>

On Mon, 29 Dec 2003 13:37:57 -0800
"Tom" <tom@nosleep.net> wrote:

> Can someone point me to information regarding either encrypting a
> perl file so it can still execute (if this is possible), or
> embedding a 10,000+ line script completely into a C/C++ program.
> 
> It also needs to encapsulate all included libraries, etc.
[Sigh]

This has been asked and answered in different ways before.  Use Google
to get a feel for what answers are available.

However, to get you started, try the following resources (at the
command line):
perldoc perlembed
perldoc -q 'compile'

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
If little green men land in your back yard, hide any little green
women you've got in the house.   -- Mike Harding, "The Armchair
Anarchist's Almanac" 


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

Date: 29 Dec 2003 12:58:51 -0800
From: csdude@hotmail.com (Mike)
Subject: Re: Formatting a Variable
Message-Id: <46cdc619.0312291258.6392cd97@posting.google.com>

>     my $formatted = sprintf "%09.1f", $number;


Geez, man, what's wrong with me? That's Perl 101. Can I chalk that one
up to late-night brain-fried?

Mike


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

Date: 29 Dec 2003 13:05:39 -0800
From: golemlist@hotmail.com (Golem)
Subject: help with perl + MQBEGIN + MQGET and MQPUT options
Message-Id: <3c8073a1.0312291305.60054bd3@posting.google.com>

Hello,
I'd like to write 2 scripts which should 
1) read from a MQSeries  queue (with wait unlimited) and write to an
oracle DB
2) read from Oracle and write to a MQSeries queue
I would like to use both mq and oracle transactions 
I'd like to do that in perl with MQSeries modules and DBI+ DBD::Oracle
I'd also like to use the plain syntax in MQ and not the OO one (the
scripts will be mantained by people who required this).
some sample in c of my ideas could be:
http://www.fiendish.demon.co.uk/MQSeries/samples/write_to_oracle.c

my problem is I have some real troubles in using MQCMIT and also my
MQCLOSE option is complaining with reason 0 and compcode 0

this is same working code I tried:
_________________________________________________
$coption = { 'ChannelName'    => $channelname,
               'TransportType'  => 'TCP',
               'ConnectionName' => '$connectionname',
             };
$Hconn = MQCONNX($qmgr_name, { 'ClientConn' => $coption
                               }, $cc, $re);

$ObjDesc = {
              ObjectName        => $queuename,
             };

$Hobj = MQOPEN($Hconn,$ObjDesc,$Options,$CompCode,$Reason);


$GetMsgOpts = {
                 Options => MQGMO_FAIL_IF_QUIESCING | MQGMO_SYNCPOINT
| MQGMO_WAIT,
                 WaitInterval => MQWI_UNLIMITED,
                };
$MsgDesc = {
              CorrelId => $correlid,
              Data => $data
             };

$Buffer = MQGET($Hconn,$Hobj,$MsgDesc,$GetMsgOpts,$BufferLength,$CompCode,$Reason);
________________________________________________________

could anyone help me in providing syntax for the MQCONNECT, MQBEGIN
MQGET or MQPUT , MQCMIT options called in a perl script ?
Infinite thanks
Golem


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

Date: Mon, 29 Dec 2003 16:53:35 -0500
From: lucas <aolblowz@yahoo.com>
Subject: Re: installing mod manually
Message-Id: <ipmdnVkjj8z9P22iRVn-sA@golden.net>

I've emailed the author, and here's what he wrote:

---
As documented, auto-install requires working Net::*.  Yours is not
working.  You need PASSIVE_FTP (sp?) to be set.

Thanks for the way to turn passive FTP on programmatically.  I have it
in my TODO list to retry with PASSIVe on if the default connect fails.
No ETA, though.
---

-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Mon, 29 Dec 2003 14:29:14 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: isql in perl
Message-Id: <qr9qsb.5lb.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2003-12-29, Ragnar Hafstaš <gnari@simnet.is> wrote:
> "Keith Keller" <kkeller-usenet@wombat.san-francisco.ca.us> wrote in message
> news:jtopsb.koa.ln@goaway.wombat.san-francisco.ca.us...
>>
>> It may be that the sysadmin was told to remove compilers to make it more
>> difficult for employees to install their own software.
>
> in that case he should ask the sysadmin to install DBI and the correct DBD
> module

 ...and it may be that the sysadmin is not permitted to do so.  :)

Of course, none of us know the context in which the OP works.  Perhaps
he can justify to his superiors that he requires DBI for his work, and
then the sysadmin can install it.  These are all political, not Perl,
questions, however.

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

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

iD8DBQE/8KquhVcNCxZ5ID8RAtE8AJ97DZ9RiCVJ+F6XdgwAc7+PbupHEwCdGthk
FvMv539QG5sP2cjUD5mDH54=
=r8bD
-----END PGP SIGNATURE-----


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

Date: 29 Dec 2003 11:57:18 -0800
From: beaton@franklincollege.edu (Clifford Bracht)
Subject: Newbie Question on Deleting Logs Script
Message-Id: <41e4115.0312291157.53e65a02@posting.google.com>

I was asked to create a Perl script that is able to when it runs
delete Performance logs that are 30 days old from the current date on
a Windows Platform.  I didn't know Pearl prior to this and this is
only after about 5 days of trying to teach myself.  Here is my code. I
was just wondering if anyone could lend some helpful suggestions that
could maybe clear things up or get me going on the right path if I'm
not already there.  Thanks

use Date::Calc qw(:all);

eval 
{ 
($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock();
};

#$days = Date_to_Days($year,$month,$day);
	#($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1);
$day_diff = Delta_Days($year1, $month1, $day1, $year2, $month2,
$day2);
$checkdate ($year1, $month1, $day1) = (@logdate);		#Date Associated
with the first or oldest perflog file
$currentdate ($year2,$month2, $day2) = (Today([$gmt]);		#Current Date
$counterlog = ("C:\PerfLogs\system\");
$tracelog = ("C:\PerfLogs\system\");					#Directory of the log files
$alertlog = ("C:\PerfLogs\system\");


@logarray("$counterlog","$tracelog","$alertlog",);		#Array of the
three performance logs
@logdate("$logdate1","$logdate2","$logdate3",)


if (($year,$month,$day) =  Decode_Date_US($counterlog);
{
	$counterlog = $logdate1;
}
else if
{
	(($year,$month,$day) = Decode_Date_US($tracelog);
	$tracelog = $logdate2;
}
else if
{
	(($year,$month,$day) = Decode_Date_US($tracelog);
	$alertlog = $logdate3;
	
}
else
{
	exit; 
};
#Reads in each Performance counter and checks the difference in days
against 30 days

for ($logcounter = 0; logcounter <= $#logarray; logcounter++)
{
	while ($day_diff >= 30)			
	{
	delete $checkdate;
	}
	else
		print "All files are current; No log files where deleted \n";
}

exit;


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

Date: Mon, 29 Dec 2003 20:18:49 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regexp *-operator and multiple elements
Message-Id: <bspv6p$7die$1@ID-184292.news.uni-berlin.de>

Martijn Houtman wrote:
> 
> @foobar = ("foobarbarbarfoo" =~ m/(foo)(bar)*(foo)/g);
> 
> this makes the array foobar contain:
>     {"foo", "bar", "foo"}
> while I want it to be
>     {"foo", "bar", "bar", "bar", "foo"}
> 
> The *-operator seems to 'forget' the first few elements and just
> returns the last element, which is stored in the $2 variable. Is
> there a way to make it return the full list of elements?

This may be something in the right direction:

     @foobar = 'foobarbarbarfoo' =~ /(foo)((?:bar)*)(foo)/;

It distinguishes between clustering and capturing, and '*' is captured
as well. The result is:

     ('foo', 'barbarbar', 'foo')

Of course, to get an array with five elements you can do:

     @foobar = 'foobarbarbarfoo' =~ /(foo|bar)/g;

But that matches much more. ;-)

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



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

Date: Mon, 29 Dec 2003 19:40:03 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: Regexp *-operator and multiple elements
Message-Id: <bspvvd$45c$1@news.simnet.is>

"Martijn Houtman" <tinus@tinus.ath.cx> wrote in message
news:pL_Hb.75652$Jh.57047@amsnews03.chello.com...
> Hello,
>
> I have an issue parsing a string with a regular exression. Here's a small
> example:
>
> @foobar = ("foobarbarbarfoo" =~ m/(foo)(bar)*(foo)/g);
>
> this makes the array foobar contain:
>     {"foo", "bar", "foo"}
> while I want it to be
>     {"foo", "bar", "bar", "bar", "foo"}
>
> The *-operator seems to 'forget' the first few elements and just returns
the
> last element, which is stored in the $2 variable.
this is because the * is outside the capture brackets

>   Is there a way to make it
> return the full list of elements?

yes
this can be done with a combination of  look-ahead/behind assertions, along
with the \G assertion

>
> I have been suggested to split the string into three pieces first, and
then
> parse them separately, but I'd still like to do it with a single regular
> expression.

why not:
@foobar = ("foo",(barbarbarfoo" =~ /foo((?:bar)*)foo/ &&
$1=~/(bar)/g),"foo");

if you still want to do it with the assertions:
@foobar =  ("foobarbarbarfoo" =~
/(foo(?=(?:bar)*foo)|\Gbar(?=(?:bar)*foo)|(?<=foo(?:bar))\Gfoo)/g;

gnari

>
> Thanks in advance!
> Regards,
> --
> tinus.




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

Date: Mon, 29 Dec 2003 19:43:21 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: Regexp *-operator and multiple elements
Message-Id: <bsq05k$45h$1@news.simnet.is>

"Ragnar Hafstaš" <gnari@simnet.is> wrote in message
news:bspvvd$45c$1@news.simnet.is...
> @foobar =  ("foobarbarbarfoo" =~
> /(foo(?=(?:bar)*foo)|\Gbar(?=(?:bar)*foo)|(?<=foo(?:bar))\Gfoo)/g;

ooops, the cut-and-paste failed to include the closing parens
@foobar =  ("foobarbarbarfoo" =~
/(foo(?=(?:bar)*foo)|\Gbar(?=(?:bar)*foo)|(?<=foo(?:bar))\Gfoo)/g);

gnari







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

Date: Mon, 29 Dec 2003 20:28:32 -0000
From: David Hill <davidh@wmis.net>
Subject: regexp - postfix maillog
Message-Id: <20031229202826.GA25696@phobia.ms>

Hello -
I have a line:

my $line = "Dec 29 11:09:22 host postfix/smtp[29933]: EBFAA4BB26: to=<user@isp.net>, orig_to=<username@domain.com>
, relay=mail.isp.net[192.168.1.2], delay=28, status=sent (250 LAA02137 Message accepted for delivery";


the to= will be either:
 to=<user@isp.net>,
 to=<user@sub.isp.net>,

I cant seem to match this line

if ($line =~ /\bto=<*\@isp.net>/) {
   print "isp.net";
} elsif ($line =~ /\bto=<*\@sub.isp.net>/) {
   print "sub.isp.net";
} else {
   print "not to isp.net";
}

any help?
Thanks in advance.
David



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

Date: Mon, 29 Dec 2003 20:55:44 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: regexp - postfix maillog
Message-Id: <bsq4da$4aq$1@news.simnet.is>

"David Hill" <davidh@wmis.net> wrote in message
news:20031229202826.GA25696@phobia.ms...

> the to= will be either:
>  to=<user@isp.net>,
>  to=<user@sub.isp.net>,
>
> I cant seem to match this line
>
> if ($line =~ /\bto=<*\@isp.net>/) {
this tries to match a word boundary,
followed by 'to='
followed by 0 or more '<'
followed by '@isp'
followed by any character
followed by 'net>'

looks like you need to read up on perldoc perlre

/\bto=<.*\@isp\.net>/

gnari






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

Date: Mon, 29 Dec 2003 16:01:18 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: regexp - postfix maillog
Message-Id: <sC0Ib.3507$Vl6.901885@news20.bellglobal.com>


"David Hill" <davidh@wmis.net> wrote in message
news:20031229202826.GA25696@phobia.ms...
>
>
> the to= will be either:
>  to=<user@isp.net>,
>  to=<user@sub.isp.net>,
>
> I cant seem to match this line
>
> if ($line =~ /\bto=<*\@isp.net>/) {
>    print "isp.net";
> } elsif ($line =~ /\bto=<*\@sub.isp.net>/) {
>    print "sub.isp.net";
> } else {
>    print "not to isp.net";
> }
>

You're matching "to=" followed by 0 or more occurrences of "<" followed by
@, which is obviously not what you want. I would change the pattern to the
following (but there are always other ways to do it):

if ($line =~ /\bto=<[^>]*\@isp.net>/) {
}
elsif ($line =~ /\bto=<[^>]*\@sub.isp.net>/) {
}
else {
}


Matt




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

Date: Mon, 29 Dec 2003 21:18:55 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: regexp - postfix maillog
Message-Id: <bsq5op$4gd$1@news.simnet.is>

"Ragnar Hafstaš" <gnari@simnet.is> wrote in message
news:bsq4da$4aq$1@news.simnet.is...
>
> /\bto=<.*\@isp\.net>/

i know, I know ....
the .* is greedy, so this will fail in cases like
blabla=<foo@bar.com>more blabla<qqq@isp.net>qwerty
which will match, but should not

it is better to use
/\bto=<[^>]*\@isp\.net>/
as suggested my Matt in another followup

gnari






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

Date: Mon, 29 Dec 2003 16:43:05 -0500
From: Colvin <rdcolvin@erols.com>
Subject: storing a hash of a hash in a DBM database
Message-Id: <3FF09FE9.5060402@erols.com>

I'm trying to store a hash of a hash in a DBM database, but I keep 
running into problems with my references.  The enclosed script runs 
without errors; the errors don't appear until I uncomment the commented 
lines (the DBM functionality).  How do I fix my references to make them 
compatible with a DBM database?

Thank you,
Alec Colvin


----- error message ----------

13457  Can't use string ("HASH(0xba0c34)") as a HASH ref while "strict 
refs" in use at c:\perl_test\database1.pl line 20.

----- code -------------------

use strict;

my %data;
# dbmopen(%data, "c:\\perl_test\\database", 0666) or
#   die "Can't open the database";

my $person1 = { "fname" => "Stevie",
                 "lname" => "Wonder"
               };

%data = ( "13457" => $person1,
         );

my @ID_number = keys(%data);
@ID_number = sort(@ID_number);

my $i;
for ($i = 0; $i < @ID_number; $i++) {
   print STDOUT "$ID_number[$i]  ";
   print STDOUT qq|$data{$ID_number[$i]}->{"fname"}  |;
   print STDOUT qq|$data{$ID_number[$i]}->{"lname"}\n|;
}

# dbmclose(%data);



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

Date: Mon, 29 Dec 2003 22:59:05 +0000
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: storing a hash of a hash in a DBM database
Message-Id: <pkent77tea-92B9E7.22590529122003@ptb-nnrpp01.plus.net>

In article <3FF09FE9.5060402@erols.com>, Colvin <rdcolvin@erols.com> 
wrote:

> I'm trying to store a hash of a hash in a DBM database, but I keep 
> running into problems with my references.
<snip>

The easiest thing to do is use MLDBM (in my opinion):

http://search.cpan.org/~chamas/MLDBM-2.01/lib/MLDBM.pm

It say:
"...store arbitrary perl data, including nested references. Thus, this 
module can be used for storing references and other arbitrary data 
within DBM databases."

But note the WARNINGS section, particularly whether there's a record 
length limit in whichever DBM implementation you're using.

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Mon, 29 Dec 2003 22:05:00 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: storing a hash of a hash in a DBM database
Message-Id: <bsq8f6$4n3$1@news.simnet.is>

"Colvin" <rdcolvin@erols.com> wrote in message
news:3FF09FE9.5060402@erols.com...
> I'm trying to store a hash of a hash in a DBM database, but I keep
> running into problems with my references.  The enclosed script runs
> without errors; the errors don't appear until I uncomment the commented
> lines (the DBM functionality).  How do I fix my references to make them
> compatible with a DBM database?

I assume you mean that you want the values of your tied hash to be
hashreferences.

in that case you might want to look at the module MLDBM (Multi-Level DBM)

gnari







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

Date: Mon, 29 Dec 2003 13:43:24 -0600
From: l v <lv@aol.com>
Subject: Re: writting an 'in' keyword for perl
Message-Id: <jt%Hb.4681$5M.98802@dfw-read.news.verio.net>

David K. Wall wrote:
> David <noylwigymea@hotmail.com> wrote:
> 
> 
>>I can't count how many times I've wanted to write a statement like
>>this:
>>
>>if ($val in @vals){
>>    # do my stuff
>>}
>>
>>    Does anyone know of a way to cause a sub call to recieve the
>>scalar preseeding the sub call as well as the array following? 
>>Essetialy I want to create a keyword called in which checks to see if
>>a list contains a certain value.
> 
> 
> I don't know of a way to do it exactly like that; I'd do it like this:
> 
> # untested
> my %hash;
> @hash{@vals} = ();
> if ( exists $hash{$val} ) {
>     # do stuff...
> }
> 

This would work:


@vals = (2 .. 10);

# change $val to 1 or 11 or 20 for testing method
$val = '10';
print "@vals\n$val\n\n";

if ("@vals" =~ m/^$val$/) {
	print $&;
}
else {
	print "$val not in \@vals\n";
}

Len



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

Date: Mon, 29 Dec 2003 20:04:08 GMT
From: "Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: writting an 'in' keyword for perl
Message-Id: <YM%Hb.3224$jC4.1386@newssvr25.news.prodigy.com>

"David" <noylwigymea@hotmail.com> wrote in message
news:7041eb48.0312291036.e950ea@posting.google.com...
> I can't count how many times I've wanted to write a statement like
> this:
>
> if ($val in @vals){
>     # do my stuff
> }
>
>     Does anyone know of a way to cause a sub call to recieve the
> scalar preseeding the sub call as well as the array following?

I believe someone (Damian Conway?) already wrote a module to do just this.
Hmmm ... a quick search turns up Quantum::Superpositions which adds an any()
function. So you can do this:

  if ($val == any(@vals)) { ... }

I've never used it before, and I don't know how efficient it is. But, given
Damian's reputation, I wouldn't worry about that too much :)

> my $in = $val eq $_ ? 1 : 0 for (@vals);

I would do this:

    if (grep {$_ eq $val} @vals) { ... }

but this iterates through all of @vals even if the first element matches
$val. Depending on the size of @vals, and how many times you're doing this
operation, this might or might not be a problem for you.

--Ala




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

Date: Mon, 29 Dec 2003 20:27:34 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: writting an 'in' keyword for perl
Message-Id: <Xns94609D420A8F5dkwwashere@216.168.3.30>

l v <lv@aol.com> wrote:

> 
> This would work:

It didn't when I copied, pasted, and ran it.

> @vals = (2 .. 10);
> 
> # change $val to 1 or 11 or 20 for testing method
> $val = '10';
> print "@vals\n$val\n\n";
> 
> if ("@vals" =~ m/^$val$/) {

This will never match unless @vals has only one element and that element is 
the number we want.

To get it to work properly the regex should be /\b$val\b/.


>      print $&;
>}
> else {
>      print "$val not in \@vals\n";
>}


-- 
David Wall


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

Date: Mon, 29 Dec 2003 22:11:27 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: writting an 'in' keyword for perl
Message-Id: <jE1Ib.11583$E17.4594@nwrddc02.gnilink.net>

David wrote:
> I can't count how many times I've wanted to write a statement like
> this:
>
> if ($val in @vals){
>     # do my stuff
> }
>
>     Does anyone know of a way to cause a sub call to recieve the
> scalar preseeding the sub call as well as the array following?
> Essetialy I want to create a keyword called in which checks to see if
> a list contains a certain value.
>
>     Yes I know I can use something like
>
> my $in = $val eq $_ ? 1 : 0 for (@vals);
> if ($in){
>     # do my stuff
> }

That's ugly. Why not simply
    for my $in ( grep {$val==$_}, @vals) {
        # do my stuff
    }

Or if you don't really care about the value and just want to do some action
if a value is present:
    if (grep {$val==$_}, @vals) {
        # do my stuff
    }

jue




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

Date: Mon, 29 Dec 2003 22:33:06 +0000
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: writting an 'in' keyword for perl
Message-Id: <pkent77tea-9F94F9.22330629122003@ptb-nnrpp01.plus.net>

In article <7041eb48.0312291036.e950ea@posting.google.com>,
 noylwigymea@hotmail.com (David) wrote:

> I can't count how many times I've wanted to write a statement like
> this:
> 
> if ($val in @vals){
>     # do my stuff
> }
> 
>     Does anyone know of a way to cause a sub call to recieve the
> scalar preseeding the sub call as well as the array following? 
> Essetialy I want to create a keyword called in which checks to see if
> a list contains a certain value.


Personally I'd either do it as a hash lookup:

my %foo = map { $_ => 1 } @vals;
if ($foo{$val}) {
   ...


or maybe as an explicit loop setting a flag:

my $boolean = 0;
foreach (@vals) {
   if ($_ eq $val) {
      $boolean = 1;
      last;
   }
}
if ($boolean) {
   ...


That's untested code but it looks right to me :-) Note that you may 
sometimes want to do either string matches or numerical matches, 
according to your problem. Which of the above is better for you might 
depend on your exact circumstances, too.

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

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.  

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


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