[17330] in Perl-Users-Digest
Perl-Users Digest, Issue: 4752 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 28 21:05:32 2000
Date: Sat, 28 Oct 2000 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972781507-v9-i4752@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 28 Oct 2000 Volume: 9 Number: 4752
Today's topics:
CGI.pm + exec = error andre_sanchez@my-deja.com
Re: chmod problems? I think. <tony_curtis32@yahoo.com>
Re: func (a) func !a! func ~a~ func a .... more? (Tad McClellan)
Re: func (a) func !a! func ~a~ func a .... more? <brondsem@my-deja.com>
Re: grep vs. a subroutine to find an occurance of an el <ren.maddox@tivoli.com>
Re: grep vs. a subroutine to find an occurance of an el (Tom Christiansen)
Re: grep vs. a subroutine to find an occurance of an el <james@NOSPAM.demon.co.uk>
Re: grep vs. a subroutine to find an occurance of an el (Gwyn Judd)
Re: How can i find my ip? <nospam@david-steuber.com>
Re: How can i find my ip? <nospam@david-steuber.com>
Re: How could post a HTML with images to newsgroup? <nospam@david-steuber.com>
Re: how to find oldest file in a directory (Martien Verbruggen)
Re: How to loop in the background <rick.delaney@home.com>
Re: How to protect perl program from pirates? <nospam@david-steuber.com>
OT: Yes there _are_ stupid questions. Anyone collect t <nospam@david-steuber.com>
Re: Perl: ICQ Checker fallenang3l@my-deja.com
Re: Sending mails from a Unix webserver <g.soper@soundhouse.co.uk>
Re: variable in module <pilsl@goldfisch.atat.at>
Re: variable in module (Martien Verbruggen)
Re: what does /warn "$x" if "$x"/ mean <josephmariadassou@primus.com.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Oct 2000 23:16:50 GMT
From: andre_sanchez@my-deja.com
Subject: CGI.pm + exec = error
Message-Id: <8tfmov$d7m$1@nnrp1.deja.com>
I have two CGI scripts, tester.pl and testee.pl listed below, that I
wish to have interact via the exec function. testee.pl runs when
called directly, however it fails when called by tester.pl via the
exec with the following error message:
Malformed multipart POST
How can I achieve what I want?
Thanks,
Andre Sanchez
#----------------------- CGI Script tester.pl
#!/usr/bin/perl -w
use strict;
use CGI;
my $query = new CGI;
my ($method, $action, $encoding) = ('post', 'tester.pl',
'multipart/form-data');
if (!$query->param('checked')) {
print $query->header();
print $query->start_html();
print $query->startform(-method=>$method,
-action=>$action,
-enctype=>$encoding);
print $query->checkbox(-name => 'checked',
-value=> '1',
-label=> 'Check Box');
print $query->submit(-value=>'Submit');
print $query->endform();
print $query->end_html();
} else {
my $one = 1;
my $two = 2;
exec "./testee.pl $one $two";
}
#----------------------- CGI Script testee.pl
#!/usr/bin/perl -w
use strict;
use CGI;
my $query = new CGI;
print $query->header();
print $query->start_html();
print "Arguments: @ARGV";
print $query->end_html();
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Oct 2000 17:07:11 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: chmod problems? I think.
Message-Id: <87em101uy8.fsf@limey.hpcc.uh.edu>
>> On Sat, 28 Oct 2000 16:04:11 -0500,
>> Steve <cochise@sky.net> said:
> I have a form in our main .html directory that when
> submitted, sends the data to a script (Perl) in the
> "cgi-bin" directory. The program creates 2 different
> files and updates a third. Updating the file goes OK,
> but when I try to access any of the files with my
> browser I've been getting the same error:
> "Forbidden: You don't have permission to access
> /cgi-bin/filename.html on this server."
I think chmod() is a small scarlet fish.
Don't create HTML documents in the cgi-bin directory. You
(i..e the uid of the process running CGI programs in
/cgi-bin) almost certainly don't own the directory.
Put the files somewhere else, i.e. somewhere under the
HTML document space. Alternatively, make the program
return the HTML as a dynamic document.
But in any case, this is more of a web-server or CGI group
question, follow-up set as best guess.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Sat, 28 Oct 2000 17:46:01 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: func (a) func !a! func ~a~ func a .... more?
Message-Id: <slrn8vmi8p.mme.tadmc@magna.metronet.com>
On Sat, 28 Oct 2000 20:53:24 GMT, Dave Brondsema <brondsem@my-deja.com> wrote:
>In article <x77l6tlfzv.fsf@home.sysarch.com>,
> Uri Guttman <uri@sysarch.com> wrote:
>> >>>>> "DB" == Dave Brondsema <brondsem@my-deja.com> writes:
[ snip trying to use alternate delimiters for function argument lists ]
>> DB> you're right. What I really want to know is what can I use
>instead
>> DB> of / in a regexp.
>>
>> DB> print qq(1);
>> those are double quoted strings and not regexes. which book or
>education
>> source is leading you to these false beliefs?
>The title "Regexp Quote-Like Operators" from perlop
Don't be absurd.
1) It does not mention "functions". (you did)
2) It does not mention "qq". (you did)
Wherever it came from, it wasn't where you are saying it came from...
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 28 Oct 2000 23:50:24 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: func (a) func !a! func ~a~ func a .... more?
Message-Id: <8tfonu$ela$1@nnrp1.deja.com>
In article <slrn8vmi8p.mme.tadmc@magna.metronet.com>,
tadmc@metronet.com (Tad McClellan) wrote:
> On Sat, 28 Oct 2000 20:53:24 GMT, Dave Brondsema <brondsem@my-
deja.com> wrote:
> >In article <x77l6tlfzv.fsf@home.sysarch.com>,
> > Uri Guttman <uri@sysarch.com> wrote:
> >> >>>>> "DB" == Dave Brondsema <brondsem@my-deja.com> writes:
>
> [ snip trying to use alternate delimiters for function argument
lists ]
>
> >> DB> you're right. What I really want to know is what can I use
> >instead
> >> DB> of / in a regexp.
> >>
> >> DB> print qq(1);
>
> >> those are double quoted strings and not regexes. which book or
> >education
> >> source is leading you to these false beliefs?
>
> >The title "Regexp Quote-Like Operators" from perlop
>
> Don't be absurd.
I try not to, but it slips through occasionally.
>
> 1) It does not mention "functions". (you did)
>
I originally (and mistakenly) thought that qq was a function because it
seemed to act like one. I have since realized my mistake.
> 2) It does not mention "qq". (you did)
It does. The 4th section under this title is named qq/STRING/
>
> Wherever it came from, it wasn't where you are saying it came from...
>
> --
> Tad McClellan SGML consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
>
--
Dave Brondsema
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Oct 2000 15:37:14 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: grep vs. a subroutine to find an occurance of an element in a list
Message-Id: <m3n1fopurp.fsf@dhcp11-177.support.tivoli.com>
clay@panix.com (Clay Irving) writes:
> I'm not seeing something and it's probably right in front of my nose.
>
> The FAQ indicates:
>
> Please do not use
>
> $is_there = grep $_ eq $whatever, @array;
>
> or worse yet
>
> $is_there = grep /$whatever/, @array;
[recommended loop from FAQ omitted]
> But why is this subroutine much slower than grep?
For at least three reasons, but one of them is the real killer.
> #!/usr/local/bin/perl -w
>
> use Benchmark;
>
> open F, "foo" or die "$!\n";
> @foo = <F>;
>
> foreach (@foo) {
> # don't do anything...
> }
>
> $count = 500;
>
> timethese($count, {
> 'grep' => '$found = grep(/ratchet/, @foo);',
> 'lookfor' => 'if (lookfor("ratchet", @foo)) { $found = 1; }'
First (minor) problem: you have an "if" here that is completely
unnecessary and simply wastes time. Second (also minor) problem is
that you have a subroutine call in one but not the other. That also
skews the result. I changed it to:
'grepfor' => '$found = grepfor("ratchet", @foo);'
'lookfor' => '$found = lookfor("ratchet", @foo);'
> });
sub grepfor {
my $string = shift;
grep /$string/, @_;
}
> sub lookfor {
>
> my $is_there = 0;
> my ($string, @array) = @_;
BINGO!!! Here's the real problem. You are copying the entire array
needlessly. That totally skews the results. Change it to:
my $string = shift;
and this line:
> foreach $elt (@array) {
to:
foreach my $elt (@_) {
> if ($elt =~ /$string/) {
> $is_there = 1;
> last;
> }
> }
> return $is_there;
> }
>
> Result:
>
> grep: 4 wallclock secs ( 3.47 usr + 0.00 sys = 3.47 CPU) @ 144.09/s
> (n=500)
> lookfor: 6 wallclock secs ( 5.90 usr + 0.00 sys = 5.90 CPU) @ 84.75/s
> (n=500)
You didn't include the data from file "foo", so I had to make up my
own. I placed "ratchet" fairly early in the file, which will
certainly skew the results toward the loop. A more fair comparison
would move "ratchet" randomly for each iteration of the benchmark.
Removing the copy of the array is the real key -- the loop wins by a
significant margin at that point. Fixing the other two problems makes
the margin even larger:
(And I had to up the iterations to get useful results for the loop.)
Benchmark: timing 5000 iterations of grep, lookfor...
grep: 38 wallclock secs (37.45 usr + 0.14 sys = 37.59 CPU) @
133.01/s (n=5000)
lookfor: 2 wallclock secs ( 1.92 usr + 0.00 sys = 1.92 CPU) @
2604.17/s (n=5000)
So the grep with a subroutine call is just a little bit slower than it
was, but the lookfor without the array copy (and without the extra
conditional) is a lot faster.
When doing benchmarks, you really need to focus on controlling all of
the extra factors that are not what you are explicitly measuring.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 28 Oct 2000 17:33:35 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: grep vs. a subroutine to find an occurance of an element in a list
Message-Id: <39fb624f@cs.colorado.edu>
In article <slrn8vmggu.rp9.clay@panix3.panix.com>,
Clay Irving <clay@panix.com> wrote:
>>> The FAQ indicates:
>>>
>>> Please do not use
>>>
>>> $is_there = grep $_ eq $whatever, @array;
>>>
>>> or worse yet
>>>
>>> $is_there = grep /$whatever/, @array;
>>>
>>> These are slow (checks every element even if the
>>> first matches), inefficient (same reason), and
>>> potentially buggy (what if there are regex
>>> characters in $whatever?). If you're only testing
>>> once, then use:
>>>
>>> $is_there = 0;
>>> foreach $elt (@array) {
>>> if ($elt eq $elt_to_find) {
>>> $is_there = 1;
>>> last;
>>> }
>>> }
>>> if ($is_there) { ... }
>>>
>>> But why is this subroutine much slower than grep?
Because the FAQ contains a mere *demonstration* of a better approach.
>I changed the subroutine to:
>
> sub lookfor {
> my $is_there = 0;
> my ($num, @array) = @_;
>
> foreach $elt (@array) {
> if ($elt eq $num) {
> $is_there = 1;
> last;
> }
> }
> return $is_there;
> }
>
>@foo contains 3,395 7 digit numbers. The result is:
>
> Benchmark: timing 500 iterations of grep, lookfor...
> grep: 6 wallclock secs ( 6.39 usr + 0.00 sys = 6.39 CPU) @ 78.25/s
> (n=500)
> lookfor: 10 wallclock secs (10.26 usr + 0.00 sys = 10.26 CPU) @ 48.73/s
> (n=500)
>
>I commented out the contents of the subroutine and reran the program. The
>result is:
>
> Benchmark: timing 500 iterations of grep, lookfor...
> grep: 6 wallclock secs ( 6.32 usr + 0.00 sys = 6.32 CPU) @ 79.11/s
> (n=500)
> lookfor: 1 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU) @ 2631.58/s
> (n=500)
> (warning: too few iterations for a reliable count)
>
>grep still wins.
From the Camel:
To get the most out of the C<Benchmark> module, you'll need a
good bit of practice. It isn't usually enough to run a couple
different algorithms on the same data set, because the timings
only reflect how well those algorithms did on that particular
data set. To get a better feel for the general case, you'll
need to run several sets of benchmarks, varying the data sets
used.
Benchmarks are only a tool. You can extrapolate nothing about
general behavior by looking at one specific case, which is all
anyone here has bothered to do. grep() only won because
it's really something of a rigged benchmark.
Problems with your demonstrated approaches include at the very
least, the following oversights:
* lack of a tuned subroutine
this is severe stack abuse
it's the wrong check, too
* lack of variance in dataset sizes
try going up or down 3 orders of magnitude to find out
what happens if you use 1/10th, 1/100th, or 1,1000th
that dataset size
what happens if you use 10x or 100x or 1000x that dataset size
* lack of variance in where the hit occurs
what if it's at the start?
what if it's 1,10th, 1/100th, or 1/1000th the way in?
what if it's 1,10th, 1/100th, or 1/1000th from the end?
what if it's not there at all?
* lack of correctness
if number is 99, and you grep /99/, 1999, you will
get a false hit.
Let's just play with a few of these. A proper analysis would,
however, address all of them.
use Benchmark;
$number = 3_395;
for ($i = 0; $i < $number; $i++) {
redo if ($foo[$i] = int rand(1e6)) == $number;
}
#$foo[10] = $number;
timethese 0 => {
'grep' => 'if (! grep(/$number/, @foo)) { $count6++; } ',
'hislookfor' => 'if (! hislookfor($number, @foo)) { $count6++; }',
'mylookfor' => 'if (! mylookfor($number, \@foo)) { $count6++; }',
};
sub hislookfor {
my $is_there = 0;
my ($num, @array) = @_;
foreach $elt (@array) {
if ($elt eq $num) {
$is_there = 1;
last;
}
}
return $is_there;
}
sub mylookfor {
my $num = shift;
local *array = shift;
$_ == $num && return 1 for @array;
}
Now, the array does not contain the hit. Even so, the timings
are as follows:
Benchmark: running grep, hislookfor, mylookfor, each for at least 3 CPU seconds...
grep: 4 wallclock secs ( 3.21 usr + 0.00 sys = 3.21 CPU) @ 120.25/s (n=386)
hislookfor: 4 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU) @ 61.66/s (n=193)
mylookfor: 4 wallclock secs ( 3.18 usr + 0.00 sys = 3.18 CPU) @ 213.84/s (n=680)
Summarized, that's
grep: 120.25/s
hislookfor: 61.66/s
mylookfor: 213.84/s
Clearly, my lookfor is better than either of the other two techniques.
Now, what happens if the hit if half-way through? That is:
$foo[ $number/2 ] = $number;
That produces these numbers:
grep: 123.08/s
hislookfor: 71.29/s
mylookfor: 423.99/s
What happens if the hit is 1/10th the way through?
$foo[ $number * 0.10 ] = $number;
grep: 121.77/s
hislookfor: 81.94/s
mylookfor: 2018.18/s
I think you can see where this is going. At 1/100th the way through:
$foo[ $number * 0.01 ] = $number;
grep: 120.54/s
hislookfor: 88.42/s
mylookfor: 13155.45/s
And finally, at the very first element:
$foo[ 0 ] = $number;
grep: 120.00/s
hislookfor: 87.93/s
mylookfor: 30719.81/s
Now lets vary the number of elements.
With 1/10th the elements (and the number missing), you get this:
grep: 1226.73/s
hislookfor: 651.88/s
mylookfor: 2004.38/s
But with 10x the elements (and the number missing), you get this:
grep: 10.49/s
hislookfor: ^C'd
mylookfor: 18.51/s
Yes, hislookfor is just too slow for me to wait for. After a few minutes,
I impatiently interrupted it.
That's enough. You can work through the rest of it on your own.
I hope this has proven enlightening.
--tom
------------------------------
Date: Sun, 29 Oct 2000 01:52:08 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: grep vs. a subroutine to find an occurance of an element in a list
Message-Id: <ant2900089eefNdQ@oakseed.demon.co.uk>
In article <39fb624f@cs.colorado.edu>, Tom Christiansen
<URL:mailto:tchrist@perl.com> wrote:
>
> sub mylookfor {
> my $num = shift;
> local *array = shift;
> $_ == $num && return 1 for @array;
> }
The local *array = shift; line looks like magic to my untrained eye.
Could you point me to a page in the Camel where I can read up on
what's happening please. (Still don't have perldoc.)
In article <8tfeh001bb1@news2.newsguy.com>, Daniel Chetlin
<URL:mailto:daniel@chetlin.com> wrote:
>
> sub lookfor {
> my $is_there = 0;
> my ($string, $array) = @_;
> /$string/ && return 1 for (@$array);
> return 0;
> }
The my ($string, $array) = @_; line looks like $array would end up
being a simple scalar containing the value of the second element of @_
but then it is used as if it were a reference to an array. I assume
this is yet more of the same kind of magic. Can I read up on it in the
same place as the local *array = shift; incantation, or this subtly
different in some way?
Thanks.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Sun, 29 Oct 2000 00:59:52 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: grep vs. a subroutine to find an occurance of an element in a list
Message-Id: <slrn8vmtk4.vkh.tjla@thislove.dyndns.org>
I was shocked! How could Tom Christiansen <tchrist@perl.com>
say such a terrible thing:
>In article <slrn8vmggu.rp9.clay@panix3.panix.com>,
>Clay Irving <clay@panix.com> wrote:
>
>Because the FAQ contains a mere *demonstration* of a better approach.
>
>>I changed the subroutine to:
>>
>> sub lookfor {
>> my $is_there = 0;
>> my ($num, @array) = @_;
>>
>> foreach $elt (@array) {
>> if ($elt eq $num) {
>> $is_there = 1;
>> last;
>> }
>> }
>> return $is_there;
>> }
>>grep still wins.
>Benchmarks are only a tool. You can extrapolate nothing about
>general behavior by looking at one specific case, which is all
>anyone here has bothered to do. grep() only won because
>it's really something of a rigged benchmark.
>
>Problems with your demonstrated approaches include at the very
>least, the following oversights:
<snip>
I think the main problem with the benchmarks posted is that the things
they are comparing are just too different. His version uses 'eq', yours
uses '==' while the grep version uses a regex. I think the overhead of
doing the regex comparison or doing the bytewise string comparison will
obscure whether or not your version really is faster or not. I don't
know if you did that on purpose or not but from the point of view of
getting an accurate benchmark I think that they should (say) all use
'==' or 'eq' or a regex and stick with that.
Perhaps an analogy is in order. It's like doing a speed-test on several
different cars but having one drive over a gravel track and one having
to drive through knee high mud while the third is on a formula one
racing track. Sure you'll get an answer, but does the answer tell you
anything you didn't already know?
>Let's just play with a few of these. A proper analysis would,
>however, address all of them.
What I did was I took your version and changed them so that they all
used '==' in the comparison. I then ran them with several different
types of input:
size = 3395, array doesn't contain the hit:
Benchmark: running grep, hislookfor, mylookfor, each for at least 3 CPU
seconds...
grep: 3 wallclock secs ( 3.25 usr + 0.00 sys = 3.25 CPU) @
226.15/s (n=735)
hislookfor: 4 wallclock secs ( 3.09 usr + 0.00 sys = 3.09 CPU) @
82.52/s (n=255)
mylookfor: 3 wallclock secs ( 3.04 usr + 0.00 sys = 3.04 CPU) @
178.95/s (n=544)
hit halfway through:
Benchmark: running grep, hislookfor, mylookfor, each for at least 3 CPU
seconds...
grep: 3 wallclock secs ( 3.19 usr + 0.00 sys = 3.19 CPU) @
223.51/s (n=713)
hislookfor: 4 wallclock secs ( 3.18 usr + 0.00 sys = 3.18 CPU) @
113.84/s (n=362)
mylookfor: 3 wallclock secs ( 3.16 usr + 0.00 sys = 3.16 CPU) @
356.33/s (n=1126)
As you can see, the tuned version has already overtaken grep, however
this does point out that in certain circumstances, grep *can* be faster.
Now when we increase the size by a factor of ten:
(array not containing the hit)
Benchmark: running grep, hislookfor, mylookfor, each for at least 3 CPU
seconds...
grep: 4 wallclock secs ( 3.09 usr + 0.00 sys = 3.09 CPU) @
19.42/s (n=60)
hislookfor: 4 wallclock secs ( 3.01 usr + 0.01 sys = 3.02 CPU) @
6.95/s (n=21)
mylookfor: 4 wallclock secs ( 3.05 usr + 0.00 sys = 3.05 CPU) @
16.39/s (n=50)
hit halfway through:
Benchmark: running grep, hislookfor, mylookfor, each for at least 3 CPU
seconds...
grep: 4 wallclock secs ( 3.07 usr + 0.01 sys = 3.08 CPU) @
19.48/s (n=60)
hislookfor: 3 wallclock secs ( 3.02 usr + 0.02 sys = 3.04 CPU) @
8.88/s (n=27)
mylookfor: 4 wallclock secs ( 3.44 usr + 0.01 sys = 3.45 CPU) @
33.33/s (n=115)
I won't post the rest of the results, but when I run the test with other
array sizes the results are more or less the same (grep is fastest if
the array doesn't contain the hit).
Your other points about Benchmarking were very valid however. I think
it's obvious that the array copy is killing the OP's version (the
typeglob trick is very nice by the way).
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
All those who believe in psychokinesis, raise my right hand.
------------------------------
Date: Sun, 29 Oct 2000 00:38:43 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: How can i find my ip?
Message-Id: <m3y9z8xyzx.fsf@solo.david-steuber.com>
</michael> writes:
' Ipconfig at the dos prompt
What is a dos prompt?
perldoc -q address:
How do I find out my hostname/domainname/IP address?
The normal way to find your own hostname is to call the
``hostname`' program. While sometimes expedient, this has
some problems, such as not knowing whether you've got the
canonical name or not. It's one of those tradeoffs of
convenience versus portability.
The Sys::Hostname module (part of the standard perl
distribution) will give you the hostname after which you
can find out the IP address (assuming you have working
DNS) with a gethostbyname() call.
use Socket;
use Sys::Hostname;
my $host = hostname();
my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));
Probably the simplest way to learn your DNS domain name is
to grok it out of /etc/resolv.conf, at least under Unix.
Of course, this assumes several things about your
resolv.conf configuration, including that it exists.
(We still need a good DNS domain name-learning method for
non-Unix systems.)
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: Sun, 29 Oct 2000 00:40:13 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: How can i find my ip?
Message-Id: <m3u29wxyxf.fsf@solo.david-steuber.com>
Larry Rosler <lr@hpl.hp.com> writes:
' Which is copied verbatim from perlfaq9: "How do I find out my
' hostname/domainname/IP address?"
Which I just posted :-(
(not the whole faq, just that portion)
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: Sun, 29 Oct 2000 00:46:37 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: How could post a HTML with images to newsgroup?
Message-Id: <m3og04xymq.fsf@solo.david-steuber.com>
kevin metcalf <xzrgpnys@yvtugubhfrovm.pbz> writes:
' However, if you wish to post graphics into (say) and alt.binaries.*
' why not go ask them?
If this is the original poster's intention, Perl does have a UUENCODE
module. Most binaries groups use UUENCODE and may split the encoded
output accross multiple messages to improve propagation.
From what I've seen, I think there are posting robots already
running...
But they will only die tired ;-) (if you get this joke, you just might
be a gun nut :)
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: Sun, 29 Oct 2000 09:21:58 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how to find oldest file in a directory
Message-Id: <slrn8vmkc6.ac5.mgjv@martien.heliotrope.home>
On Sat, 28 Oct 2000 21:27:11 GMT,
mr_potato_head@my-deja.com <mr_potato_head@my-deja.com> wrote:
> HI,
> I have a script using the find module looking for files that have
> today's date in the filename. Out of the list returned, how can I find
> out which file is the oldest? (most current file) thanks in
> advance...
Do you want to know which file is the oldest, or which is the most
'current'. Normally 'most current' means youngest.
Anyway, since you don't give us any clue about how your filenames are
formatted, or how those dates look, and you also don't give us any clue
on whether any other program can ever modify ctime or mtime, or whether
ctime and mtime can be reliably used to reflect that same date, I'll just
give you a list of possible things to use:
Get the list of files with opendir and readdir. If the list is large,
process them in a loop, otherwise use a grep to create a list of
matching files.
# perldoc -f opendir
# perldoc -f readdir
For each file name, extract the date (use some regex for the name, or
use stat() to get the ctime if those aren't modified by anything else,
and they are equivalent to that date in the name). Remember the most
(or least) recent date. At the end of the loop, you'll have your answer.
How to compare the dates? If you use stat and the ctime field, use <, >
<=, >= or <=>, depending on what you're doing. If you need to parse a
textual date, well, there can be millions of possible strings to parse.
You'll have to show more specific examples.
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
Date: Sat, 28 Oct 2000 23:04:07 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How to loop in the background
Message-Id: <39FB5E69.2793C374@home.com>
7brankin9@my-deja.com wrote:
>
> So: I need to wrap "system" in some sort of Perl loop (a for
> statement?) that goes into the background...any ideas greatly
> appreciated.
perldoc -q background
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Sun, 29 Oct 2000 00:51:45 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: How to protect perl program from pirates?
Message-Id: <m3k8asxye6.fsf@solo.david-steuber.com>
"Paul Antonov" <antonov@lib.bmstu.ru> writes:
' I need to protect my perl program...
' How can I crypt... compile...or do something else to
' privent free reaching of source codes?
Others have given you sensible answers. Now I'm going to give you one
that works. Destroy all copies of the Perl program source files,
including any backups that may be stored off site. That will prevent
anyone from stealing your code.
Even if you translated the Perl program into an ELF or COFF (or
whatever architecture format you are interested in) binary, it will
always be possible to reverse engineer it.
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: Sun, 29 Oct 2000 01:02:23 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: OT: Yes there _are_ stupid questions. Anyone collect them?
Message-Id: <m3g0lgxxwg.fsf@solo.david-steuber.com>
If this is a FAQ, I haven't found it. Has anyone collected really
stupid questions? By stupid, I don't mean, "how do I substitute foo
for bar?" I mean questions where people ask how to do ethically
questionable things.
eg. How do I write a Perl script to grab the daily Dilbert cartoons
that I can run from a cron job so that I don't have to visit the site
and see all the ads? (A trivial script to write ;-)
I'm sure many whoppers have been posted. No, I do not want frys with
that.
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: Sat, 28 Oct 2000 22:54:39 GMT
From: fallenang3l@my-deja.com
Subject: Re: Perl: ICQ Checker
Message-Id: <8tflfe$cah$1@nnrp1.deja.com>
But why do you want such a thing when ICQ has its own tool for it? The
addy to it is http://www.icq.com/features/web/indicator.html.
In article <%1DK5.173$M86.6157@read2.inet.fi>,
"Teemu Oksanen" <teemu.oksanen@luukku.com> wrote:
>
> > #!/usr/bin/perl -w0
> > print "${\(($_=<>)=~y=ICQ=QIC=)}";
>
> Sorry, but what this should do???
> I meant a script which check, if (for example) ICQ-user #9428573 is
online.
> If he is, then the script prints "online". If he isn't, then it prints
> "offline".
>
> -Teemu
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 29 Oct 2000 00:35:02 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Re: Sending mails from a Unix webserver
Message-Id: <4a14cbf313g.soper@soundhouse.co.uk>
In article <slrn8vmio9.1qb.clay@panix3.panix.com>, Clay Irving
<clay@panix.com> wrote:
> Why don't you use majordomo instead of building a mailing list system
> with Perl?
I'd like to but I don't thnk I have anything to run it on. Our hosting
provider charges for Majordomo so I was thinking of doing it myself. BTW
can Majordomo provide for mailing given subsets of the total subscription?
Thanks
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Sat, 28 Oct 2000 22:14:51 GMT
From: peter pilsl <pilsl@goldfisch.atat.at>
Subject: Re: variable in module
Message-Id: <MPG.14656f107357631b9898fb@news.chello.at>
In article <slrn8vmihk.ac5.mgjv@martien.heliotrope.home>,
mgjv@tradingpost.com.au says...
<skip>
>
> None. Unless you are doing something other than what you are telling us.
> evals can invoke local scoping, but I don't think in this case.
>
> And please, for next time: Real code only.
>
I´m sorry. Here is a real-code-example:
---------start /tmp/test.pl-------
#!/usr/bin/perl -w
use strict;
require '/tmp/pack.pl';
pack::a1();pack::a2();
--------start /tmp/pack.pl -------
package pack;
use strict;
my $s=7;
sub a1 {eval '$s=8;'; warn $@ if $@;}
sub a2 { print $s,"\n"; }
---
and this is the result:
$>/tmp/test.pl
7
$>
when using "our $s=7;" in pack.pl the result is 8 like I expect it to be.
when adding a "print $s;" after the eval-statement in pack::a1 the result
is 88 (yes, its 88 like eighteight).
There is no warning printed out.
Thanx for any help.
--
pilsl@
goldfisch.at
------------------------------
Date: Sun, 29 Oct 2000 11:50:10 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: variable in module
Message-Id: <slrn8vmt22.ac5.mgjv@martien.heliotrope.home>
On Sat, 28 Oct 2000 22:14:51 GMT,
peter pilsl <pilsl@goldfisch.atat.at> wrote:
> In article <slrn8vmihk.ac5.mgjv@martien.heliotrope.home>,
> mgjv@tradingpost.com.au says...
>
> <skip>
> >
> > None. Unless you are doing something other than what you are telling us.
> > evals can invoke local scoping, but I don't think in this case.
> >
> > And please, for next time: Real code only.
> >
>
> I´m sorry. Here is a real-code-example:
>
> ---------start /tmp/test.pl-------
> #!/usr/bin/perl -w
>
> use strict;
> require '/tmp/pack.pl';
>
> pack::a1();pack::a2();
>
> --------start /tmp/pack.pl -------
> package pack;
> use strict;
> my $s=7;
>
> sub a1 {eval '$s=8;'; warn $@ if $@;}
> sub a2 { print $s,"\n"; }
> ---
>
> and this is the result:
> $>/tmp/test.pl
> 7
> $>
>
> when using "our $s=7;" in pack.pl the result is 8 like I expect it to be.
> when adding a "print $s;" after the eval-statement in pack::a1 the result
> is 88 (yes, its 88 like eighteight).
> There is no warning printed out.
The easiest to solve is the question why it prints 88: You get two
prints of 8 each. Only the second one adds a newline.
The others are a bit odd. I would almost say that there is a bug in the
way the eval gets handled in sub a1. According to documentation
eval '$x';
eval { $x };
should be identical. They are not.
sub a1 { eval '$s++'; warn $@ if $@ }
sub a2 { eval {$s++}; warn $@ if $@ }
Should do the same thing, but they do not. However, as you indicated,
adding any usage of $s to a1 will make these two work identically. This
cannot be anything else but a bug.
sub a1 { $s; eval '$s++'; warn $@ if $@; }
What is interesting, however, is that the bug has been present since
Perl 5.004_05 at least. This also draws warnings about Useless use of
private variable in void context at /tmp/pack.pl line 6. (Change to my
$x = $s, or $s = $s to stop that).
I'd say there is something wrong with the choices that are being made
about which variable gets to be seen as in scope here. I don't know
which $s is used in the first sub a1, but I suspect it's a localised
copy of the package variable $pack::s. It doesn't modify $pack::s or
$::s, so it's not that. This behaviour is certainly not according to
the documentation on eval. I'd say the behaviour is wrong, but it
wouldn't be the first time I've trusted the documentation too much. In
reality, the documentation carries not a lot of weight in determining
what's correct behaviour.
Unless one of the people with knowledge of Perl internals says
otherwise, I'd probably prepare a bug report. Either the behaviour is
wrong, or the documentation. They should be synchronised.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Sun, 29 Oct 2000 11:38:28 +1100
From: "Joseph Chakrvarti" <josephmariadassou@primus.com.au>
Subject: Re: what does /warn "$x" if "$x"/ mean
Message-Id: <39fb63cd@news.iprimus.com.au>
Obviuosly if I I had written the whole program I would know what I am doing.
I patched various code snippets from ImageMagick doco and from the "camel"
book and I got it to work. I suppose next time I write
while((c=getc(fp)!=EOF)
I will have to mention that I took it from K& R.
$count is not some random value. It is correct for the set of files I
tested.
Thanks for your detailed reply. Although I am not sure I have understood
what is going I will just take it as one of life's pleasant unexplained
surprises.
joe
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8vkrpe.c8.mgjv@martien.heliotrope.home...
> On Fri, 27 Oct 2000 03:32:24 GMT,
> joechakra@my-deja.com <joechakra@my-deja.com> wrote:
> > Here is a short perl script(?) I wrote to split images and it works:
> > use Image::Magick;
> > $fname=shift;
> > print "input file=$fname\n";
> > $image = new Image::Magick;
> > $x=$image->Read($fname);
> > warn "$x" if "$x";
> > $count=0+$x;
> > $of="out001";
> > print "$count";
>
> I think this program is supposed to read something like
>
> use strict;
> use Image::Magick;
> my $fname = shift;
> print "Input file '$fname'\n";
> my $im = Image::Magick->new();
> my $rc = $im->Read($fname);
> die "(Read:$fname) $rc" if $rc;
>
> # And here I have no clue anymore what you are trying to achieve, see
> # later
>
> > My question what is the meaning of
> > warn "$x" if "$x";
> > $count=0+$x;
> >
> > Is $x a string, a number, a list, or a class? warn does not produce any
> > output. But count prints as "2"
>
> You have already had some explanations about what all this generally
> means. $x can contain any scalar value. However, there are many scalar
> values, and how you use them, and what you do with them, depends on
> context.
>
> In the context of Image::Magick $x is the result code of the call to
> $image->Read($fname). For Image::Magick there are two different kinds of
> methods, ones that returns objects and ones that don't. The ones that
> return objects should be checked like this:
>
> my $obj = $im->Clone();
> if (! ref $obj)
> {
> # You have an error, exit the program
> die $obj;
> }
>
> In other words: if the returned thing isn't an object, it's an error
> message. So, the return value from these methods is either an
> Image::Magick object,
>
> The other class of methods for Image::Magick returns undef on success,
> or an error string on failure. So you check them this way:
>
> my $rc = $im->Read($fname);
> if ($rc)
> {
> # There's an error, exit
> die $rc;
> }
>
> A convenient shorthand for this is
>
> die $rc if $rc;
>
> or if you only want to warn, as in your code:
>
> warn $rc if $rc;
>
> One other thing is important to know aboiut these error messages: They
> contain an error number.
>
> my $errno = $rc =~ /(\d+)/;
>
> Error numbers of 400 and above mean that something went seriously
> wrong, and you should destroy the object, and no longer use it.
> Everything below that is up to you to decide.
>
> What I don't understand is the
>
> $count = 0 + $x;
>
> In the context of your program, $x can be either undefined (the load of
> your image failed), or it contains a string. I suspect that you copied
> this code from somewhere, and that that line is an attempt to put $x in
> a numerical context, to extract the error number, as I did above with a
> regex. But it doesn't make sense in your code, and I wouldn't use it
> that way.
>
> Doing 0 + $x makes no sense whatsoever if the read was successful,
> because you're adding 0 to a reference, only to end up with a totally
> meaningless number. In this case obviously 2.
>
> You said that you wrote it. Maybe you should come out clean and say that
> you copied it, and have another look at the code you copied it from,
> maybe this time with the thoughts above in mind.
>
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | You can't have everything, where
> Commercial Dynamics Pty. Ltd. | would you put it?
> NSW, Australia |
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4752
**************************************