[24444] in Perl-Users-Digest
Perl-Users Digest, Issue: 6627 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 30 03:05:50 2004
Date: Sun, 30 May 2004 00:05:09 -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 Sun, 30 May 2004 Volume: 10 Number: 6627
Today's topics:
about Net::DNS 0.47 <sun@cnnic.cn>
Re: decode_entities possible bug? <invalid-email@rochester.rr.com>
Re: decode_entities possible bug? <wherrera@lynxview.com>
Re: Effective perl function to remove one element from <matthew.garrish@sympatico.ca>
Re: Effective perl function to remove one element from <jurgenex@hotmail.com>
Re: Effective perl function to remove one element from <jaselby@cox-internet.com>
Re: Effective perl function to remove one element from <postmaster@castleamber.com>
Re: Effective perl function to remove one element from <jurgenex@hotmail.com>
Re: Effective perl function to remove one element from <uri@stemsystems.com>
Re: Effective perl function to remove one element from <postmaster@castleamber.com>
Re: Effective perl function to remove one element from <postmaster@castleamber.com>
Re: Effective perl function to remove one element from <tassilo.parseval@rwth-aachen.de>
Re: Effective perl function to remove one element from <tassilo.parseval@rwth-aachen.de>
Re: Effective perl function to remove one element from (Anno Siegel)
how to make the page not available in perl when click B <darick_ang@yahoo.com.sg>
Hybrid Module Question <mshelor@comcast.removeme.net>
Re: Hybrid Module Question (Malcolm Dew-Jones)
Re: Hybrid Module Question <uri@stemsystems.com>
Newbie question: PERL proxies... (mrmike)
Re: Print a formatted array <jurgenex@hotmail.com>
Re: Setting ENV varibles by calling a shell script with (Sam Holden)
Re: Setting ENV varibles by calling a shell script with <as@no-span.org>
Re: Setting ENV varibles by calling a shell script with <uri@stemsystems.com>
Re: UK Social research job to suit Excel programmer (no <invalid-email@rochester.rr.com>
Re: Why is this upload script not working (Mark Constant)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 30 May 2004 10:53:19 +0800
From: Sun Guonian <sun@cnnic.cn>
Subject: about Net::DNS 0.47
Message-Id: <40B94C9F.4030109@cnnic.cn>
Base.pm_00 is original Base.pm file of Net-DNS-0.47,
Base.pm if my updated version.
# diff -c Base.pm_00 Base.pm
*** Base.pm_00 Sat Feb 21 20:45:27 2004
--- Base.pm Sun May 30 10:28:51 2004
***************
*** 430,436 ****
my $ans = $self->send($packet);
! return $ans && $ans->header->ancount ? $ans : undef;
}
--- 430,436 ----
my $ans = $self->send($packet);
! return $ans ? $ans : undef;
}
My question is why it check $ans->header->ancount,
for some authority-only server, its reply has no answer
record, and we think it is right answer. for example,
==== foo.pl ====
#!/usr/bin/perl
use Net::DNS;
my $res1 = Net::DNS::Resolver->new(
nameservers => [qw(81.91.161.5)],
recurse => 1,
debug => 1,
);
my $query1 = $res1->query("nokia.de", "NS");
if (defined($query1)) {
foreach $rr (grep { $_->type eq 'NS' } $query1->answer) {
print $rr->nsdname, "\n";
}
}
else {
warn "query1 failed: ", $res1->errorstring, "\n";
}
==== foo.pl ====
its output is the followed :
;; query(nokia.de, NS, IN)
;; send_udp(81.91.161.5:53)
;; answer from 81.91.161.5:53 : 101 bytes
;; HEADER SECTION
;; id = 39479
;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 0
;; ra = 0 ad = 0 cd = 0 rcode = NOERROR
;; qdcount = 1 ancount = 0 nscount = 2 arcount = 2
;; QUESTION SECTION (1 record)
;; nokia.de. IN NS
;; ANSWER SECTION (0 records)
;; AUTHORITY SECTION (2 records)
nokia.de. 86400 IN NS ns1.openit.de.
nokia.de. 86400 IN NS ns2.openit.de.
;; ADDITIONAL SECTION (2 records)
ns1.openit.de. 86400 IN A 217.69.65.1
ns2.openit.de. 86400 IN A 217.10.64.100
query1 failed: NOERROR
Any advice is appreciated !
Best Regard,
Sun Guonian
------------------------------
Date: Sun, 30 May 2004 01:50:07 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: decode_entities possible bug?
Message-Id: <40B93DC0.8080902@rochester.rr.com>
Richard Bell wrote:
> decode_entities does not appear to decode this text
>
> <span class="linksep1">•</span>
>
> The sequence • is left untouched.
>
> Is this correct/expected behavior, a bug, or what?
>
> Thanks for any help.
>
> R
Perhaps you could clarify what "decode_entities" is? Is it some sub or
module you wrote, or part of a CPAN module? If the latter, which one of
the 6000+ modules is it a method of? Thanks.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sat, 29 May 2004 20:44:29 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: decode_entities possible bug?
Message-Id: <Zr-dnc8vVPU61yTdRVn-gg@adelphia.com>
Bob Walton wrote:
> Richard Bell wrote:
>
>> decode_entities does not appear to decode this text
>>
>> <span class="linksep1">•</span>
>>
>> The sequence • is left untouched.
>>
>> Is this correct/expected behavior, a bug, or what?
>>
>> Thanks for any help.
>>
>> R
>
>
> Perhaps you could clarify what "decode_entities" is? Is it some sub or
> module you wrote, or part of a CPAN module? If the latter, which one of
> the 6000+ modules is it a method of? Thanks.
>
He's using HTML::Entities to decode unicode for a bullet, and it does
not seem to work well. Perl support for Unicode over Ā is still in
the works for some modules.
------------------------------
Date: Sat, 29 May 2004 21:03:34 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <Apauc.51500$sr3.1499727@news20.bellglobal.com>
"josh" <josh.kuo@prioritynetworks.net> wrote in message
news:66001607.0405291644.3993e158@posting.google.com...
> Hi all:
>
> I am trying to find out the most efficient way to remove an element
> from an array, and have the array size shrink by one.
>
> pop, push, and splice won't work too well for me, I am trying to
> remove an element that could be in any position.
>
> Here is my current implementation (may not actually compile, just a
> example)
>
> <psuedo perl code>
> # this array is purposely unsorted
> @array = ['bob', 'alice', 'david', 'christy', 'edward', 'henry',
> 'frank'];
> @array = removeFromArray ( @array, "edward" );
>
> sub removeFromArray {
> @array = $_[0];
> $name = $_[1];
>
> for ( $i = 0; $i < @$array; $i++ ) {
> if ( $array[$i] eq $name ) {
> unset $array[$i];
> }
> }
> }
> </psuedo perl code>
>
> As you can see, this is not exactly the most efficient way of removing
> an element as the size of my array grows.
Which begs the question, why use an array when a hash would work better?
my %hash = (bob => 1, alice => 1, david => 1, christy =>1, edward => 1,
henry => 1);
delete $hash{'edward'};
It would also make removing duplicates simple because you could just assign
all the keys from your existing hashes to a new hash. And sorting would be
faster, too.
Matt
------------------------------
Date: Sun, 30 May 2004 02:12:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <eqbuc.9003$oh7.8522@nwrddc01.gnilink.net>
josh wrote:
> I am trying to find out the most efficient way to remove an element
> from an array, and have the array size shrink by one.
>
> pop, push, and splice won't work too well for me, I am trying to
> remove an element that could be in any position.
I would doubt that you can hand code anything that is faster than the
build-in function splice().If there were anything faster, then chances are
that algorithm would have been used to implement splice() in the first
place.
> Here is my current implementation (may not actually compile, just a
> example)
>
> <psuedo perl code>
> # this array is purposely unsorted
> @array = ['bob', 'alice', 'david', 'christy', 'edward', 'henry',
> 'frank'];
> @array = removeFromArray ( @array, "edward" );
>
> sub removeFromArray {
> @array = $_[0];
> $name = $_[1];
>
> for ( $i = 0; $i < @$array; $i++ ) {
> if ( $array[$i] eq $name ) {
> unset $array[$i];
> }
> }
> }
> </psuedo perl code>
>
> As you can see, this is not exactly the most efficient way of removing
> an element as the size of my array grows. And especially when I run
> this in a nested loop, say, when I want to compare two arrays and
> remove the differences, it will result in a close to BigO(n^2)
> efficiency.
> Is there a faster, more efficient way to remove an element from an
> array (and preferrably not BigO(n) )?
This code screams for a better data structure. Why aren't you using a hash?
Then all you need to do is
sub removeFromHash {
delete $hash{$_[0]};
}
I would guess this should be somewhere near O(log n) (access to hash table
is not quite linear).
> Will it help if I am performinig this on an already sorted array? Then
> I can perhaps use some sort of binary search function to find the item
> I am looking for?
Well, sure, but why? I thought your problem was deleting, not finding. A
sorted array won't help you with deleting an element.
Use a proper data structure and your problem becomes trivial.
jue
------------------------------
Date: Sat, 29 May 2004 21:15:40 -0500
From: Jason <jaselby@cox-internet.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <10biguqqtil4080@corp.supernews.com>
Matt Garrish wrote:
> "josh" <josh.kuo@prioritynetworks.net> wrote in message
> news:66001607.0405291644.3993e158@posting.google.com...
>
>>Hi all:
>>
>>I am trying to find out the most efficient way to remove an element
>>from an array, and have the array size shrink by one.
>>
>>pop, push, and splice won't work too well for me, I am trying to
>>remove an element that could be in any position.
>>
>>Here is my current implementation (may not actually compile, just a
>>example)
>>
>><psuedo perl code>
>># this array is purposely unsorted
>>@array = ['bob', 'alice', 'david', 'christy', 'edward', 'henry',
>>'frank'];
>>@array = removeFromArray ( @array, "edward" );
>>
>>sub removeFromArray {
>> @array = $_[0];
>> $name = $_[1];
>>
>> for ( $i = 0; $i < @$array; $i++ ) {
>> if ( $array[$i] eq $name ) {
>> unset $array[$i];
>> }
>> }
>>}
>></psuedo perl code>
>>
>>As you can see, this is not exactly the most efficient way of removing
>>an element as the size of my array grows.
>
>
> Which begs the question, why use an array when a hash would work better?
>
> my %hash = (bob => 1, alice => 1, david => 1, christy =>1, edward => 1,
> henry => 1);
>
> delete $hash{'edward'};
>
> It would also make removing duplicates simple because you could just assign
> all the keys from your existing hashes to a new hash. And sorting would be
> faster, too.
>
> Matt
>
>
I was thinking that a hash would be a good solution as well. If you are
bent on using an array, you could try something like this in your
"removeFromArray" subroutine:
$tmp_string = join("," , @array);
$tmp_string =~ s/$name//;
$tmp_string =~ s/,,/,/;
@array = split(/,/, $tmp_string);
Jason
------------------------------
Date: Sat, 29 May 2004 23:37:08 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <40b964f7$0$203$58c7af7e@news.kabelfoon.nl>
Jürgen Exner wrote:
> I would guess this should be somewhere near O(log n) (access to hash table
> is not quite linear).
Access to a hash table is normally O(1). That's the whole idea behind a
hash :-D.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Sun, 30 May 2004 06:10:50 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <KVeuc.8784$g15.6097@nwrddc02.gnilink.net>
John Bokma wrote:
> Jürgen Exner wrote:
>
>> I would guess this should be somewhere near O(log n) (access to hash
>> table is not quite linear).
Ooopps, that should have been "not quite constant"
> Access to a hash table is normally O(1). That's the whole idea behind
> a hash :-D.
True, but only as long as the hash is sparsely populated.
As the hash begins to fill up you will get hash conflicts and then you are
loosing O(1).
jue
------------------------------
Date: Sun, 30 May 2004 06:25:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <x7n03qa0ty.fsf@mail.sysarch.com>
>>>>> "JE" == Jürgen Exner <jurgenex@hotmail.com> writes:
JE> John Bokma wrote:
>> Jürgen Exner wrote:
>>
>>> I would guess this should be somewhere near O(log n) (access to hash
>>> table is not quite linear).
JE> Ooopps, that should have been "not quite constant"
>> Access to a hash table is normally O(1). That's the whole idea behind
>> a hash :-D.
JE> True, but only as long as the hash is sparsely populated.
JE> As the hash begins to fill up you will get hash conflicts and then you are
JE> loosing O(1).
and perl will grow the hash as needed to keep it efficient. one of the
nice little behind the scenes things. true it is not exactly O(1) but
you can assume that for common uses. the real killer is when it grows so
large that you have to swap :). then you might as well use a real db
which will be more efficient since they are designed to handle this
whereas an in ram hash is not.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 30 May 2004 01:42:52 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <40b9826e$0$209$58c7af7e@news.kabelfoon.nl>
Jürgen Exner wrote:
> John Bokma wrote:
>
>>Jürgen Exner wrote:
>>
>>
>>>I would guess this should be somewhere near O(log n) (access to hash
>>>table is not quite linear).
>
> Ooopps, that should have been "not quite constant"
>
>>Access to a hash table is normally O(1). That's the whole idea behind
>>a hash :-D.
>
> True, but only as long as the hash is sparsely populated.
> As the hash begins to fill up you will get hash conflicts and then you are
> loosing O(1).
Ok, you get O(k), which is still O(1) as long as k << n, which is
hopefully the case :-D.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Sun, 30 May 2004 01:44:35 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <40b982d3$0$209$58c7af7e@news.kabelfoon.nl>
Uri Guttman wrote:
> and perl will grow the hash as needed to keep it efficient. one of the
> nice little behind the scenes things. true it is not exactly O(1) but
The fun part behind the big O notation is that O(k) for k << n, is still
O(1). So "not exactly O(1)" does not exists.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Sun, 30 May 2004 08:46:15 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <2hte9pFgro9cU1@uni-berlin.de>
Also sprach Jürgen Exner:
> josh wrote:
>> Is there a faster, more efficient way to remove an element from an
>> array (and preferrably not BigO(n) )?
>
> This code screams for a better data structure. Why aren't you using a hash?
> Then all you need to do is
> sub removeFromHash {
> delete $hash{$_[0]};
> }
> I would guess this should be somewhere near O(log n) (access to hash table
> is not quite linear).
Hash-access is O(n) in the absolutely worst-case (for open hashing where
linear lists are used). However, the average case can be considered
constant, too, which has to do with the fact that hashes are resized
(normally their amount of buckets is doubled). So you have a complexity
of O(1 + a/2), where 'a' is the average list-length with a = m/n. 'm' is
the number of keys whereas 'n' is the number of buckets. In case of
Perl, some empirical tests suggest that 'a' is between 0.35 and 0.7.
When treating it as a random variable, I am quite sure that it will have
an expected value of 0.5. The standard deviation, I would guess, is then
probably around 0.1 or even less.
It is therefore reasonable to assume that access to Perl hashes is
constant in all but the contrived cases.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 30 May 2004 08:53:59 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <2hteo9Fgmip7U1@uni-berlin.de>
Also sprach John Bokma:
> Jürgen Exner wrote:
>> True, but only as long as the hash is sparsely populated.
>> As the hash begins to fill up you will get hash conflicts and then you are
>> loosing O(1).
>
> Ok, you get O(k), which is still O(1) as long as k << n, which is
> hopefully the case :-D.
Why would that be the case? If you have O(ln(n)) and set n to 10^16,
then k is around 37. That should qualify as k << n but still, it is not
constant. It can't be constant as long as it is parametrized with n and
the function is monotonously increasing with n (log is such a function).
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 30 May 2004 06:55:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <c9c0h6$e0e$1@mamenchi.zrz.TU-Berlin.DE>
Jürgen Exner <jurgenex@hotmail.com> wrote in comp.lang.perl.misc:
> josh wrote:
> > I am trying to find out the most efficient way to remove an element
> > from an array, and have the array size shrink by one.
> >
> > pop, push, and splice won't work too well for me, I am trying to
> > remove an element that could be in any position.
>
> I would doubt that you can hand code anything that is faster than the
> build-in function splice().If there were anything faster, then chances are
> that algorithm would have been used to implement splice() in the first
> place.
>
> > Here is my current implementation (may not actually compile, just a
> > example)
> >
> > <psuedo perl code>
> > # this array is purposely unsorted
> > @array = ['bob', 'alice', 'david', 'christy', 'edward', 'henry',
> > 'frank'];
> > @array = removeFromArray ( @array, "edward" );
> >
> > sub removeFromArray {
> > @array = $_[0];
> > $name = $_[1];
> >
> > for ( $i = 0; $i < @$array; $i++ ) {
> > if ( $array[$i] eq $name ) {
> > unset $array[$i];
> > }
> > }
> > }
> > </psuedo perl code>
> >
> > As you can see, this is not exactly the most efficient way of removing
> > an element as the size of my array grows. And especially when I run
> > this in a nested loop, say, when I want to compare two arrays and
> > remove the differences, it will result in a close to BigO(n^2)
> > efficiency.
> > Is there a faster, more efficient way to remove an element from an
> > array (and preferrably not BigO(n) )?
>
> This code screams for a better data structure. Why aren't you using a hash?
> Then all you need to do is
> sub removeFromHash {
> delete $hash{$_[0]};
> }
The OP's pseudo-code (heavy on the pseudo, light on the code) looks like
an attempt to re-implement grep(). In real (but untested) code:
sub remove_from_array {
my ( $array, $name) = @_;
@$array = grep $_ ne $name, @$array;
$array; # return ref to changed array
}
Depending on what the OP means with "unset $array[ $i]", the grep
line could also be
@$array = map { $_ eq $name ? undef : $_ } @$array;
It is probably true that a hash is a better data structure for the
problem -- "remove the differences" is a well-known keyword -- but
"grep" seems to be what OP was aiming at.
Anno
------------------------------
Date: Sun, 30 May 2004 13:40:23 +0800
From: Darick <darick_ang@yahoo.com.sg>
Subject: how to make the page not available in perl when click Back button
Message-Id: <aosib0tpd8vqp9dna3fni33pasqbrd5gat@4ax.com>
when i try to click back button in some website, the website will show
the message in the following :-
---- start
Warning: Page has Expired The page you requested was created using
information you submitted in a form. This page is no longer available.
As a security precaution, Internet Explorer does not automatically
resubmit your information for you.
To resubmit your information and view this Web page, click the Refresh
button.
---- end
may i know how to do this effect in perl ?
------------------------------
Date: Sat, 29 May 2004 22:32:39 -0700
From: Mark Shelor <mshelor@comcast.removeme.net>
Subject: Hybrid Module Question
Message-Id: <HPidnS1sF7xh7CTdRVn-vg@comcast.com>
I'm the author of a CPAN module that contains XSUBs written in C. In
other words, users are required to have a C compiler to build the module.
In the future, I'd like to also include pure Perl versions of these
subroutines so that the module can still be used even if a C compiler
isn't present. I assumed there was a more-or-less standard way to go
about writing a hybrid module, but I've yet to find specific guidelines
in the Perl documentation I've looked at.
Basically, I want to set things up such that the C-language XSUBs are
automatically used if the build platform has a C compiler. Otherwise,
the pure Perl versions of the routines would be installed.
Could anyone point me to relevant examples or how-to documentation?
Thanks, Mark
------------------------------
Date: 29 May 2004 22:56:17 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Hybrid Module Question
Message-Id: <40b97781@news.victoria.tc.ca>
Mark Shelor (mshelor@comcast.removeme.net) wrote:
: I'm the author of a CPAN module that contains XSUBs written in C. In
: other words, users are required to have a C compiler to build the module.
: In the future, I'd like to also include pure Perl versions of these
: subroutines so that the module can still be used even if a C compiler
: isn't present. I assumed there was a more-or-less standard way to go
: about writing a hybrid module, but I've yet to find specific guidelines
: in the Perl documentation I've looked at.
: Basically, I want to set things up such that the C-language XSUBs are
: automatically used if the build platform has a C compiler. Otherwise,
: the pure Perl versions of the routines would be installed.
: Could anyone point me to relevant examples or how-to documentation?
MIME::Base64 does this.
------------------------------
Date: Sun, 30 May 2004 06:21:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Hybrid Module Question
Message-Id: <x7pt8ma0zn.fsf@mail.sysarch.com>
>>>>> "MS" == Mark Shelor <mshelor@comcast.removeme.net> writes:
MS> Basically, I want to set things up such that the C-language XSUBs are
MS> automatically used if the build platform has a C compiler. Otherwise,
MS> the pure Perl versions of the routines would be installed.
MS> Could anyone point me to relevant examples or how-to documentation?
i do this exact thing in stem. it is very simple. you make the C and
perl versions into sibling classes and have a wrapper class above
them. something like this:
Foo.pm
Foo/Perl.pm
Foo/C.pm
the user always creates a Foo but inside that it tries to load Foo/C.pm
and it uses that if it can. else it tries to load Foo/Perl.pm and that
had better succeed or you die.
here is my code that does this. it tries to load the event loop you
request which is normally the c module Event.pm and falls back to my
Perl event loop. on winblows it always uses the Perl one since Event.pm
is unix specific.
the can't locate a module is the only error allowed. then it
will do the forced load of Perl.pm
my $loop_type = $Stem::Vars::Env{ 'event_loop' } ||
($^O =~ /win32/i ? 'perl' : 'event' );
my $loop_class = $loop_to_class{ $loop_type } || 'Stem::Event::Perl' ;
unless ( eval "require $loop_class" ) {
die "can't load $loop_class: $@" if $@ && $@ !~ /locate/ ;
eval 'require Stem::Event::Perl' ;
die "can't load default event loop Stem::Event::Perl $@" if $@ ;
}
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 29 May 2004 22:38:47 -0700
From: mike@enovative-solutions.net (mrmike)
Subject: Newbie question: PERL proxies...
Message-Id: <e9da4b27.0405292138.2c8ab639@posting.google.com>
I am in the design stages of developing a website that will allow a
user to log into my site, the site internally would log into a third
party site using something like LWP::UserAgent or WWW::Mechanize,
parse the HTML data and return it to the users browser using my
formatting (trust me, not trying to do anything illegal). The problem
is that I want to more or less spoof the user's IP address and send it
along to the third party server rather than use my own. I'm sure by
now this sounds bad, but really the whole concept is due to the fact
that the user(s) IP addresses are part of the security mechanism. Boy,
I'm really digging myself a hole here, aren't I? Ok, you get the
point. Again, nothing illegal. How might I do this in PERL? Perhaps
some kind of proxy?
------------------------------
Date: Sun, 30 May 2004 02:24:52 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Print a formatted array
Message-Id: <UBbuc.9035$oh7.2957@nwrddc01.gnilink.net>
Jamie Smyth wrote:
> I'm having some trouble printing an array in Perl. The array is very
> long and must be read in by some archaic FORTRAN code so the spacing
> needs to be exact. For those that speak FORTRAN, the format is
> basically '(5(F16.10))'.
>
> In perl I have:
>
> 105 my $i;
> 106 for ($i=0; $i<(scalar(@data)); $i++) {
No need for scalar() here.
> 107 my $s = int($i*6);
No need for int() here.
You are jumping in steps of 6 elements ...
> 108 #print "$s $e \n";
> 109 $fh->printf("%10.6f %10.6f %10.6f %10.6f %10.6f\n",
> 110 $data[$s], $data[$s+1], $data[$s+2], $data[$s+3],
> $data[$s+4]);
... but you are printing only 5 elements?
> In addition to being rather awful looking and slow, the above code
Idea #1: use a better data structure! What you got there is in reality a
two-dimensional array. So use one. With an array of arrays your code will
become a lot nicer.
> pads a partially full, last line with zero values if the number of
> elements in the array is not divisible by 5.
If you want to go with a c-style loop (and in this case it might actually
not be that bad) then what about:
for my ($i=5; $i < @data; $i += 6) {
$fh->printf("%10.6f %10.6f %10.6f %10.6f %10.6f\n",
@data[$i-5..$i-1]); #not sure if the array slice works here
}
This will terminate before trying to print incomplete records.
jue
------------------------------
Date: 30 May 2004 01:05:41 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Setting ENV varibles by calling a shell script within a perl program
Message-Id: <slrncbicr4.p0t.sholden@flexal.cs.usyd.edu.au>
On Sun, 30 May 2004 00:18:03 GMT,
Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> wrote:
> Tad McClellan wrote:
>
>> ad <as@no-span.org> wrote:
>>>
>>> I need to make some system calls to other programs from a perl program
>>> and those programs that are being called have some environment
>>> variable dependencies that are set by a shell script program. So I
>>> have to call this shell script to set up (export bunch of variables)
>>> environment variables so that the other program that I call can run
>>> fine.
[snip]
>>> If all possible, I am trying to avoid writing another shell program
>>> that call the other shell program prior to my perl program since I
>>> have lots of variable combination that my perl program can run with
>>> and do not want to have all the variable validated with this extra
>>> shell program so that it can call my perl program.
>>
>>
>> If you want access to those env vars in your Perl program, then
>> wrapping it in a sh program is what you should do.
>>
>> I don't think I understand what your objection to that approach is.
>>
>> Why is that not a good solution?
>
> An extra layer of dependancy? In this world, we have A.sh calling
> A.pl. We then need to ensure that no one calls A.pl except through
> A.sh. This may be trivial for a new program, but if it's an existing
> perl script which is being called by numerous automated processes, that
> may not be as good.
I'd do
; mv perl_program ORIGperl_program
; cat <<HERE >perl_program
> #!/bin/sh
> . myShell.sh
> exec ORIGperl_program
> HERE
; chmod 755 perl_program
Probably using full paths...
Unless there are some situations where MyShell.sh should *not* be
sourced before executing the perl program or sourcing MyShell.sh
twice should *not* be done then I can't see a problem with that.
All the automated processes are going to now be calling the shell
script wrapper.
If either of those two situations apply then I'd consider that a huge
bug that needs to be fixed anyway.
Or modify myShell.sh to also do:
MYSHELL_HAS_BEEN_RUN=1
EXPORT MYSHELL_HAS_BEEN_RUN
and modify the perl program to start with:
[completely untested, I haven't considered handling the various
ways a program can be started (and effect on $0)]
use strict;
use warnings;
use FindBin;
use File::Basename;
unless ($ENV{MYSHELL_HAS_BEEN_RUN}) {
exec ". myShell.sh; $FindBin::Bin" . basename($0);
}
But that seems error prone.
--
Sam Holden
------------------------------
Date: Sat, 29 May 2004 22:58:43 -0400
From: ad <as@no-span.org>
Subject: Re: Setting ENV varibles by calling a shell script within a perl program
Message-Id: <pan.2004.05.30.02.58.42.583930@no-span.org>
>> system '. ./myShell.sh; other_prog';
>
Thanks for all the replies and information. The above system call helped
to solve my problem. I didn't think about calling multiple calls in one
"system" before.
Thanks everyone again.
------------------------------
Date: Sun, 30 May 2004 04:18:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Setting ENV varibles by calling a shell script within a perl program
Message-Id: <x7y8naa6pp.fsf@mail.sysarch.com>
>>>>> "DM" == Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> writes:
DM> Another solution, which is kinda ugly, is to do something like this:
DM> my @lines = `. myShell.sh; env`;
that is the best way to do it. it isn't ugly, just clumsy.
DM> Then, parse each line, splitting on '=', and putting them into your
DM> %ENV hash:
DM> foreach my $line (@lines)
DM> {
DM> /([^=]+)=(.*)/ and $ENV{$1} = $2;
DM> }
bah.
my $env = `. myShell.sh; env`;
local( %ENV ) = $env =~ m/^([^=]+)=(.+)$/mg ;
DM> This may have some funny side effects - if myShell.sh sets some
DM> variable that Perl ends up using, what happens depends on whether the
DM> perl module in question has already read that environment variable or
DM> not.
not if you localize %ENV first. do it in a block and the old %ENV be
back when you exit the block.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 30 May 2004 01:39:36 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: UK Social research job to suit Excel programmer (not necessarily VBA)
Message-Id: <40B93B49.7060409@rochester.rr.com>
Duncan Smith wrote:
> http://www.man.ac.uk/news/vacancies/research.html#581
>
> Apologies if this is an inappropriate post for this group.
>
> Duncan Smith
Better to not post it than to apologize. It reflects poorly on yourself
and your organization to knowingly violate usenet standards.
Where should it be posted? A group with "jobs" in its name would be a
good start.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 29 May 2004 22:41:45 -0700
From: constants@mix-net.net (Mark Constant)
Subject: Re: Why is this upload script not working
Message-Id: <ce43fdea.0405292141.56f78d29@posting.google.com>
Well I think I am getting close. A file by the name of $path ends up
in the quickbooks directory now. The file contains nothing though
which I don't understand. Please bear with me on this because I am
trying to take everybodies suggestions. Below is what outputs.
Upload Results
Filename: XF86Config.new
Destination: /var/www/htdocs/quickbooks/XF86Config.new
Original CWD was: /var/www/htdocs
New CWD after chdir is: /var/www/htdocs/quickbooks
MIME Type: text/plain
File saved
Here is my code
#!/usr/bin/perl -T
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use File::Spec::Functions qw/catfile splitdir/;
use strict;
use warnings;
use Cwd;
my $q = CGI->new();
my $file = $q->param('upfile');
$file =~ /^([\w.-]+)$/ or die "Unaccetable file name: $file";
my $filename = $1;
my $cdir = cwd;
chdir('quickbooks');
my $dir = cwd;
my $path = catfile splitdir($dir), $filename;
print $q->header, $q->start_html('Uploading File');
print $q->h1('Upload Results');
if(!$filename){
print "Nothing Uploaded\n";
} else {
print "Filename: $filename<br />\n";
print "Destination: $path<br />\n";
print 'Original CWD was: ',$cdir,"<br />\n";
print 'New CWD after chdir is: ', $dir,"<br />\n";
my $ctype = $q->uploadInfo($file)->{'Content-Type'};
print "MIME Type: $ctype<br />\n";
open(OUTFILE, '>$path') or die("Didn't work because of $! \n");
binmode(OUTFILE);
while (my $bytesread = read($filename, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close(OUTFILE);
print "File saved\n";
}
$q->end_html;
------------------------------
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 6627
***************************************