[29550] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 794 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 25 09:09:46 2007

Date: Sat, 25 Aug 2007 06:09:10 -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, 25 Aug 2007     Volume: 11 Number: 794

Today's topics:
    Re: autobox as ppm package for AS Perl? <bik.mido@tiscalinet.it>
        better and great hash <john.swilting@wanadoo.fr>
    Re: better and great hash QoS@domain.invalid
    Re: dynamic regex <dummy@example.com>
    Re: Efficiently de-duping an array <tadmc@seesig.invalid>
    Re: FAQ 8.39 How do I set CPU limits? <brian.d.foy@gmail.com>
    Re: How safe is $0? <bik.mido@tiscalinet.it>
    Re: Is there a better way of doing this? (Jamie)
    Re: Is there a better way of doing this? <bill@ts1000.us>
    Re: Is there a perl equivalent to the following.... (Randal L. Schwartz)
    Re: Regular expression use <5502109103600001@t-online.de>
    Re: Regular expression use <dummy@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 25 Aug 2007 14:25:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: autobox as ppm package for AS Perl?
Message-Id: <cq70d3lc9tuqjk01jfidi77qc8fr3ftjl5@4ax.com>

On Fri, 24 Aug 2007 14:05:45 +0200, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

>Does anybody have a precompiled autobox ppm for AS Perl, version
>5.8.8? Currently my repositories are:

One reply @ PM, reported here for completeness:

: I looked at building autobox with perl-5.8.8 (ActivePerl 820), but
: this fails when compiling the xs component with a missing symbol
: error. This is due to autobox.xs calling Perl_pp_method_named, which
: isn't available in the perl public API.


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


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

Date: Sat, 25 Aug 2007 12:20:52 +0200
From: john swilting <john.swilting@wanadoo.fr>
Subject: better and great hash
Message-Id: <46d00284$0$27385$ba4acef3@news.orange.fr>

        
I would wish to store the result of the loop while in a list. I must make
how?

#!/usr/bin/perl -w

use strict;
use warnings;

my %Conf;
$Conf{XferMethod} = 'rsync';
$Conf{XferLogLevel} = 1;
$Conf{RSyncShareName} = '___1___';
$Conf{ClientNameAlias} = '___2___';

while(my($clef, $valeur) = each (%Conf)) {
    print "$clef => $valeur","\n";
    }


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

Date: Sat, 25 Aug 2007 11:44:28 GMT
From: QoS@domain.invalid
Subject: Re: better and great hash
Message-Id: <wCUzi.1066$Ya2.872@trnddc05>


john swilting <john.swilting@wanadoo.fr> wrote in message-id:  <46d00284$0$27385$ba4acef3@news.orange.fr>

> 
> 
> I would wish to store the result of the loop while in a list. I must make
> how?
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> 
> my %Conf;
> $Conf{XferMethod} = 'rsync';
> $Conf{XferLogLevel} = 1;
> $Conf{RSyncShareName} = '___1___';
> $Conf{ClientNameAlias} = '___2___';
> 
> while(my($clef, $valeur) = each (%Conf)) {
>     print "$clef => $valeur","\n";
>     }

Assuming you mean store to disk... use DBM::Deep



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

Date: Sat, 25 Aug 2007 11:21:21 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: dynamic regex
Message-Id: <RgUzi.1955$bO6.753@edtnps89>

Paul Lalli wrote:
> On Aug 24, 12:56 pm, papahuhn <papah...@gmx.net> wrote:
>> Paul Lalli schrieb:
>>
>>> On Aug 24, 11:24 am, Thomas Peter <braindum...@expires-31-08-2007.news-
>>>> when i call the thing with -p '.*(\d+).*' and -r '\1'
>>>> it only prints \1 not the first occurence of \d+
>>>> any suggestions what's wrong?
> 
>> Besides,\1 is only valid in the matching part of an s///.
>> Probably you need $1.
> 
> It's perfectly *valid*.  It's just not recommended:

Because in a double quoted string \<digit> is usually interpreted as an octal 
escape.  Is "\1" the SOH character or a back-reference to (\d+)?



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Sat, 25 Aug 2007 01:18:23 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Efficiently de-duping an array
Message-Id: <slrnfcvidf.4u1.tadmc@tadmc30.sbcglobal.net>

Dan Otterburn <dan.otterburn@gmail.com> wrote:
> On 24 Aug, 02:31, Tad McClellan <ta...@seesig.invalid> wrote:
>
>> Your Question is Asked Frequently:
>
> Thanks to both of you for being gentle and taking the time to answer
> (and explain the answer to) a question that should never have been
> asked.
>
> We learn by our mistakes - and I have made plenty here - so, if it is
> any consolation, I have learnt more than I would have done had I found
> the FAQ in the first place. I will endeavour not to make the same
> mistakes twice!


