[13076] in Perl-Users-Digest
Perl-Users Digest, Issue: 486 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 12 15:07:46 1999
Date: Thu, 12 Aug 1999 12:05:14 -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 Thu, 12 Aug 1999 Volume: 9 Number: 486
Today's topics:
Re: Browser detection - write different html (Bruce M Krawetz)
CGI Lite (Jose)
Re: CGI Lite <rootbeer@redcat.com>
Re: Known Issues with perl <grg@umn.edu>
List Files in a directory and search nerilius@my-deja.com
Re: Looking for a good Perl Book <flavell@mail.cern.ch>
Member of an array (Phil Goetz)
Re: Member of an array <tchrist@mox.perl.com>
Re: Member of an array <makkulka@cisco.REMOVETHIS.com>
Re: Member of an array <rootbeer@redcat.com>
Re: Member of an array <sariq@texas.net>
Re: OFF: Opinions on Magazines (NRN Consulting)
Re: OFF: Opinions on Magazines (John Porter)
Re: OFF: Opinions on Magazines <rootbeer@redcat.com>
Re: perl on linux (James R. Goodfriend)
Re: Regexp question <rootbeer@redcat.com>
Re: Regexp question <sariq@texas.net>
Re: Sesssion ID <uri@sysarch.com>
Re: Sesssion ID (Greg Bacon)
Re: Sesssion ID (Benjamin Franz)
Re: Starnge DBI behavior <raison@mc.net>
streaming jpeg with perl <wim@comned.com>
Re: test <mzive@interactive.net>
warnings and init (was: reese) <uri@sysarch.com>
Re: while loop teminates too early (Greg Bacon)
Re: Why use Perl when we've got Python?! (Matt)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Aug 1999 18:53:02 GMT
From: bmk@wdl.lmco.com (Bruce M Krawetz)
Subject: Re: Browser detection - write different html
Message-Id: <7ov56e$j3b2@svlss.lmms.lmco.com>
It's been a long time since I've done CGI scripting, and I know
nothing about shockwave. But I still have a question?
Whatever happened to $HTTP_ACCEPT? Wouldn't a shockwave-capable
browser list shockwave in its environment, along with all the
other types the browser understands? Or has the world forgotten
about HTTP_ACCEPT?
Most likely, I'm out of date. Sigh.
In article <37b02e4e@carrera.intergate.ca>,
"Robert" <ducott@intergate.bc.ca> writes:
|> What we are looking for is a perl/cgi script or a java script that will
|> accomplish the following...When a user comes to our page, the script will
|> detect the browser app ver # and take an action base on that result. What we
|> want is when a browser is 4.0 or better, we want the page to load a
|> shockwave slideshow, if the browser is lower and can't handle shockwave we
|> want the page to load a java applet slide show. Now, were not sure if this
|> can be done so we'll end by saying this. Our company is will to pay top
|> dollar for a working script that will do this. Please reply or send to
|> enquiries to ducott@intergate.bc.ca
|>
|>
--
------------------------------------------- bruce.m.krawetz@lmco.com
We must learn from our mistakes, so we can make bigger and better ones.
------------------------------
Date: Thu, 12 Aug 1999 18:26:47 GMT
From: jose@nospam_nitefever.com (Jose)
Subject: CGI Lite
Message-Id: <37b30dfc.24119956@news.idt.net>
I'm looking to use CGI Lite, I was wondering if there is a website
that explains how to really use CGI_Lite.pm, or if many of you out
there use CGI.pm, is there a page to use CGI.pm?
Thanks...
------------------------------
Date: Thu, 12 Aug 1999 11:57:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: CGI Lite
Message-Id: <Pine.GSO.4.10.9908121156070.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999, Jose wrote:
> I'm looking to use CGI Lite, I was wondering if there is a website
> that explains how to really use CGI_Lite.pm, or if many of you out
> there use CGI.pm, is there a page to use CGI.pm?
It sounds as if you want the documentation which comes with the modules.
When the modules are properly installed, the command 'man' or 'perldoc'
(or your local equivalent) should show you the documentation. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 12 Aug 1999 02:48:55 -0500
From: "George R. Gonzalez" <grg@umn.edu>
Subject: Re: Known Issues with perl
Message-Id: <7ov53g$k6g$1@news1.tc.umn.edu>
I would try running the babtch file by hand and see exactly what error you
get.
You may have a file locking error, or the system could be out of file
handles,
or any number of "run out of" possibilities, or some sort of deadlock
situation.
Try running the smallest test you can by hand and try to narrow down the
problem.
------------------------------
Date: Thu, 12 Aug 1999 18:44:59 GMT
From: nerilius@my-deja.com
Subject: List Files in a directory and search
Message-Id: <7ov4n9$he1$1@nnrp1.deja.com>
I'm trying to write a program that searches a directory for a file. If
that file exists it returns true.
This doesn't work:
#!/usr/bin/perl
require "cgi-lib.pl";
print "Content-type: text/html\n\n";
print "<html><head><title>Online Restaurant</title></head><body
bgcolor=ffffff>\n";
print " <form method=POST
action=\"http://www.worldphase.com/cgi-bin/attack.cgi\"
name=\"bigform\">";
print "<input type=\"text\" name=\"file\">";
print " <input type=\"submit\" name=\"Submit\" value=\"Proceed to Step
2\"> ";
&ReadParse;
$viles = $in{'file'};
opendir(DIR, "/u60/gabeus/");
foreach $fir (readdir(DIR)) {
push @array, $fir;
}
close(DIR);
$i=0;
foreach $f (@array) {
if ($viles =~ /$f/) {
$i=1;
}
}
if ($i==1) {
print "That name is already taken";
}
else {
print "That name is available, good";
}
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 12 Aug 1999 19:40:09 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Looking for a good Perl Book
Message-Id: <Pine.HPP.3.95a.990812184548.21009J-100000@hpplus03.cern.ch>
On Thu, 12 Aug 1999, Kenneth Bandes wrote:
(in over-long lines, now reflowed to usenet customs)
> I don't understand the sport of flaming newbies, personally.
Maybe you're confusing pointless flaming and robust practical advice.
> If a message says "newbie" in the subject, filter it out, ignore it,
> or answer it, but why torture the poor sucker who posted it, even if
> in the long run s/he could have found the answer by plowing through
> the docs?
It seems you wish to condemn newbies to be permanent newbies, or at
least to severely hamper their development.
------------------------------
Date: 12 Aug 1999 18:18:45 GMT
From: goetz@cse.buffalo.edu (Phil Goetz)
Subject: Member of an array
Message-Id: <7ov365$kko$1@prometheus.acsu.buffalo.edu>
I've gone through my Perl manual without finding a built-in
method to ask whether a variable is a member of an array.
E.g., I want to know if "fred" is in the array
@foo = split(/:/, "hi:there:fred:flintstone");
Is there such a method?
------------------------------
Date: 12 Aug 1999 12:39:33 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Member of an array
Message-Id: <37b314e5@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
goetz@cse.buffalo.edu (Phil Goetz) writes:
:I've gone through my Perl manual without finding a built-in
:method to ask whether a variable is a member of an array.
You didn't try the FAQ, did you? Here's an outline of the
perlfaq4 manpage:
§ NAME
perlfaq4 - Data Manipulation ($Revision: 1.40 $, $Date:
1999/01/08 04:26:39 $)
§ DESCRIPTION
The section of the FAQ answers question related to the
manipulation of data as numbers, dates, strings, arrays,
hashes, and miscellaneous data issues.
§ Data: Numbers
· Why am I getting long decimals (eg, 19.9499999999999) instead
of the numbers I should be getting (eg, 19.95)?
· Why isn't my octal data interpreted correctly?
· Does Perl have a round() function? What about ceil()
and floor()? Trig functions?
· How do I convert bits into ints?
· Why doesn't & work the way I want it to?
· How do I multiply matrices?
· How do I perform an operation on a series of integers?
· How can I output Roman numerals?
· Why aren't my random numbers random?
§ Data: Dates
· How do I find the week-of-the-year/day-of-the-year?
· How do I find the current century or millennium?
· How can I compare two dates and find the difference?
· How can I take a string and turn it into epoch seconds?
· How can I find the Julian Day?
· How do I find yesterday's date?
· Does Perl have a year 2000 problem? Is Perl Y2K compliant?
§ Data: Strings
· How do I validate input?
· How do I unescape a string?
· How do I remove consecutive pairs of characters?
· How do I expand function calls in a string?
· How do I find matching/nesting anything?
· How do I reverse a string?
· How do I expand tabs in a string?
· How do I reformat a paragraph?
· How can I access/change the first N letters of a string?
· How do I change the Nth occurrence of something?
· How can I count the number of occurrences of a substring within
a string?
· How do I capitalize all the words on one line?
· How can I split a [character] delimited string except when inside
· How do I strip blank space from the beginning/end of a string?
· How do I pad a string with blanks or pad a number with zeroes?
· How do I extract selected columns from a string?
· How do I find the soundex value of a string?
· How can I expand variables in text strings?
· What's wrong with always quoting "$vars"?
· Why don't my <<HERE documents work?
§ Data: Arrays
· What is the difference between a list and an array?
· What is the difference between $array[1] and @array[1]?
· How can I remove duplicate elements from a list or array?
>>>>>> · How can I tell whether a list or array contains a certain element?
· How do I compute the difference of two arrays? How do
I compute the intersection of two arrays?
· How do I test whether two arrays or hashes are equal?
· How do I find the first array element for which a condition is true?
· How do I handle linked lists?
· How do I handle circular lists?
· How do I shuffle an array randomly?
· How do I process/modify each element of an array?
· How do I select a random element from an array?
· How do I permute N elements of a list?
· How do I sort an array by (anything)?
· How do I manipulate arrays of bits?
· Why does defined() return true on empty arrays and hashes?
§ Data: Hashes (Associative Arrays)
· How do I process an entire hash?
· What happens if I add or remove keys from a hash while
iterating over it?
· How do I look up a hash element by value?
· How can I know how many entries are in a hash?
· How do I sort a hash (optionally by value instead of key)?
· How can I always keep my hash sorted?
· What's the difference between "delete" and "undef" with hashes?
· Why don't my tied hashes make the defined/exists distinction?
· How do I reset an each() operation part-way through?
· How can I get the unique keys from two hashes?
· How can I store a multidimensional array in a DBM file?
· How can I make my hash remember the order I put elements
into it?
· Why does passing a subroutine an undefined element in
a hash create it?
· How can I make the Perl equivalent of a C structure/C++
class/hash or array of hashes or arrays?
· How can I use a reference as a hash key?
§ Data: Misc
· How do I handle binary data correctly?
· How do I determine whether a scalar is
a number/whole/integer/float?
· How do I keep persistent data across program calls?
· How do I print out or copy a recursive data structure?
· How do I define methods for every class/object?
· How do I verify a credit card checksum?
· How do I pack arrays of doubles or floats for XS code?
--tom
--
"... an initial underscore already conveys strong feelings of
magicalness to a C programmer."
--Larry Wall in <1992Nov9.195250.23584@netlabs.com>
------------------------------
Date: Thu, 12 Aug 1999 11:36:04 -0700
From: Makarand Kulkarni <makkulka@cisco.REMOVETHIS.com>
Subject: Re: Member of an array
Message-Id: <37B31414.479AF631@cisco.REMOVETHIS.com>
[
Phil Goetz wrote:
> I've gone through my Perl manual without finding a built-in
> method to ask whether a variable is a member of an array.
> Is there such a method?
]
You have read the Perl Manual but have you read the Perl FAQ ?
If you are going to make large number of calls to a method
to find if a scalar was contained in an array the fastest way
is to maintain a hash whose keys are the scalars in the array.
When you add new elements to the array add the corresponding
key to the hash.
There is no built-in.
--
------------------------------
Date: Thu, 12 Aug 1999 11:58:55 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Member of an array
Message-Id: <Pine.GSO.4.10.9908121158290.7774-100000@user2.teleport.com>
On 12 Aug 1999, Phil Goetz wrote:
> I've gone through my Perl manual without finding a built-in
> method to ask whether a variable is a member of an array.
FAQ, section four, "How can I tell whether an array contains a certain
element?" Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 12 Aug 1999 13:52:45 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Member of an array
Message-Id: <37B317FD.A2CB54E@texas.net>
Phil Goetz wrote:
>
> I've gone through my Perl manual without finding a built-in
> method to ask whether a variable is a member of an array.
> E.g., I want to know if "fred" is in the array
>
> @foo = split(/:/, "hi:there:fred:flintstone");
>
> Is there such a method?
perlfaq4
- Tom
------------------------------
Date: 12 Aug 1999 18:06:40 GMT
From: nrn@enteract.com (NRN Consulting)
Subject: Re: OFF: Opinions on Magazines
Message-Id: <7ov2fg$s6o$1@eve.enteract.com>
In article <7ov1f8$9e9@news.service.uci.edu>, Gabe <grichard@uci.edu> wrote:
>I post this here only because there are a lot of knowledgeable computer
Good luck.
>
>I'm looking for a computer magazine for non computer morons. I'm tired of ZD
>and their 'zines. Every issue it's the same damn things: shitty reviews of
>hardware/software I'll never buy, the "latest" Windows tips, the "latest"
>Linux hype, the 50 best this, the 10 greatest that, the "latest" internet
Perl Journal?
--
NRN Consulting 500 W Cermak Rd #42 Chicago IL 60616-1860 http://www.nrnc.com/
------------------------------
Date: Thu, 12 Aug 1999 18:28:53 GMT
From: jdporter@min.net (John Porter)
Subject: Re: OFF: Opinions on Magazines
Message-Id: <slrn7r64j5.ggv.jdporter@min.net>
In article <7ov1f8$9e9@news.service.uci.edu>, Gabe wrote:
>I post this here only because there are a lot of knowledgeable computer
>users here. Don't flame me.
Bad reason. You deserve the flamage.
>I want a mag geared towards the knowledgeable hobbyist/professional which
>deals more with issues in computing (programming, networking, web stuff, ai,
>database design, etc) than with ratings and reviews for the ignorant.
The Perl Journal. (What else would you expect from this newsgroup?)
--
John Porter
------------------------------
Date: Thu, 12 Aug 1999 11:47:45 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: OFF: Opinions on Magazines
Message-Id: <Pine.GSO.4.10.9908121142160.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999, Gabe wrote:
> I post this here only because there are a lot of knowledgeable computer
> users here. Don't flame me.
Okay, I won't flame you. But someone else probably will. I mean, you can
pretty much count on getting a message saying something like "What kind of
a reason is that? You could use that kind of flawed logic to justify
asking about restaurants, since there are a lot of people here who like
food. Just because people here know about something, you shouldn't think
your question is automatically on-topic."
But I won't say that. I'll just encourage you to find a more-appropriate
forum the next time.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Aug 1999 18:07:12 GMT
From: GoodfriB@jntf.osd.mil (James R. Goodfriend)
Subject: Re: perl on linux
Message-Id: <7ov2gg$kr8$1@news1.rmi.net>
In article <7our74$g95$1@news1.rmi.net>, I unthinkingly wrote...
>
>In article <Lqms3.610$wU.5297@news1.online.no>, mike@crusaders.no says...
>>
>>Ala Qumsieh <aqumsieh@matrox.com> wrote in message
>>news:x3ywvv29qy5.fsf@tigre.matrox.com...
>>> > perl -e 'while(<>){s/\cM//g;print}' < oldscript.pl > fixedscript.pl
>>> Haven't heard of the -p and -n flags?
>>
>>Actually... No.
>>
>>> or even the -i flag?
>>
>>I know what it's for, but I haven't used it.
>>
>>> % perl -pi -e 's/\cM//g' oldscript.pl > fixedscript.pl
>>
>
> perl's actually got a special character (\r) for the carriage reurn,
>so you could just do this:
>
>% perl -pie 's/\r//g' script.pl
>
> Note I'm not redirecting, since -i is going to change the script in
>place anyway.
...but not the way I've written it, it won't. Tom Christiansen pointed out to
me in mail that this didn't work, and shame on me for not testing it. The "e"
in -pie is being interpreted as an argument to -i here. This is what I wanted:
%perl -pi -e 's/\r//g' script.pl
Shame on me for testing one thing, but writing about another similar thing.
-Bob
------------------------------
Date: Thu, 12 Aug 1999 11:20:45 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Regexp question
Message-Id: <Pine.GSO.4.10.9908121119310.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999, A Zielke wrote:
> $_ = '19990812';
> my ($year,$month,$day) = /(\d{4})(\d{2})(d{2})/;
> # they're all undef but why????
Because there weren't two 'd's in that string. Maybe you meant to use
another backslash in your pattern. Alas, Perl can't always do what you
mean, so it does what you tell it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 12 Aug 1999 13:13:34 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Regexp question
Message-Id: <37B30ECE.4AF9E00E@texas.net>
A Zielke wrote:
>
> Hi,
>
> I'm really getting a bit desperate. Have a look at this
>
> #!perl -w
> use strict;
> $_ = '19990812';
> my ($year,$month,$day) = /(\d{4})(\d{2})(d{2})/;
You're missing something from '(d{2})'.
- Tom
------------------------------
Date: 12 Aug 1999 14:06:28 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sesssion ID
Message-Id: <x74si47u1n.fsf@home.sysarch.com>
>>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:
TC> : $sec = sprintf("%02d",$sec);
TC> : $min = sprintf("%02d",$min);
TC> : $hour = sprintf("%02d",$hour);
TC> : $mday = sprintf("%02d",$mday);
TC> for $value ($sec, $min, $hour, $mday) {
TC> $value = sprintf "%02d", $value;
TC> }
sorry, tom, that is too obscure for even the most jaded perl hacker
(except you!). though it is cute code.
:-)
how about:
($sec, $min, $hour, $mday) = map sprintf("%02d", $_), $sec, $min, $hour, $mday;
slightly redundant but much clearer IMO. as you know, redundancy in a
language (like english) is a necessary thing.
or this:
s/^(\d)$/0$1/ for $sec, $min, $hour, $mday ;
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 12 Aug 1999 19:01:54 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Sesssion ID
Message-Id: <7ov5n2$afb$2@info2.uah.edu>
In article <x74si47u1n.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> writes:
: >>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:
:
: TC> for $value ($sec, $min, $hour, $mday) {
: TC> $value = sprintf "%02d", $value;
: TC> }
:
: sorry, tom, that is too obscure for even the most jaded perl hacker
: (except you!). though it is cute code.
Please point out the part or parts that are "too obscure".
Greg
--
Sam: What'd you like, Normie?
Norm: A reason to live. Gimmie another beer.
------------------------------
Date: Thu, 12 Aug 1999 19:03:37 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: Sesssion ID
Message-Id: <dUEs3.93$DI3.9077@typhoon01.swbell.net>
Aggie, Tom and Uri write:
"We can do it better. Or at least weirder."
I reply:
Benchmark: timing 100000 iterations of benjamin2, fl_aggie, original, tomc, uri1, uri2...
benjamin2: 10 wallclock secs ( 8.20 usr + 0.00 sys = 8.20 CPU)
fl_aggie: 11 wallclock secs (10.45 usr + 0.03 sys = 10.48 CPU)
original: 11 wallclock secs ( 9.64 usr + 0.00 sys = 9.64 CPU)
tomc: 13 wallclock secs (12.25 usr + 0.00 sys = 12.25 CPU)
uri1: 14 wallclock secs (13.48 usr + 0.00 sys = 13.48 CPU)
uri2: 14 wallclock secs (12.36 usr + 0.01 sys = 12.37 CPU)
As you can see, none of (Tom, Aggie and Uri's) proposals are faster than the
_original_ code. I (of course ;) ) was able to improve on it slightly.
--
Benjamin Franz
#!/usr/bin/perl -w
use strict;
use Benchmark;
my $tick = time;
timethese(100000,{
'original' => sub { date_cookie('Biida',$tick) },
'fl_aggie' => sub { fl_aggie('Biida',$tick) },
'tomc' => sub { tomc('Biida',$tick) },
'uri1' => sub { uri1('Biida',$tick) },
'uri2' => sub { uri2('Biida',$tick) },
'benjamin2' => sub { benjamin2('Biida',$tick) },
});
sub date_cookie {
my ($self) = shift;
my ($tick) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
$month,$wkday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($tick);
$wkday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
$month = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
$sec = "0$sec" if (length($sec) < 2);
$min = "0$min" if (length($min) < 2);
$hour = "0$hour" if (length($hour) < 2);
$mday = "0$mday" if (length($mday) < 2);
$year += 1900;
return "$wkday, $mday-$month-$year ${hour}\:${min}\:${sec} GMT";
}
sub fl_aggie {
my ($self) = shift;
my ($tick) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
$month,$wkday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($tick);
$wkday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
$month = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
$sec = sprintf("%02d",$sec);
$min = sprintf("%02d",$min);
$hour = sprintf("%02d",$hour);
$mday = sprintf("%02d",$mday);
$year += 1900;
return "$wkday, $mday-$month-$year ${hour}\:${min}\:${sec} GMT";
}
sub tomc {
my ($self) = shift;
my ($tick) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
$month,$wkday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($tick);
$wkday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
$month = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
for my $value ($sec, $min, $hour, $mday) {
$value = sprintf "%02d", $value;
}
$year += 1900;
return "$wkday, $mday-$month-$year ${hour}\:${min}\:${sec} GMT";
}
sub uri1 {
my ($self) = shift;
my ($tick) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
$month,$wkday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($tick);
$wkday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
$month = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
($sec, $min, $hour, $mday) = map sprintf("%02d", $_), $sec, $min, $hour, $mday;
$year += 1900;
return "$wkday, $mday-$month-$year ${hour}\:${min}\:${sec} GMT";
}
sub uri2 {
my ($self) = shift;
my ($tick) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
$month,$wkday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($tick);
$wkday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
$month = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
s/^(\d)$/0$1/ for $sec, $min, $hour, $mday ;
$year += 1900;
return "$wkday, $mday-$month-$year ${hour}\:${min}\:${sec} GMT";
}
sub benjamin2 {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(pop);
$wday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
$mon = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
sprintf('%s, %02d-%s-%s %02d:%02d:%02d GMT',$wday,$mday,$mon,$year+1900,$hour,$min,$sec);
}
------------------------------
Date: Thu, 12 Aug 1999 13:58:34 -0500
From: Kevin Raison <raison@mc.net>
To: Steve Linberg <linberg@literacy.upenn.edu>
Subject: Re: Starnge DBI behavior
Message-Id: <37B3195A.6A63B8AE@mc.net>
Steve Linberg wrote:
> In article <37B301EA.E7F1282F@mc.net>, kevin@mc.net wrote:
>
> > Have I discovered a bug?
>
> I don't think so.
>
> > my @array;
> > my $sth = $dbh->prepare("select * from table");
> > $sth->execute;
>
> Not checking for errors on these calls?
>
The statements produce no errors. This code submission is merely paired
down.
So, assume, $dbh->prepare("blah") || die($dbh->errstr);
etc.
>
> > foreach(@array) {
> > print "$_->{column1} : $_->{column2}\n";
> > }
>
> Why are you treating $_ as a hashref, when you asked for an arrayref?
> Maybe you mean $_->[0], $_->[1]?
My typo. try again:
$_->[0] : $_->[1]
>
>
> > $sth = {};
>
> Why are you setting $sth to a reference to an empty hash? Are you trying
> to dispose of it, as in $sth->finish?
This action does the same thing as finish except, in cases where a statement
has aready returned everything it can, this is more efficient.
It simply undefines the handle. Remember, in PERL, setting something to an
empty array or hash is the same as setting it to undef.
Sorry for being unclear in my first message.
--
Kevin Raison (raison@mc.net)
Senior Systems Administrator
MCnet
http://www.mc.net
------------------------------
Date: Thu, 12 Aug 1999 20:37:16 +0200
From: wim bakker <wim@comned.com>
Subject: streaming jpeg with perl
Message-Id: <37B3145C.8354C671@comned.com>
This is a multi-part message in MIME format.
--------------0AA8CF7E8C62823C6BF49EE4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
--------------0AA8CF7E8C62823C6BF49EE4
Content-Type: text/plain; charset=us-ascii;
name="question.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="question.txt"
I have two machines. On one runs bttvgrab which produces a constant jpeg video stream
into a file called image, with the modified perl script that comes with bttvgrab I try to
transport this file via the net to the other machine.
The script on the grabber-machine looks as follows:
#!/usr/bin/perl -w
# directory of temporary files
$BTTVDIR = "/tmp/bttvgrab";
# file to show when not grabbing
$OFFIMG = "tv_off.jpg";
$OFFTYPE = "jpeg";
$WIDTH = 305;
$HEIGHT = 228;
use IO::Socket;
$sock = new IO::Socket::INET (PeerAddr => '<hostname_of_other_machine>',
PeerPort => 8000,
Proto => 'tcp',
);
die "socket could not be created. Reason: $!\n" unless $sock;
sub cat {
local $CATFILE;
open(CATFILE,shift);
print $sock <CATFILE>;
close(CATFILE);
}
# test if grabbing...
if (not (-d "$BTTVDIR" and -p "$BTTVDIR/status" and -f "$BTTVDIR/format")) {
cat($OFFIMG);
exit 0;
}
$| = 1;
# yes, web-tv is active
open(FORMFILE,"$BTTVDIR/format");
$TYPE=<FORMFILE>;
close(FORMFILE);
if ("$TYPE" eq "jpg") {
$TYPE="jpeg";
} else {
if ("$TYPE" eq "gif") {
$TYPE="gif";
} else {
$TYPE="x-$TYPE";
}
}
open(STATUS,"<$BTTVDIR/status");
open(STATUS_LOCK,"<$BTTVDIR/status-lock");
$MASK = '';
vec($MASK,fileno(STATUS),1) = 1;
$MASK_LOCK = '';
vec($MASK_LOCK,fileno(STATUS_LOCK),1) = 1;
$NO = '';
vec($NO,fileno(STATUS),1) = 0;
$N = 0;
while (-f "$BTTVDIR/format") {
$read = $MASK_LOCK;
$write = $NO;
$error = $NO;
$n = select($read,$write,$error,undef);
$read = $MASK;
$write = $NO;
$error = $NO;
$n = select($read,$write,$error,undef);
cat("$BTTVDIR/image");
}
close ($sock);
close(STATUS);
close(STATUS_LOCK);
It generates a constant image stream to the other machine.
On the other machine runs the following script:
#!/usr/bin/perl -w
use File::Copy "mv";
use IO::Socket;
$sock = new IO::Socket::INET (LocalHost => '<hostname>',
LocalPort => 8000,
Proto => 'tcp',
Listen => 5,
Reuse => 1,
);
die "could not connect: $!" unless $sock;
while ($new_sock = $sock->accept()) {
while (defined ($buf = <$new_sock>)) {
$bytes_to_read = #well how much bytes is the forthcoming jpeg
$img = "";
while ($bytes_to_read) {
$bytes_read = sysread($new_sock, $buf, $bytes_to_read);
if (defined($bytes_read)) {
if ($bytes_read == 0) {
close($new_sock);
last;
} else {
$img .= $buf;
$bytes_to_read -= $bytes_read;
}
} else {
if ($! == EAGAIN()) {
} else {
last;
}
}
}
open(NEW, ">/ext/stream-new");
(print NEW $img);
close(NEW);
mv ("/ext/stream-new", "/ext/stream.jpg");
}
}
close ($sock);
There is this problem that I need to distinguish when the next image comes in.
I figured that first sending the filesize of the coming image and then reading in
such much bytes might work but I don't know how to implement that,
is this a good approach or are there better ways (e.g. letting the sending machine
trigger the receiving machine for or after each image that is being send)
Any suggestion is appreciated
wim bakker
--------------0AA8CF7E8C62823C6BF49EE4--
------------------------------
Date: Thu, 12 Aug 1999 14:37:07 -0400
From: "Michael Zive" <mzive@interactive.net>
Subject: Re: test
Message-Id: <grEs3.1$mo5.73@reader1.interactive.net>
what is this
Michael Zive <mzive@interactive.net> wrote in message
news:qOzs3.2$hk5.41@reader1.interactive.net...
> test test
>
>
------------------------------
Date: 12 Aug 1999 14:34:01 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: warnings and init (was: reese)
Message-Id: <x71zd87srq.fsf_-_@home.sysarch.com>
>>>>> "A" == Abigail <abigail@delanet.com> writes:
abigail, you ignorant slut!!
<tomc> let's clear this up once and for all </tomc>
:-)
A> Uri Guttman (uri@sysarch.com) wrote on MMCLXXII September MCMXCIII in
A> <URL:news:x74si591tw.fsf@home.sysarch.com>:
A> {} what about $foo = [] ; push @$foo, blah?
A> No problem at all. $foo is given a value, and hence, not uninitialized.
A> And hence, @$foo isn't either.
someone else mentioned what i consider the key to this thread. defined
on aggregates is meaningless. as you know it will be a warning (or fatal
i hope?) in 5.6. currently is checks to see if any storage was ever
allocated for the aggregate which is of dubious value.
so if you declare an aggregate, what difference does it make if you
don't assign () to it before its use in any expressions? it is empty by
any meaning of that word. there is no out of band value like undef is
for scalars. so you can't use it in any code where you get an unexpected
result since you didn't initialize it.
look at this common case:
my( $foo, @bar ) = @_ ;
if called with a single arg, @bar is declared but not assigned
anything. does that make it uninitialized? not really. it is initialized
by default with () which is what you want. you then test it with a
boolean which says if it has any elements. you don't do an explicit init
like:
@bar = () unless @bar ;
A> Huh? "$foo = [];" has an assignment operator, "my @foo;" doesn't.
A> Big difference. In fact, that difference is the entire point!
this difference is when you deref $foo. is that anon array initialized?
do you then have to say @$foo = () before you push onto it?
A> {} whereas, using a scalar value of undef can work as perl will auto coerce
A> {} it to '' or 0 as needed. that is an implied corecion that can be wrong
A> {} if you don't know what youare doing. hence the warnings if you use it as
A> {} avalue in a calculation (broad meaning of that term).
A> Well, of course one could argue all variables get a default
A> value. But even then why is there just one default value for
A> arrays, yet there can be 2 default values for scalars? Why not say
A> "all scalars will be initialized as ''"?
because scalars have multiple possible value forms and also an out of
band value of undef. undef will coerce to '' or 0 on demand. that
coercion is the issue, not initialization. the warning will happen
regardless how the undef got into the scalar value if it is used in a
context which forces coercion.
A> But even then, I still want -w to warn me for uninitialized
A> values. I don't care if a default values has been set. What is
A> important is that the moment the variable is used *I* haven't
A> assigned a value yet - and that's a potential problem. Giving
A> variables default values, and allowing them to be used without a
A> warning under -w makes -w *less* useful. Because then it will not
A> determine that no value has been set by the programmer.
i again will say, -w is checking for coercion of undef and not
uninittialized scalars.
$foo = 'x' ;
$bar = join( $foo, qw( a b c ) ) ;
$foo = undef ;
$bar = join( $foo, qw( a b c ) ) ;
was $foo initialized in either case? i say yes but it was undef in the
second and under -w that will warn about uninitialized value.
perl -we 'print join $a, qw( a b c)'
Name "main::a" used only once: possible typo at -e line 1.
Use of uninitialized value at -e line 1.
perhaps that should say "Coercion of undef to ''"?
and the paired warning should say:
"Coercion of undef to 0"?
i will post to p5p about changing this.
makes more sense to me than the current warning. in fact it is better as
it covers assigned undef values being coerced.
A> "" is a nice idempotent value for concatination. Do you realize that
A> forcing people to initialize variables can actually *increase* the
A> number of mistakes?
they are poor programmers if they do things like the second one below.
A> my $foo;
A> ...
A> foreach my $fruit (qw /apple pear banana/) {
A> $foo .= "$fruit "; # Gives a warning, but is ok.
A> }
should be my warning text above.
A> my $foo = 0;
A> ...
A> foreach my $fruit (qw /apple pear banana/) {
A> $foo .= "$fruit "; # Doesn't give a warning, but it probably wrong.
A> }
you get what you ask for. you have a number being coerced into a
string. perl does that all the time when you want it. why break that
here? see tom's python post today on this issue.
A> That is true, but it irks me that Perl isn't consistent in its warnings.
it is consistant. aggregates are empty when created so there is no
coercion when first used in any context. scalars are undef which needs
coercion when used in string or numeric contexts. that can be a bug so
it is a warning. undef values don't get coerced in boolean contexts
which is used a lot and is fine as undef makes for a useful out of band
error or not assigned value.
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 12 Aug 1999 18:52:47 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: while loop teminates too early
Message-Id: <7ov55v$afb$1@info2.uah.edu>
In article <37b307db@cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> writes:
: In comp.lang.perl.misc,
: bart.lateur@skynet.be (Bart Lateur) writes:
:
: :All the problems were caused because Perl considers the string "0" to be
: :False. Nobody in his right mind would have thought any string but the
: :empty string could be considered False, but Perl had a mind of it's own.
:
: It has to work this way. Think about it.
I was told that there would be no math in this debate. :-)
Greg
--
If you can't beat your computer at chess, try kickboxing.
------------------------------
Date: Thu, 12 Aug 1999 18:15:01 GMT
From: mck@iag.net (Matt)
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <37b40eec.11806226@news.iag.net>
On Thu, 12 Aug 1999 17:52:25 GMT,
mcafee@waits.facilities.med.umich.edu (Sean McAfee) wrote:
>To help me learn Python, I decided to rewrite some of my Perl scripts
>in Python. The first script I chose for conversion was called "getfile";
>it grabs a file via FTP and prints it on stdout.
Did you finish the conversion? If so, it would be interesting to see
the code to compare, for us who know no Python.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 486
*************************************