[23683] in Perl-Users-Digest
Perl-Users Digest, Issue: 5890 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 4 00:05:42 2003
Date: Wed, 3 Dec 2003 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 3 Dec 2003 Volume: 10 Number: 5890
Today's topics:
Re: Add File Names with Time Stamp <Temp@NoSuchDomain.Info>
Re: Add File Names with Time Stamp (Jay Tilton)
Re: Add File Names with Time Stamp <noreply@gunnar.cc>
Re: Can an .OCX be used in Perl? <martinvalley@comcast.net>
Re: Can perl be used to test ISP upload speed? <someone@somewhere.nb.ca>
Re: Can perl be used to test ISP upload speed? <noreply@gunnar.cc>
Re: Don't Read - Testing <Alquemius@hotmail.com>
Re: Don't Read - Testing <matthew.garrish@sympatico.ca>
Re: Don't Read - Testing (Malcolm Dew-Jones)
Re: Don't Read - Testing (Tad McClellan)
Re: First Perl Question - about sorting numeric arrays (BKennedy)
Re: How to disable print() function buffering in perl? <jurgenex@hotmail.com>
Re: In search of elegant code: is variable is within a <usenet@morrow.me.uk>
Re: In search of elegant code: is variable is within a <usenet@morrow.me.uk>
Re: In search of elegant code: is variable is within a <glex_nospam@qwest.invalid>
Re: In search of elegant code: is variable is within a (Jay Tilton)
Re: In search of elegant code: is variable is within a <pinyaj@rpi.edu>
Re: In search of elegant code: is variable is within a <matthew.garrish@sympatico.ca>
Re: In search of elegant code: is variable is within a (Malcolm Dew-Jones)
Re: question about installation of GD::Text on cygwin ( (Upstart)
Re: redirect using location header does not work from a <flavell@ph.gla.ac.uk>
UDP Log & CPU Usage <nospam.hciss@yahoo.com>
Re: Useless use of private variable in void context at <REMOVEsdnCAPS@comcast.net>
Re: using GD module <mgjv@tradingpost.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 04 Dec 2003 03:31:32 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Re: Add File Names with Time Stamp
Message-Id: <oUxzb.147322$Ec1.5888454@bgtnsc05-news.ops.worldnet.att.net>
> > for (@dots) {
> >
> > ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
> > $atime,$mtime,$ctime,$blksize,$blocks)
> > = stat($_);
>
> I would always be inclined to use File::stat: put
> use File::stat;
> at the top and then you can simply say
> my $mtime = stat($_)->mtime;
question. what is the difference between using File::stat as your way or the
one without as my war? Do I have to use File::stat before I can use my
$mtime = stat($_)->mtime;?
> .
>
> > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> > localtime($mtime);
> > $year = sprintf("%02d", $year % 100);
> > $mon = sprintf("%02d", $mon % 100);
> > $mday = sprintf("%02d", $mday % 100);
> > $hour = sprintf("%02d", $hour % 100);
> > $min = sprintf("%02d", $min % 100);
> > $sec = sprintf("%02d", $sec % 100);
>
> Why are all these '% 100'? $year, OK, it's necessary; the others will
> never be greater than 100 anyway.
all %100 are must!!! for instance 11/03 and 01/13 wiill all get 113, so I
insist to use 2 digit for all month and day info.
>
> I would use POSIX::strftime for this: put
> use POSIX qw/strftime/;
> at the top and then say
> my $timestamp = strftime "%y%m%d%H%M%S", localtime stat($_)->mtime;
> , but I know there are those in this group who wouldn't :).
>
> > $new= "$year$mon$mday$hour$min$sec.jpg";
> > print "$new\n";
>
> I am assuming here that when you say 'at the end of the file' you mean
> before the '.jpg'? :)
> Here you want to add:
>
> my $ext = "";
> while(-e "$timestamp$ext.jpg") {
> $ext++;
> $ext = "A" if $ext == 1;
> }
>
what is te ext for? if you have ext as '', then $timestampe$ext is nothing
but still $timestamp.
how can you ext++ a string? if you ''++ do you get 1 or A or what? can you
show me some reference to read about -e? thank you.
my scripts work 100% fine with my 1000 files. i am not sure if what you
added is a MUST or a Better, because I don't understand your concerns. Could
you give some example in which why your changed code is better and mine is
not working.
> > rename $_, $new;
>
> rename $_, "$timestamp$ext.jpg";
>
> There is a race condition here between the -e and the rename, which
> basically means 'don't mess around and add files to the directory
> while the script is running'.
------------------------------
Date: Thu, 04 Dec 2003 04:21:36 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Add File Names with Time Stamp
Message-Id: <3fceb378.946224840@news.erols.com>
"Picker Leon" <Temp@NoSuchDomain.Info> wrote:
[Further author attributions lost.]
: > > for (@dots) {
: > >
: > > ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
: > > $atime,$mtime,$ctime,$blksize,$blocks)
: > > = stat($_);
: >
: > I would always be inclined to use File::stat: put
: > use File::stat;
: > at the top and then you can simply say
: > my $mtime = stat($_)->mtime;
:
: question. what is the difference between using File::stat as your way or the
: one without as my war?
You could try reading the File::stat documentation. The first line
explains it pretty well.
File::stat - by-name interface to Perl's built-in stat() functions
: Do I have to use File::stat before I can use my $mtime = stat($_)->mtime;?
Yes.
: > > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
: > > localtime($mtime);
: > > $year = sprintf("%02d", $year % 100);
: > > $mon = sprintf("%02d", $mon % 100);
: > > $mday = sprintf("%02d", $mday % 100);
: > > $hour = sprintf("%02d", $hour % 100);
: > > $min = sprintf("%02d", $min % 100);
: > > $sec = sprintf("%02d", $sec % 100);
: >
: > Why are all these '% 100'? $year, OK, it's necessary; the others will
: > never be greater than 100 anyway.
:
: all %100 are must!!! for instance 11/03 and 01/13 wiill all get 113
How could any of those scalars ever contain the value "11/03" or "01/13" ?
Do you have any idea what localtime() returns?
: how can you ext++ a string? if you ''++ do you get 1 or A or what?
See "Auto-increment and Auto-decrement" in perlop.
: can you show me some reference to read about -e?
"-e" is one of the file test operators. See "-X FILEHANDLE" in perlfunc.
------------------------------
Date: Thu, 04 Dec 2003 05:37:11 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Add File Names with Time Stamp
Message-Id: <bqmdrp$24giqb$1@ID-184292.news.uni-berlin.de>
Picker Leon wrote:
>>> for (@dots) {
>>>
>>> ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
>>> $atime,$mtime,$ctime,$blksize,$blocks)
>>> = stat($_);
>>
>> I would always be inclined to use File::stat: put
>> use File::stat;
>> at the top and then you can simply say
>> my $mtime = stat($_)->mtime;
>
> question. what is the difference between using File::stat as your
> way or the one without as my war?
I suppose it's more about personal preferences.
What strikes me is that there is no reason to initiate all those
variables just to get the last modify time. Since you are only
interested in the 10:th element in the list generated by the stat()
function, this is how I would have done it (without File::stat):
my $mtime = (stat $_)[9];
>>> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
>>> localtime($mtime);
>>> $year = sprintf("%02d", $year % 100);
>>> $mon = sprintf("%02d", $mon % 100);
>>> $mday = sprintf("%02d", $mday % 100);
>>> $hour = sprintf("%02d", $hour % 100);
>>> $min = sprintf("%02d", $min % 100);
>>> $sec = sprintf("%02d", $sec % 100);
>>
>> Why are all these '% 100'? $year, OK, it's necessary; the others
>> will never be greater than 100 anyway.
>
> all %100 are must!!! for instance 11/03 and 01/13 wiill all get
> 113, so I insist to use 2 digit for all month and day info.
The sprintf() function does that. The '%' operator is redundant
(except for $year).
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 03 Dec 2003 20:52:09 -0700
From: Martin <martinvalley@comcast.net>
Subject: Re: Can an .OCX be used in Perl?
Message-Id: <mqbtsvkfofebq575h8f3njdkb1rj42tucj@4ax.com>
On 03 Dec 2003 21:52:20 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>On Wed, 03 Dec 2003 13:02:37 -0700,
> Martin <martinvalley@comcast.net> wrote:
>> Can an .OCX (ActiveX) that is normally used in a Windows Visual Basic
>> program be used in a Perl/Unix environment?
>
>No.
>
>Martien
OK - Thanks.
Martin
------------------------------
Date: Thu, 04 Dec 2003 00:51:43 GMT
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: Can perl be used to test ISP upload speed?
Message-Id: <zyvzb.4186$IF6.198085@ursa-nb00s0.nbnet.nb.ca>
I thought my previous postings already showed that :-)
Actually, the only thing I -have- done with Perl, are CGI scripts running on
web servers, that manipulate data sent to it from forms inside HTML pages.
So I've really only seen where a few variables at a time are sent to a Perl
script and for that matter, the Perl script just updates text files and then
spits out HTML pages in return back to the browser.
The only thought that comes to mind for measuring upload speed is that I'd
have to keep track of time. Then making a few repeated calls to the Perl
script sending a little bit of data at a time. But making repeated calls
wouldn't be a good way either because each time a new channel has to be
created and this takes time not really related to upload speed. I also
don't know the inside of HTTP either. There must be a limit to the amount of
data an HTML document can send back to the web server - but that's another
issue.
Guy
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bqjn76$23379n$1@ID-184292.news.uni-berlin.de...
> Guy wrote:
> > But I can't think of a way that perl could be used to test upload
> > speed.
>
> Then you don't know much about Perl, do you?
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
------------------------------
Date: Thu, 04 Dec 2003 05:56:29 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Can perl be used to test ISP upload speed?
Message-Id: <bqmf08$24mol6$1@ID-184292.news.uni-berlin.de>
[ Please do not top post! ]
Guy wrote:
> Gunnar Hjalmarsson wrote:
>> Guy wrote:
>>> But I can't think of a way that perl could be used to test
>>> upload speed.
>>
>> Then you don't know much about Perl, do you?
>
> I thought my previous postings already showed that :-)
Well, sorry for my sulky reply. I just thought that your original post
was unnecessarily wordy. If I understand you right, you want to know:
"How can I have Perl measure the time it takes to run a certain
operation?"
Basically it can be done like this (assuming the operation takes a few
seconds):
my $starttime = time;
# code for accomplishing something
print 'Done. It took ', time - $starttime, " seconds.\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 4 Dec 2003 01:26:17 +0100
From: "Alquemius" <Alquemius@hotmail.com>
Subject: Re: Don't Read - Testing
Message-Id: <bqlum8$5d812@eui1nw.euskaltel.es>
once again i am sorry.
This is a new world for me,
I dont understand the mistake i made with top-posting, i dont even know what
that is.
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> escribió en el mensaje
news:bqln3u$cen$1@mamenchi.zrz.TU-Berlin.DE...
> Alquemius <Alquemius@hotmail.com> wrote in comp.lang.perl.misc:
> > I am sorry for that HUGE mistake i have commited. It was just a test of
my
> > account, and i needed to do it in the channel i was intending to use.
>
> This is Usenet, there are no channels. What you are talking to is called
> a newsgroup. If the software you use to access Usenet doesn't allow you
> to post tests to a test group it is unfit for use. Get something else.
>
> You are on new territory and don't know the local habits. Sneering
> irony is not going to endear you to the natives.
>
> > Up from this moment, that i hope everything is properly fixed, the main
> > subject of every mail i post will be Perl Programming and all the terms
> > related with biological aplications of Perl, ok?
>
> Let's hope so. Note that by top-posting you have violated another Usenet
> rule. I guess it's best you take a look at the posting guidelines, posted
> regularly to this group.
>
> [...]
>
> > PS: Its incredible that a 1KB test post can generate a conversation...
lol
>
> ...nor do the natives appreciate outright laughter at their strange
habits.
>
> [TOFU snipped]
>
> Anno
------------------------------
Date: Wed, 3 Dec 2003 21:36:25 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Don't Read - Testing
Message-Id: <75xzb.10435$zf2.1295016@news20.bellglobal.com>
"Alquemius" <Alquemius@hotmail.com> wrote in message
news:bqlum8$5d812@eui1nw.euskaltel.es...
>
> I dont understand the mistake i made with top-posting, i dont even know
what
> that is.
>
Writing your responses at the top of your message. If you look above my
reply you can see who I'm replying to and why. If I were to post on top, you
would have to scroll down through the previous messages to figure out what
I'm talking about. It is also expected that the poster will trim off the
excess parts of the previous message(s) so that it is clear what
specifically is being responded to.
Don't think of posting to Usenet as being akin to writing an email to
someone. Emailers hate it when others intersperse comments in their messages
because it makes following the train of logic more difficult (i.e., it's
usually a conversation between two people, so you know what you're both
talking about). When you post to a technical group, you're usually looking
for an answer, and so people will break down your original message and
comment on the questions you have. If you have follow-up comments or
questions, it only makes sense to keep the pattern going and ask your new
question under whatever part of the reply you have in doubt.
It also provides context for other people to join in the discussion if they
haven't been following from the start. If you're top-posting your responses,
however, most people who haven't been involved from your original post won't
bother to scroll down and read the messages in the thread below to figure
out what's going on. It requires more work to do, so most people will take
the lazy route and just skip your email entirely. If you don't mind that few
people respond to your messages, there's nothing stopping you from
top-posting, but if you want to get the most out of a group it's best to
adhere by certain guidelines of usenetiquette.
Matt
------------------------------
Date: 3 Dec 2003 20:02:39 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Don't Read - Testing
Message-Id: <3fceb1df@news.victoria.tc.ca>
Alquemius (Alquemius@hotmail.com) wrote:
: once again i am sorry.
: This is a new world for me,
: I dont understand the mistake i made with top-posting, i dont even know what
: that is.
Do I smell a troll around here somewhere?
------------------------------
Date: Wed, 3 Dec 2003 22:30:14 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Don't Read - Testing
Message-Id: <slrnbste2m.4r3.tadmc@magna.augustmail.com>
Alquemius <Alquemius@hotmail.com> wrote:
> I am sorry for that HUGE mistake i have commited.
I am pretty sure that you are not.
> and i needed to do it in the channel i was intending to use.
Why do you think that you needed to do it in the channel you
were intending to use?
If it works in a *.test.* newsgroup, it'll work in other newsgroups.
> the main
> subject of every mail i post
mail does not go to Usenet newsgroups.
This is not email.
> will be Perl Programming
Too late I'm afraid, the killfile entries have already been made.
> Once again... sorry.
Yeah right.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Dec 2003 15:42:17 -0800
From: b_t_k@hotmail.com (BKennedy)
Subject: Re: First Perl Question - about sorting numeric arrays
Message-Id: <53240d5a.0312031542.9c16cb3@posting.google.com>
sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnbso7nf.8um.sholden@flexal.cs.usyd.edu.au>...
> On 1 Dec 2003 21:01:32 -0800, BKennedy <b_t_k@hotmail.com> wrote:
> perldoc -f sort
>
> Provides numerous examples on how to use the sort function,
> including sorting numerically.
>
> You should read the posting guileines that are posted here frequently.
> It is also available at:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
Thank you both and your help got me to my answer. Also, I followed
the augustmail link and will now abide by the 'rules'. Thanks again.
------------------------------
Date: Thu, 04 Dec 2003 03:58:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to disable print() function buffering in perl?
Message-Id: <5iyzb.4083$uE6.575@nwrddc02.gnilink.net>
KJ wrote:
[...]
> My logic for why this is happening is this: PERL optimizes the code
> (as all good compilers do) and erroneously thinks that since the "."
> output is static, it is "unimportant" and can be buffered. In the
> latter case, though, it sees that $sortcount is a dynamic variable
> that is modified within the sort function's loop and deems it as
> "important" - therefore outputting it to the screen without buffering
> as the loop is executing.
Actually no. Or not quite. Any decend OS/IO-library buffers output. And the
newline simply triggers a flush of the output buffer.
No compile-time optimization involved at all.
> Any ideas on how I can force PERL to deem that little period (.) as
> important enough to output at runtime (and thus, disable print
> buffering)? Any help or ideas that anyone can provide would be
> greatly appreciated.
Well, the first place to search for help would be the Perl documentation,
wouldn't it.
The FAQ actually has a nice entry: "perldoc -q buffer" or "perldoc -q
flush":
"How do I flush/unbuffer an output filehandle? Why must I do this?"
> <<On a side note, I know there is a command "cerr <<" in C++ that
> outputs a line of text as an "error" to the screen. Basically it is a
> high-priority call to the print queue and followed by an immediate
> buffer flush. Is there such an error output in PERL that I could use?
> Keep in mind, this is for debugging purposes and will NOT be used in
> the program on a regular basis... >>
Well, just write to stderr instead of to stdout
jue
------------------------------
Date: Wed, 3 Dec 2003 23:06:32 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <bqlq9o$aii$2@wisteria.csv.warwick.ac.uk>
see@sig.invalid wrote:
> David Filmer wrote:
>
> > Suppose I want to check if $foo is between 1 and 10. What I would like
> > to do is something elegant like:
> >
> > if (1 < $foo < 10) {blah blah...
> >
> > But Perl doesn't like that. Am I forced to resort to
> >
> > if (1 < $foo && $foo < 10) {blah blah...
> >
> > or is there a more elegant way to write it?
> >
>
> if(abs($foo-5.5)<4.5){blah blah...
You clearly have a different idea of 'elegant' from me... :)
I would have said
if(grep /$foo/, 1..10) {
before that...
No, there isn't. Not till Perl6, anyway.
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
Date: Wed, 3 Dec 2003 23:11:13 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <bqlqih$b4r$1@wisteria.csv.warwick.ac.uk>
Ben Morrow <usenet@morrow.me.uk> wrote:
> I would have said
> if(grep /$foo/, 1..10) {
> before that...
Yeah, OK, not thinking... I've got integers on the brain :(.
Sorry...
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'
------------------------------
Date: Wed, 03 Dec 2003 17:56:35 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <1Huzb.261$pQ2.43713@news.uswest.net>
Ben Morrow wrote:
> see@sig.invalid wrote:
>
>>David Filmer wrote:
>>
>>
>>>Suppose I want to check if $foo is between 1 and 10. What I would like
>>>to do is something elegant like:
>>>
>>> if (1 < $foo < 10) {blah blah...
>>>
>>>But Perl doesn't like that. Am I forced to resort to
>>>
>>> if (1 < $foo && $foo < 10) {blah blah...
>>>
>>>or is there a more elegant way to write it?
>>>
>>
>> if(abs($foo-5.5)<4.5){blah blah...
>
>
> You clearly have a different idea of 'elegant' from me... :)
>
> I would have said
> if(grep /$foo/, 1..10) {
That'd handle 1<=$foo<=10 which is fine, just not what was needed. :-)
if(grep /$foo/, 2..9) {
To be more readable, you could simply throw together a sub/method to do it.
sub is_between {
my ($v, $l, $h) = @_;
$l < $v && $v < $h;
}
if (is_between($foo, 1, 10)) {
See ya
------------------------------
Date: Thu, 04 Dec 2003 00:07:34 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <3fce7909.931263687@news.erols.com>
IneverReadAnythingSentToMe@hotmail.com (David Filmer) wrote:
: Suppose I want to check if $foo is between 1 and 10. What I would like
: to do is something elegant like:
:
: if (1 < $foo < 10) {blah blah...
:
: But Perl doesn't like that. Am I forced to resort to
:
: if (1 < $foo && $foo < 10) {blah blah...
:
: or is there a more elegant way to write it?
Perl's core doesn't have an operator that can do that.
You can make one of your own, if you don't mind a bit of horror in your
elegance.
#!perl
use strict;
use warnings;
package Other;
sub new { bless[sort{$a<=>$b}@_[0,1]] }
use overload '==' => sub {$_[1]>$_[0][0] && $_[1]<$_[0][1]};
*main::between = \&new;
package main;
for my $foo ( 1 .. 10 ) {
print "$foo is between 1 and 10\n"
if $foo == between(1, 10);
}
------------------------------
Date: Wed, 3 Dec 2003 21:46:09 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <Pine.SGI.3.96.1031203214500.1075836A-100000@vcmr-64.server.rpi.edu>
On Wed, 3 Dec 2003, J. Gleixner wrote:
>sub is_between {
> my ($v, $l, $h) = @_;
> $l < $v && $v < $h;
>}
>
>if (is_between($foo, 1, 10)) {
That seems to be a horrible way to send the arguments to the function. If
the function's name is "between", I'd expect to send LOW, VAL, HIGH.
sub is_between { $_[0] < $_[1] and $_[1] < $_[2] }
if (is_between(1, $x, 10)) { ... }
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Wed, 3 Dec 2003 22:00:32 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <Krxzb.10505$zf2.1302592@news20.bellglobal.com>
"Jeff 'japhy' Pinyan" <pinyaj@rpi.edu> wrote in message
news:Pine.SGI.3.96.1031203214500.1075836A-100000@vcmr-64.server.rpi.edu...
> On Wed, 3 Dec 2003, J. Gleixner wrote:
>
> >sub is_between {
> > my ($v, $l, $h) = @_;
> > $l < $v && $v < $h;
> >}
> >
> >if (is_between($foo, 1, 10)) {
>
> That seems to be a horrible way to send the arguments to the function. If
> the function's name is "between", I'd expect to send LOW, VAL, HIGH.
>
You should have read the documentation first...
Matt
------------------------------
Date: 3 Dec 2003 20:08:30 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <3fceb33e@news.victoria.tc.ca>
David Filmer (IneverReadAnythingSentToMe@hotmail.com) wrote:
: Suppose I want to check if $foo is between 1 and 10. What I would like
: to do is something elegant like:
: if (1 < $foo < 10) {blah blah...
: But Perl doesn't like that. Am I forced to resort to
: if (1 < $foo && $foo < 10) {blah blah...
: or is there a more elegant way to write it?
sub is { my $number = shift; bless \$number , 'Hairy' }
sub Hairy::between
{ my ($nref,$lo,$hi) = @_;
return ($lo < $$nref and $$nref < $hi);
}
my $foo = 5;
if ( is($foo)->between(1,10) )
{
print "Yes!";
}
------------------------------
Date: 3 Dec 2003 18:28:29 -0800
From: stimonyhall@netscape.net (Upstart)
Subject: Re: question about installation of GD::Text on cygwin (could be a Makefile q)
Message-Id: <79516caa.0312031828.593d11d8@posting.google.com>
On Wed, 3 Dec 2003, Ben Morrow wrote:
> stimonyhall@netscape.net (Upstart) wrote:
> > /usr/lib/perl5 $ find . -name GD.pm -print
> > ./site_perl/5.8.0/cygwin-multi-64int/GD.pm
> > ./site_perl/5.8.2/cygwin-thread-multi-64int/GD.pm
> <snip>
> >
> Aha! I think this may be your problem. Try the following:
>
> perl -le'print for @INC'
>
> and then try adding
>
> $\ = "\n";
> print for @INC;
>
> to the top of Makefile.PL, *before* it makes any attempt to load
> GD.pm. If either of those lists have the 5.8.0 dir before the 5.8.2
> dir, that is your problem: extensions built against a perl without
> threading are binary-incompatible with perls with.
This seems to be doing the right thing. Here is output:
$ perl Makefile.jim
/home/jhall/lib/perl5
/usr/lib/perl5/5.8.2/cygwin-thread-multi-64int
/usr/lib/perl5/5.8.2
/usr/lib/perl5/site_perl/5.8.2/cygwin-thread-multi-64int
/usr/lib/perl5/site_perl/5.8.2
/usr/lib/perl5/site_perl
.
Could not find/open font
Could not find/open font
Checking if your kit is complete...
Looks good
I then actually removed the all the 5.8.0 stuff just to be sure and
got the same results.... thanks for the help though!
JIM
------------------------------
Date: Thu, 4 Dec 2003 01:22:28 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: redirect using location header does not work from an already redirected doc.
Message-Id: <Pine.LNX.4.53.0312040053310.22396@ppepc56.ph.gla.ac.uk>
It occurs to me that the good Will either solved this one himself, or
took fright at the response on c.l.p.misc; anyway I'm taking the
initative of deciding that this was more of a server issue than a
specifically CGI one, though I could turn out to have been mistaken...
Interested parties could perhaps read the start of the thread on
c.l.perl.misc, or at
http://groups.google.com/groups?selm=c97890a4.0311292035.63b7b660%40posting.google.com
but in brief the questioner wanted to:
- define an errordocument 404 which invoked a CGI script;
- have the CGI script issue some flavour of "Location:" response.
In its original form, his "Location:" response was specifying an
absolute virtual path...
[I had said:]
> > Check the CGI specification. That form of CGI response is mandated to
> > return its results with status 200 (sometimes known as an internal
> > redirection).
I was forgetting of course that there was a 404 status from the
original error. "now read on..."
On Tue, 1 Dec 2003, Will wrote:
> yes, but if the script is pointed to by ErrorDocument 404 the header
> is 404.
OK: required reading at this point (you mentioned apache 1.3.*)
would be http://httpd.apache.org/docs/mod/core.html#errordocument
and http://httpd.apache.org/docs/custom-error.html
As you see, in the situations described there, a reference to an
absolute URLpath ("local URL" as the apache doc puts it) is able to
preserve the original error code, which is normally what one wants.
Whereas, if you succeed in creating an external redirection, then the
original 404 error code will go missing. What actually were you
hoping to achieve in terms of a status code?
In the event, in your original posting, you show that what you got
when the script issued a "Location: /absURLpath" response, was an
error status 404 (from the original error) plus a Location: HTTP
header, which isn't at all what you hoped.
[I had gone on to say:]
> > To get a redirection by means of an external HTTP redirection
> > transaction (HTTP status 30x and HTTP location header), the CGI
> > specification calls for a complete URL in the CGI Location: response.
but of course -if- one does that, then the original 404 status goes
missing, just as it says in the documentation.
> I tried adding an addition header 30x or 200 along with location
> header but it just does not work. My guess would be I would have to
> modify the original top
> HTTP/1.z 404 Not Found header. I am not really sure how.
I have to admit at this point I drew a blank: I'm not quite sure what
you want as the final outcome of this, and also I'm not sure what
Apache is meant to do in this specific scenario - it doesn't seem to
be documented. That's where I decided that it was more in the nature
of an Apache question than a CGI question, hence the cross-posting and
followups set.
hope this helps to move the discussion forward a bit.
------------------------------
Date: Wed, 3 Dec 2003 17:09:43 -0600
From: "Matt" <nospam.hciss@yahoo.com>
Subject: UDP Log & CPU Usage
Message-Id: <vssra4jpcf5d08@corp.supernews.com>
I wrote the below UDP logger. The syslog in Linux did not do what I wanted
so I wrote this. Its supposed to fork and stay resident. Seems to work
fine. My question is how much CPU will it use? Is it going to be a real
hog being it just loops through constantly? Is this a bad way to do it?
Also, where I use: "gethostbyaddr($ipaddr, AF_INET)" I would rather just use
the IP source address but could not figure out how to do that.
Matt
#!/usr/bin/perl -w
#udp logging
use IO::Socket;
use LWP::Simple;
use Time::localtime;
close(STDIN);
close(STDOU);
close(STDERR);
exit if (fork());
exit if (fork());
while (1){
my($sock, $msg, $PORTNO, $LPATH);
$PORTNO = 5151;
$LPATH = "/home/logs/";
$sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp')
or die "socket: $@";
print "awaiting UDP messages on port $PORTNO\n";
while ($sock->recv($msg, 1024)) {
$tm = localtime;
($hour, $minute, $sec, $day, $month, $year) = ($tm->hour, $tm->min,
$tm->sec, $tm->mday, $tm->mon, $tm->year);
$year = ($year+1900);
$month = ($month+1);
if ($hour < 10){
$hour = '0'.$hour;}
if ($minute < 10){
$minute = '0'.$minute;}
if ($day < 10){
$day = '0'.$day;}
if ($month < 10){
$month = '0'.$month;}
if ($sec < 10){
$sec = '0'.$sec;}
$time_stamp = $year.'-'.$month.'-'.$day.'
'.$hour.':'.$minute.':'.$sec;
$file_stamp = $year."-".$month;
my($port, $ipaddr) = sockaddr_in($sock->peername);
open(LOGFILE, ">>".$LPATH.$file_stamp.'.log') || die "cannot
open/create file: $!";
print LOGFILE $time_stamp." ".gethostbyaddr($ipaddr, AF_INET)."
".$msg."\n";
close(LOGFILE);
}
die "recv: $!";
}
------------------------------
Date: Wed, 03 Dec 2003 18:21:36 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Useless use of private variable in void context at parser.cgi line 48.
Message-Id: <Xns9446C51A7D25Fsdn.comcast@216.196.97.136>
jon rogers <jon.rogers@tv.tu> wrote in news:bql1u1$t28$1@news.gu.se:
> Hi,
>
> I keep getting this error message when running my Perl script:
>
> Useless use of private variable in void context at parser.cgi line ...
>
> It is apparently non-fatal as the script executes flawlessly in other
> respects. What am I doing wrong?
Look at the $framble variable on line 44 of wingnut.pl.
--
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
------------------------------
Date: 04 Dec 2003 01:46:49 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: using GD module
Message-Id: <slrnbst4gc.2sd.mgjv@verbruggen.comdyn.com.au>
On Wed, 03 Dec 2003 16:30:34 +1100,
Edo <eddGallary2@hotmail.com> wrote:
> Ben Morrow wrote:
>> Edo <eddGallary2@hotmail.com> wrote:
>> <snip>
>>
>>>my $graph = GD::Graph::lines->new(400, 300);
>>>my $gd = $my_graph->plot(\@data) or die $my_graph->error; <--- 23
>>>
>>>Can't call method "plot" on an undefined value at prog/graph line 23.
>> Why did you put the line 'my $my_graph;' in? Was it because you got a
>> 'strict' error about it not being declared? 'strict' is there to help
>> you find typos and thinkos: don't shut it up by simply putting 'my
>> $var;' at the top until you have checked that you actually did mean to
>> have a separate variable.
> all what I am trying to do is follow the example in the man GD::Graph
> exactly as it is presented, it does not mention any var declaration of
> my_Graph so I copy and paste whatever in there, with my not very strong
> understanding on how modules work in general and GD in particular I was
> hoping to start learning by examples from the man pages, but that did
> not work in this case, in help with explanation is appriciated.
There is indeed an inconsistency in the documentation, although this
is the first time anyone seems to have notice, or run into problems
because of it. It's fixed for the next release, whenever that is.
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy from a
Trading Post Australia | rich salesperson.
|
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5890
***************************************