Making mistakes in a public forum is a very good way to "internalize"
a lesson. You're not likely to forget what has been learned.

I've "internalized" a bunch of stuff myself.   :-)


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


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

Date: Thu, 23 Aug 2007 13:05:31 -0700
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.39 How do I set CPU limits?
Message-Id: <230820071305311513%brian.d.foy@gmail.com>

In article <20070822124353.549$V4@newsreader.com>, <xhoster@gmail.com>
wrote:

> 
> 8.39: How do I set CPU limits?
> 
>     Use the BSD::Resource module from CPAN.
>     As an example:
> 
>     use BSD::Resource;
>     setrlimit(RLIMIT_CPU,10,20) or die $!;
> 
>     This sets the soft and hard limits to 10 and 20 seconds, respectively.
>     After 10 seconds of time spent running on the CPU (not "wall" time),
>     the process will be sent a signal (XCPU on some systems) which, if not
>     trapped, will cause the process to terminate.  If that signal is
>     trapped, then after 10 more seconds (20 seconds in total) the process
>     will be killed with a non-trappable signal.
> 
>     See the BSD::Resource and your systems documentation for the gory
>     details.


I've updated perlfaq8 with your answer. It should appear in the next go
around.

Thanks, :)

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sat, 25 Aug 2007 12:23:11 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How safe is $0?
Message-Id: <jm00d31hn84pqmm9ml0dg78u17nr0i1g5h@4ax.com>

On Fri, 24 Aug 2007 13:47:55 -0700, Bill H <bill@ts1000.us> wrote:

>I learned this today. On my windows system testing $0 was great, on
>the linux webserver, it was the full path. So the easiest thing was to
>just to use index and cover both bases (ie index($0,"for.pl")).

The easiest and more reliable way would have been to use basename() as
has already been suggested to you. It is unlikely, but what if you
have to do with /path/to/for.pl.for.pl?


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


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

Date: Sat, 25 Aug 2007 11:16:49 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: Is there a better way of doing this?
Message-Id: <Lc1188038575305700x8b83044@earth.podro.com>

In <1187946342.509055.110980@l22g2000prc.googlegroups.com>,
Bill H <bill@ts1000.us> mentions:
>In a script I have on a site I read all the values passed in the url
>(using the GET method) into an array called $query{'foo'} where foo is
>the name of the value. Though this has always worked fine I find
>myself assigning them to a new variable to make it easier to recognize
>them and quicker to type, for example I'll make $foo = $query{'foo'};
>
>The question is, is there anything wrong with doing the following to
>automate this process, or is there a better "perl" way of doing the
>same?
>
>
>foreach $temp (keys(%query))
>{
>    eval("\$$temp = \$query{\$temp};");
>}

As everyone else has pointed out, someone could come along and pass in
whatever they want thus "surprising" you with new variables (or worse...)

You could, I suppose, mess around in the package symbol table if you wanted
to get around the eval part, thats what my example does.. but that makes for 
some rather un-readable code.

If you're going to do it anyay, at least make sure you know which variables
your importing.


Not the "right" way to do it.. but at least it makes sure you're not throwing
in arbitrary variables or eval'd code:

---
use strict;
use vars qw($BAD $APPLE $Q);

# We're poking our nose into the main:: symbol table. 
no strict 'refs';

# This is our "test" query, $BAD should NOT be tampered with.                                                                                                              
my %query = (
    APPLE => 'Rotten',
    BAD   => 'FAIL - Should NOT be set to this!',
    Q     => 'Keywords'
);

# This should be left ALONE!
$BAD = 'OK - not been messed with';

# Iterate through the variables we know are OK to mess with.
foreach my $vname (qw(APPLE Q)){
	# Mess about with the symbol table of package 'main'
    ${'main::' . $vname} = $query{$vname};
}

# "prove" that $BAD wasn't touched.

print 'APPLE=',$APPLE,"\n",'Q=',$Q,"\n",'BAD=',$BAD,"\n";
---

You still need to be careful, GET is reasonably safe, but if someone posts in
HUGE chunks of data and you ever accept POST, you could be in for some nasties.

In general, it's better to use CGI::Simple or one of the other CGI-ish modules
for this. (it's also easier..)


Jamie
-- 
http://www.geniegate.com                    Custom web programming
Perl * Java * UNIX                        User Management Solutions


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

Date: Sat, 25 Aug 2007 04:56:45 -0700
From:  Bill H <bill@ts1000.us>
Subject: Re: Is there a better way of doing this?
Message-Id: <1188043005.006770.147150@i13g2000prf.googlegroups.com>

On Aug 24, 12:24 pm, Jim Gibson <jgib...@mail.arc.nasa.gov> wrote:
> In article <1187946342.509055.110...@l22g2000prc.googlegroups.com>,
>
>
>
>
>
> Bill H <b...@ts1000.us> wrote:
> > In a script I have on a site I read all the values passed in the url
> > (using the GET method) into an array called $query{'foo'} where foo is
> > the name of the value. Though this has always worked fine I find
> > myself assigning them to a new variable to make it easier to recognize
> > them and quicker to type, for example I'll make $foo = $query{'foo'};
>
> > The question is, is there anything wrong with doing the following to
> > automate this process, or is there a better "perl" way of doing the
> > same?
>
> > foreach $temp (keys(%query))
> > {
> >     eval("\$$temp = \$query{\$temp};");
> > }
>
> The main thing wrong with this method is that you lose control of what
> you are defining. You have no idea what is being passed to your
> program. While you know what values a legitimate submission of your
> form page will pass, there is nothing preventing a malicious person
> submitting a totally bogus URL that could contain anything. What if I
> submitted such a URL that defined an already-defined variable, thereby
> clobbering or hijacking your CGI program.
>
> There also doesn't seem to be much point. If you only use a value once,
> then just use $query{'foo'} (or just $query{foo}). If you use it more
> than once, put my $foo = $query{foo}. How many variables do you have
> that you can't have one line defining scalar variables to use in the
> rest of your program?
>
> --
> Jim Gibson
>
>  Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
>     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------        
>                http://www.usenet.com- Hide quoted text -
>
> - Show quoted text -

Jim

You have a good point there. The reason I want to use it is that I
have about 20 or so routines in a script that use various values
passed in the "get". But I never thought of someone just putting junk
in the line and causing problems so I may just do as you and Jamie
suggest: $foo = $query{'foo'};

This brings up another thing I have been working on. If you go on a
lot of sites they use what appears to be random characters on the url
but are infact the "get" data encoded. I have used this method before
where everything after the ? in the url is converted to hex so that it
isnt readable. Is there any perl routines that would encrypt this data
(or any string) and have some form of checksum in it? For example

Say my unencrypted line is: foo.pl?action=this&data=that

After encryption it would be something like: foo.pl?
kkiuKJHjy786jghjgjhERHGfgh

Then in my scrypt I would "decrypt" the text (held in the query line
of ENV) to get the original action=this&data=that which I would then
handle like a normal query line. Some form of checksum would be nice
so I could determine if the text had been mangled.

I could write this, but if there is a perl routine I would rather use
it.

Bill H



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

Date: Thu, 23 Aug 2007 18:32:25 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: grocery_stocker <cdalten@gmail.com>
Subject: Re: Is there a perl equivalent to the following....
Message-Id: <864pipiuom.fsf@blue.stonehenge.com>

>>>>> "grocery" == grocery stocker <cdalten@gmail.com> writes:

grocery> Is there a perl equivalent to the java 'this' keyword ?

In a Perl object call, that's the first parameter to the subroutine.

sub some_method {
  my $this = shift;
  ... 
  $this->some_other_method
  ...
}

Of course, you can call it $self or $this or $xyzzy if you want.

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/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sat, 25 Aug 2007 12:10:29 +0200
From: Josef Moellers <5502109103600001@t-online.de>
Subject: Re: Regular expression use
Message-Id: <faov6l$s7k$01$2@news.t-online.com>

Nick Maclaren wrote:
> For reasons that I won't explain, as they are too complicated
> and not terribly relevant, I am interested in discovering what
> people actually use regular expressions for.  Not the subject
> domain, but the construction of the regular expressions.
> 
> I know about computer scientists and parsing, and I know about
> the use of relatively simple ones for things like extracting
> HTML links from Web pages.  But I don't have much feel for the
> (probably rare but difficult) uses of more complex ones for
> other purposes.  I have heard of several such uses, but don't
> have an overall idea of what is going on.
> 
> Any pointers appreciated, to more-or-less anything.

I just don't get what you're after!
Lots of data is available in text form, so sifting though it requires 
regular expressions.
A better question would be: what do you use Perl for, as I'd say most 
Perl programs utilize REs at some point or the other.
But IIRC we've had that thread already.

-- 
Mails please to josef dot moellers
and I'm on gmx dot de.


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

Date: Sat, 25 Aug 2007 10:57:24 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: Regular expression use
Message-Id: <oWTzi.1954$bO6.752@edtnps89>

Nick Maclaren wrote:
> In article <famlj0$33k$1@mlucom4.urz.uni-halle.de>,
> Mirco Wahab <wahab-mail@gmx.net> writes:
> |> 
> |> Using complex regular expressions is like tank destruction
> |> with contact charges glued on them.  Only a few people
> |> will even survive the first "usage", but survivors will
> |> then eventually be able to destroy almost every tank with
> |> tremendous speed and precision.
> 
> I must remember that!  It is nicely put.

I couldn't understand it.  (An old Centurion trooper.)


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

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


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