[13578] in Perl-Users-Digest
Perl-Users Digest, Issue: 988 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 5 09:05:39 1999
Date: Tue, 5 Oct 1999 06:05:19 -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: <939128719-v9-i988@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 5 Oct 1999 Volume: 9 Number: 988
Today's topics:
Re: A different turn ( WAS Re: Bye Tom? ) (Anno Siegel)
Re: A different turn ( WAS Re: Bye Tom? ) (Abigail)
Re: A different turn ( WAS Re: Bye Tom? ) <dan@tuatha.sidhe.org>
Re: array getting in the way of compilation (Larry Rosler)
Re: Bug with localtime() in Perl 5.004 and 5.005 <sariq@texas.net>
Re: Bug with localtime() in Perl 5.004 and 5.005 (M.J.T. Guy)
Cookie Troubles...... <mattking@techie.com>
Counter <loeser@uni-paderborn.de>
Create file ok, write fails fredrick.backman@pmail.net
Re: Create file ok, write fails <gellyfish@gellyfish.com>
eval Problem <gernot@cat.at>
how to change a '\' to '/' ? <rudolpht@lsv-wuerttemberg.de>
Re: how to change a '\' to '/' ? (Sam Holden)
Re: how to change a '\' to '/' ? (Abigail)
Re: how to change a '\' to '/' ? <NukeEmUp@ThePentagon.com>
Re: How to start up Netscape or Internet Explorer from (Nim Chu)
Re: Knowing sizeof (int) inside a Perl program <greenej@my-deja.com>
Re: libraries "die"ing <NukeEmUp@ThePentagon.com>
Re: libraries "die"ing (Sam Holden)
Need help with input verifier (Jana Cole or John Sayre)
Re: Newbie: Combining split and shift on One Statement (Sam Holden)
Re: Newbie: Combining split and shift on One Statement <sariq@texas.net>
odd or even numbers? <fokko.wesselius@ict.nl>
Re: odd or even numbers? <debot@xs4all.nl>
Re: odd or even numbers? <gellyfish@gellyfish.com>
Re: odd or even numbers? (Abigail)
Re: odd or even numbers? <rick.delaney@home.com>
OS/2 and <$ARGV[0]/foo/*.bar>: will it work? <hoffmann@ehmgs2.et.tu-dresden.de>
PERL CGI script works in concole but not with IIS or Ap <gregor.bruhin@bluewin.ch>
Re: Simple - yet won't work! (Randal L. Schwartz)
Re: sort routine - can it ignore numeric values? (M.J.T. Guy)
Sorted -- Thanks (Re: Create file ok, write fails) flevli@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Oct 1999 10:31:21 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A different turn ( WAS Re: Bye Tom? )
Message-Id: <7tck1p$316$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@delanet.com> wrote in comp.lang.perl.misc:
>I've gotten a love letter from a complete stranger on my pager. Unsigned.
So how do you know it was from a stranger?
Anno
------------------------------
Date: 5 Oct 1999 06:08:46 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: A different turn ( WAS Re: Bye Tom? )
Message-Id: <slrn7vjnho.e85.abigail@alexandra.delanet.com>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCCXXVI
September MCMXCIII in <URL:news:7tck1p$316$1@lublin.zrz.tu-berlin.de>:
:: Abigail <abigail@delanet.com> wrote in comp.lang.perl.misc:
::
:: >I've gotten a love letter from a complete stranger on my pager. Unsigned.
::
:: So how do you know it was from a stranger?
Because it was certainly not any of the 4 people who knew my pager number.
Abigail
--
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")
-> define ("foldoc", "perl")) [0] -> print'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 05 Oct 1999 11:58:33 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: A different turn ( WAS Re: Bye Tom? )
Message-Id: <JJlK3.5956$S32.13140@news.rdc1.ct.home.com>
Abigail <abigail@delanet.com> wrote:
> Dan Sugalski (dan@tuatha.sidhe.org) wrote on MMCCXXV September MCMXCIII
> in <URL:news:3G7K3.5680$S32.11576@news.rdc1.ct.home.com>:
> ..
> .. When exactly does it *not* seem absurd? That's the bit that's got me puzzled.
> Oh, the internet looks pretty ok to me if there are no packages going
> over my ppp-link.
Oh, sure, it looks OK. Even when there are packets going across my link. (Well, as
long as I know why, and the reason isn't windows) Still seems absurd...
Dan
------------------------------
Date: Thu, 30 Sep 1999 23:38:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: array getting in the way of compilation
Message-Id: <MPG.125df6d4c601e40998a01a@nntp.hpl.hp.com>
In article <37F41F53.91CDB94B@gator.net> on Thu, 30 Sep 1999 22:41:24 -
0400, Gary M. Greenberg <garyg@gator.net> says...
> shaun.coon wrote:
> > I'm writing a piece of code that is meant to circulate through a list of
> > data, and place chunks of it into a group of arrays (based on a fairly
> > simple alphabetical criteria). I've done this with a set of elsif
> > statements following the initial if.
> Iterating thru an array creating clustered datasets screams for a hash.
> if (exists $list{$k}) {
> $list{$k} .= ",".$section[$k];
> } else {
> $list{$k} = $section[$k];
> }
A more generally useful way of doing that might be to replace the above
snippet by this:
push @{$list{$k}}, $section[$k];
Then you get, rather than a comma-separated string that has to be split
anyway to be usable, a set of arrays. As requested by the original
poster.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 05 Oct 1999 06:03:16 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Bug with localtime() in Perl 5.004 and 5.005
Message-Id: <37F9DAF4.51528D00@texas.net>
Robert Rothenburg wrote:
>
> Tom Briles wrote:
> > Keep in mind that there are alot of very
> > high-level professionals using Perl, and this type of bug would be
> > virtually impossible.
>
> As for the the notion that a lot of high-level professionals using
> something makes a stupid bug virtually impossible... well, that's
> another topic for discussion/argument (which I'll take a virtual
> raincheck on).
Just for clarification, I said *this type* of bug, not a "stupid bug".
We all know that Perl has had/has bugs.
> Thanks again.
You're welcome. And I'm happy to see that you aren't as thin skinned as
many of the uninitiated in these parts...
- Tom
------------------------------
Date: 5 Oct 1999 12:47:19 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Bug with localtime() in Perl 5.004 and 5.005
Message-Id: <7tcs0n$qjq$1@pegasus.csx.cam.ac.uk>
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Alan Curry
><pacman@defiant.cqc.com>],
>who wrote in article <_h7K3.14074$t%3.1085991@typ11.nn.bcandid.com>:
>> >$seconds_per_day = 86400;
>>
>> Are you sure about that? What about DST and leap seconds?
>
>The last part is a common misconception. There are no leap seconds in
>time(). time() is 86400 * $d + $s. $d is the number of whole days
>after the epoch, and $s is number of seconds during the last day.
>
>A patch to perlfunc is welcome.
What patch is needed? perldoc -f time is quite explicit:
=item time
Returns the number of non-leap seconds since whatever time the system
^^^^^^^^
considers to be the epoch (that's 00:00:00, January 1, 1904 for MacOS,
and 00:00:00 UTC, January 1, 1970 for most other systems).
Suitable for feeding to C<gmtime()> and C<localtime()>.
Mike Guy
------------------------------
Date: Tue, 5 Oct 1999 14:21:35 +0200
From: "Matt King" <mattking@techie.com>
Subject: Cookie Troubles......
Message-Id: <7tco7h$aki$1@news.uk.ibm.com>
This is a multi-part message in MIME format.
------=_NextPart_000_0012_01BF0F3C.EE5893A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I'm trying to use the cgi.pm cookie ability to save a cookie with a =
single piece of information ($ENV{'REMOTE_USER'};) to the remote users =
system so that I can use it on other pages. According to the =
documentation, I the functions only work with NS. How can I save (and =
read) a cookie on a remote pc with IE or NS? Please include a simple =
example. I have Active PERL 519 (Windows 98), and the examples don't wok =
exactly as shown (if they even work at all).
Thanks.
Matt
------=_NextPart_000_0012_01BF0F3C.EE5893A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2014.210" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I'm trying to use the cgi.pm cookie =
ability to save=20
a cookie with a single piece of information ($ENV{'REMOTE_USER'};) to =
the remote=20
users system so that I can use it on other pages. According to the=20
documentation, I the functions only work with NS. How can I save (and =
read) a=20
cookie on a remote pc with IE or NS? Please include a simple example. I =
have=20
Active PERL 519 (Windows 98), and the examples don't wok exactly as =
shown (if=20
they even work at all).</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Matt</FONT></DIV></BODY></HTML>
------=_NextPart_000_0012_01BF0F3C.EE5893A0--
------------------------------
Date: Tue, 05 Oct 1999 14:29:20 +0200
From: Chris Loeser <loeser@uni-paderborn.de>
Subject: Counter
Message-Id: <37F9EF1F.3FD99491@uni-paderborn.de>
Tach Post,
ich moechte ganz gerne einen Counter in einem HTML-Dokument haben.
1.Server Side Includes ist bei dem HTTP-Server ausgeschaltet, daher :
2. In einer vorhandenen Seite soll ein Perl-Script aufgerufen werden und
die Counterzahl soll in das Dokument eingebunden werden....
Hat jemand das schon mal gemacht ??
cheers
Chris
mailto:loeser@upb.de
------------------------------
Date: Tue, 05 Oct 1999 10:45:04 GMT
From: fredrick.backman@pmail.net
Subject: Create file ok, write fails
Message-Id: <7tckre$m6g$1@nnrp1.deja.com>
I have this perl CGI on Solaris 5.5.1 and I'm trying to write a variable
to a file but all that happens is that the file is created (if it
doesn't already exist) but nothing is written to it! Please can someone
advice?
open(file, ">$user_dir/logins");
print(file $nlogins);
close(file)
If I change the filename to /tmp/logins it works all right, which
indicates it might be something with file permissions in the $user_dir
directory but it doesn't make sense that the file can be created but not
written...or? I'm far from a UNIX or Perl beginner but it might be a bit
too early in the morning :-)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 5 Oct 1999 12:12:43 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Create file ok, write fails
Message-Id: <37f9dd2b_2@newsread3.dircon.co.uk>
fredrick.backman@pmail.net wrote:
> I have this perl CGI on Solaris 5.5.1 and I'm trying to write a variable
> to a file but all that happens is that the file is created (if it
> doesn't already exist) but nothing is written to it! Please can someone
> advice?
>
> open(file, ">$user_dir/logins");
You shoudl always check the success of a file open before you use the
filehandle - also you should use an upper case filehandle lest Perl
confuse it for a bareword.
open(FILE,">$user_dir/logins") || die "cant open $user_dir/logins - $!\n";
This should give you some diagnostic message.
--
"Like Anne Robinson in a Korean restaurant, it'll be dog eat dog" -
Graham Norton
------------------------------
Date: Tue, 05 Oct 1999 14:38:59 +0200
From: Gernot Homma <gernot@cat.at>
Subject: eval Problem
Message-Id: <37F9F163.402E7382@cat.at>
This is a multi-part message in MIME format.
--------------1E89547042C2A8F21A8BDD73
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I have a problem with "eval" inside object-methods
I have a method called method2
sub method2 {
my $self = shift;
print $self . "\n";
}
and when I call method2 in two different ways I get different results
from the print command.
this code works fine:
the print command in method2 prints out the correct reference to the
object
sub method1 {
my $self = shift;
$self->method2("atext");
}
but when i use
sub method1 {
my $self = shift;
my $s = '$self->method2("atext")';
eval($s);
}
the code failes, the print command in method2 doesn't print out the
correct reference
many thanks in advance,
Gernot
--------------1E89547042C2A8F21A8BDD73
Content-Type: text/x-vcard; charset=us-ascii;
name="gernot.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Gernot Homma
Content-Disposition: attachment;
filename="gernot.vcf"
begin:vcard
n:Homma;Gernot
x-mozilla-html:FALSE
org:Cyber-Atelier
adr:;;;Vienna ;;1210;Austria
version:2.1
email;internet:gernot@cat.at
tel;fax:+43 1 272 92 51 9
tel;work:+43 1 272 92 51
x-mozilla-cpt:;0
fn:Homma, Gernot
end:vcard
--------------1E89547042C2A8F21A8BDD73--
------------------------------
Date: Tue, 05 Oct 1999 12:51:36 +0200
From: Tobias Rudolph <rudolpht@lsv-wuerttemberg.de>
Subject: how to change a '\' to '/' ?
Message-Id: <nNX5N3c3LOb7=uxQM5IjuklsbzHn@4ax.com>
Hi!
I´ve got a beginner problem.
In a string I want to change a backslash ('\') to a slash ('/').
Example:
$path = "\my_dir\my_file";
I already tried something like
$path =~ s/\\/\//g;
or
$path =~ s/\0134/\057/g; # octal 134 = '\'; octal 57 = '/'
but neither did it.
What must I do to get "/my_dir/my_file" as result?
Thanks in advance
Tobias
------------------------------
Date: 5 Oct 1999 11:01:31 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: how to change a '\' to '/' ?
Message-Id: <slrn7vjmkb.6ge.sholden@pgrad.cs.usyd.edu.au>
On Tue, 05 Oct 1999 12:51:36 +0200,
Tobias Rudolph <rudolpht@lsv-wuerttemberg.de> wrote:
>Hi!
>
>I´ve got a beginner problem.
>In a string I want to change a backslash ('\') to a slash ('/').
>
>Example:
>$path = "\my_dir\my_file";
This does not contain any \ characters.
Why don't you try printing it out, before you do the s/// and you will
see what I mean.
Then you could try reading the documentation that comes with perl to find out
how to do what you want. The documentation in 'perlop' anout the various
quoting mechanisms in perl should be useful. Try running 'perldoc perlop'
and reading it.
>
>I already tried something like
>
>$path =~ s/\\/\//g;
You would be better off using tr for this. Check the perlop documentation
again for this.
>
>or
>
>$path =~ s/\0134/\057/g; # octal 134 = '\'; octal 57 = '/'
>
>but neither did it.
>
>What must I do to get "/my_dir/my_file" as result?
Ummm...
$path=~s/m/\\m/g;
--
Sam
Any computer scientist who praises orthogonality should be sentenced to
use an Etch-a-Sketch.
-- Larry Wall
------------------------------
Date: 5 Oct 1999 06:10:37 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: how to change a '\' to '/' ?
Message-Id: <slrn7vjnl7.e85.abigail@alexandra.delanet.com>
Tobias Rudolph (rudolpht@lsv-wuerttemberg.de) wrote on MMCCXXVI September
MCMXCIII in <URL:news:nNX5N3c3LOb7=uxQM5IjuklsbzHn@4ax.com>:
<>
<> $path = "\my_dir\my_file";
That doesn't contain any backslashes. Print $path and see.
Then read the perlop manpage.
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 05 Oct 1999 12:24:51 +0100
From: David Cantrell <NukeEmUp@ThePentagon.com>
Subject: Re: how to change a '\' to '/' ?
Message-Id: <g9=5N8171HDitYCWkNGg7Ig5l8zj@4ax.com>
On Tue, 05 Oct 1999 12:51:36 +0200, Tobias Rudolph
<rudolpht@lsv-wuerttemberg.de> said:
>I´ve got a beginner problem.
>In a string I want to change a backslash ('\') to a slash ('/').
>
>Example:
>$path = "\my_dir\my_file";
If that's how you're setting $path, then I suggest you try printing
out the value of $path to see what you've set it to. Then consult the
documentation to figure out why.
>I already tried something like
>
>$path =~ s/\\/\//g;
>
>What must I do to get "/my_dir/my_file" as result?
Your substitution is correct. However, to avoid 'leaning toothpick
syndrome' consider using a delimiter other than the slash.
[Copying newsgroup posts to me by mail is considered rude]
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: Tue, 05 Oct 1999 13:44:48 GMT
From: nimchu@hal-pc.org (Nim Chu)
Subject: Re: How to start up Netscape or Internet Explorer from a Perl script
Message-Id: <7tckqt$2tl1$1@news.hal-pc.org>
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>You might want to see :
><http://msdn.microsoft.com/workshop/browser/webbrowser/reference/Objects/InternetExplorer.asp>
Yes, certainly I'll look up this document.
>In concert with the documentation for Win32::OLE that comes with the
>ActiveState distribution of Perl.
>A quick example:
>#!/usr/bin/perl -w
>use Win32::OLE;
>use strict;
>my $browser = Win32::OLE->new('InternetExplorer.Application') or die "Aiee \n";
>$browser->Navigate('http://www.gellyfish.com',1,'_BLANK');
After trying what you suggested above, I am really excited that it
works. Then I added:
$browser->close();
But it did not close the browser session. However, I think the link
you quoted above will have documentation about what methods to call as
to do the kind of things I want to manipulate the browser session. I
really appreciate your help. (BYW, I tried something similar to what
you suggested but failed because I did take out the sapce between
"Internet Explorer" in the constructor)
------------------------------
Date: Tue, 05 Oct 1999 09:07:09 GMT
From: JAG <greenej@my-deja.com>
Subject: Re: Knowing sizeof (int) inside a Perl program
Message-Id: <7tcf3o$ipn$1@nnrp1.deja.com>
In article <37F93B62.5A371C6@mail.cor.epa.gov>,
David Cassell <cassell@mail.cor.epa.gov> wrote:
> I thought that by definition sizeof(char) had to be 1.
> Huh. Oh well, live and learn... :-)
Unicode and far-eastern language systems (Kanji, traditional chinese,
etc.) use a 2-byte character format.
--
# James Greene - Informatics Consulting - D-79539 Loerrach, Germany
# Internet: www.gucc.org/greene/consult - greene@gucc.org
# PGP Fingerprint: CA88 9BE2 92B3 3162 DF6B 7080 2F9E A97E F25C 5972
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 05 Oct 1999 12:43:15 +0100
From: David Cantrell <NukeEmUp@ThePentagon.com>
Subject: Re: libraries "die"ing
Message-Id: <OOD5N2inbanE5PHHhLWT3bJCOgf1@4ax.com>
On Mon, 27 Sep 1999 16:46:59 GMT, rdosser@my-deja.com said:
>I find myself increasingly annoyed by library subroutines that take the
>liberty of "die"ing for me instead of setting an error code/message and
>returning undef.
You're not the only one.
I suspect that modules/libraries dieing is often because the authors
are aware that programmers frequently don't bother checking return
values. My policy in modules I have written recently is to have them
default to dieing when an error occurs, but if the programmer sets
something like $MyModule::RETURN_ON_ERROR to a true value, they will
return error codes instead. In this way, programmers can make a
'contract' with my module promising that they will be good little boys
and girls and religiously check return values and handle them
appropriately.
[Copying newsgroup posts to me by mail is considered rude]
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: 5 Oct 1999 12:01:20 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: libraries "die"ing
Message-Id: <slrn7vjq4g.9gu.sholden@pgrad.cs.usyd.edu.au>
On Tue, 05 Oct 1999 12:43:15 +0100,
David Cantrell <NukeEmUp@ThePentagon.com> wrote:
>On Mon, 27 Sep 1999 16:46:59 GMT, rdosser@my-deja.com said:
>
>>I find myself increasingly annoyed by library subroutines that take the
>>liberty of "die"ing for me instead of setting an error code/message and
>>returning undef.
>
>You're not the only one.
>
>I suspect that modules/libraries dieing is often because the authors
>are aware that programmers frequently don't bother checking return
>values. My policy in modules I have written recently is to have them
>default to dieing when an error occurs, but if the programmer sets
>something like $MyModule::RETURN_ON_ERROR to a true value, they will
>return error codes instead. In this way, programmers can make a
>'contract' with my module promising that they will be good little boys
>and girls and religiously check return values and handle them
>appropriately.
Of course using eval{} turns the 'die' into the setting of
an error code/message (in $@).
It makes perl code read just like python code... Wrapping
everything in try and catch because simple things throw exceptions
wily-nily.
I'll leave it up to the reader to determine whether perl being like
python is good or bad. (Though I think perl owes a plot
to python when it comes to it's OO style - of course I've been
wrong before).
(There was no python in the headers, and no cross-post, maybe this
won't cause a flame-war... if I whisper).
--
Sam
It is inappropriate to require that a time represented as seconds
since the Epoch precisely represent the number of seconds between
the referenced time and the Epoch
--IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2
------------------------------
Date: Tue, 05 Oct 1999 12:49:36 GMT
From: quikscor@ix.netcom.com (Jana Cole or John Sayre)
Subject: Need help with input verifier
Message-Id: <37f9f1c9.2777093@nntp.ix.netcom.com>
#!/usr/bin/perl
I copied this verification code from Flanagan's JavaScript book, but I
can't get it to work for me. Maybe the way I'm inbedding it in the
Perl, I don't know. Also, I'm not sure if this should be posted here
or on a JavaScript newsgroup.
I'm checking a text field for empty. If it's empty, I'm supposed to
get a dialog box saying please fill the field. The empty field should
not be submitted. But it is. If the field is filled or empty the CGI
program runs, and the field is written to the data file.
When the field is empty, the file record looks like this:
record_number|todays_date|*|
So, it seems that somehow the JavaScript is being ignored.
Why, why, why......
*************************************************************************************
#script: lstreqtst.cgi
use CGI;
$q = new CGI;
print $q->header();
print "<HTML><HEAD><TITLE></TITLE>";
print <<Scripting;
<SCRIPT LANGUAGE="JavaScript">
# verifies input
function verinp(frm)
{
var msg;
var empty_fields = "";
if ((emt.restaurant_name == null) || (emt.restaurant_name == "") ||
isBlank(emt.restaurant_name))
{
empty_fields += "\n " + emt.name;
}
if (!empty_fields) return true;
if (empty_fields)
{
msg += "You must fill in all required fields.\n\n"
msg += "Fill in the following empty fields:"
+ empty_fileds + "\n";
}
alert(msg);
return false;
}
# tests for a field of whitespace
function isBlank(str)
{
for (var i = 0; i < str.length; i++)
{
var chr = str.charAt(i);
if ((chr != ' ') && (chr != '\n') && (chr != '\t')) return
false;
}
return true;
}
</SCRIPT>
Scripting
;
print "</HEAD><BODY>";
# if parameters, write them to file,
# if no parameters, display the form
if ($q->param())
{
#write them to request file
wrtreqfil();
# thank for info
print tnklstinf();
}
else
{
# print the form
prtlstinffrm();
}
print $q->end_html();
# write parameters to file
sub wrtreqfil
{
$record_number = getrecnum();
$month = (qw(1 2 3 4 5 6 7 8 9 10 11 12)) [(localtime)[4]];
$day = (qw(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30 31)) [(localtime)[3]];
$year = (localtime)[5];
if ($year > 99)
{
$year = year - 100;
}
$todays_date = "$month/$day/$year";
open(REQFIL,">>lstreq.txt");
print REQFIL "|$record_number|$todays_date|*";
foreach $name ($q->param())
{
$value = $q->param($name);
if ($value ne "Send")
{
$value =~ s/^\s+//;
$value =~ s/\s+$//;
print REQFIL "|$value";
}
}
print REQFIL "\n";
close(REQFIL);
}
# thank user for info
sub tnklstinf
{
print "Thank you for submitting your information";
}
# display the form
sub prtlstinffrm
{
print <<EndForm
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=10 WIDTH="400"
BGCOLOR="#FFFFFF">
<tr><td><VALIGN=TOP>
<FORM ACTION="lstreq.cgi" METHOD="post" onSubmit="return
verinp(this);">
<INPUT type="text" name="restaurant_name" size="40"><p>
<INPUT type="submit" value="Send" name="submit">
<INPUT type="reset" value="Reset" name="reset">
</FORM>
</td></tr>
</TABLE>
EndForm
;
}
# get the record number to write to file
sub getrecnum
{
open(RECNUMFIL,"recnum.txt");
$currecnum = <RECNUMFIL>;
$nxtrecnum = $currecnum + 1;
open(RECNUMFIL,">recnum.txt");
print RECNUMFIL $nxtrecnum;
close(RECNUMFIL);
chomp($currecnum);
return $currecnum;
}
------------------------------
Date: 5 Oct 1999 09:29:49 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Newbie: Combining split and shift on One Statement
Message-Id: <slrn7vjh8d.fsp.sholden@pgrad.cs.usyd.edu.au>
On Tue, 5 Oct 1999 07:57:51 GMT, I.J. Garlick <ijg@connect.org.uk> wrote:
>In article <mfleming-0410991155460001@cserv51.csubak.edu>,
>mfleming@csub.edu (Michael W. Fleming) writes:
>> I have the following situation:
>>
>> $x = " abc xxx";
>> @stuff = split(/\s+/,$x);
>> shift(@stuff);
>>
>> I have tried all manner of non-working attempts at combining the
>> functionality of the split and shift into one statement. I have tried a
>...[snipped irrelevant explanation]
>>
>> How might I accomplish this?
>
>Simple answer you don't.
>
>You are travelling ten times around the world to accomplish strolling down
>to the corner shop, do you have a really valid reason for doing this?
>
>As far as I can tell the only reason you are doing this is because the
>split gives you a '' value in $stuff[0]
>
>So why not simply remove the leading white space before the split? radical
>concept I know but you'll get the hang of it.
>
> $x =~ s/^\s+//;
Or even better you could read the documentation that comes with perl.
Reading the documentation for split seems like a reasonable thing to do when
you are having problems with split.
What does this quote from the docs indicate to you?
As a special case, specifying a PATTERN of space (C<' '>) will split on
white space just as C<split()> with no arguments does. Thus, C<split(' ')>
can be used to emulate B<awk>'s default behavior, whereas C<split(/ /)>
will give you as many null initial fields as there are leading spaces.
A C<split()> on C</\s+/> is like a C<split(' ')> except that any leading
whitespace produces a null first field. A C<split()> with no arguments
really does a C<split(' ', $_)> internally.
Sounds like
split ' ', $x;
solves the problem...
When will people learn to RTFM?
--
Sam
Remember that the P in Perl stands for Practical. The P in Python
doesn't seem to stand for anything.
--Randal Schwartz in <8cemsabtef.fsf@gadget.cscaper.com>
------------------------------
Date: Tue, 05 Oct 1999 06:20:02 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Newbie: Combining split and shift on One Statement
Message-Id: <37F9DEE2.ADDC544D@texas.net>
David Amann wrote:
>
> Hi Tom,
Hello. Please cease sending stealth email. In fact, you don't need to
email me at all. I read the newsgroup frequently.
> Tom Briles wrote:
>
> > perldoc -f split
> >
> > explains this issue precisely.
>
> I've looked at my version of perldoc -f split, and I don't see where it talks
> about shift or anything like that.
<snipped the mostly irrelevant parts>
> A `split()' on `/\s+/' is like a
> `split(' ')' except that any leading whitespace producess
> a null first field.
The above sentence is saying that if you use '/\s+/' you get a null
first field, and the original posters 'shift' issue. The answer is to
use `split(' ')'. Then, no shift.
- Tom
------------------------------
Date: Tue, 5 Oct 1999 11:39:23 +0200
From: "Fokko Wesselius" <fokko.wesselius@ict.nl>
Subject: odd or even numbers?
Message-Id: <7tckj7$qnq$1@tasmania.dev.ict.nl>
Hello,
Does anybody know if there is an easy way to check whether a scalar value
contains a odd or even integer?
Is there a perl function for this problem?
P.S. I'm using ActivePerl's win32 port of Perl.
------------------------------
Date: Tue, 05 Oct 1999 12:12:08 +0200
From: Frank de Bot <debot@xs4all.nl>
Subject: Re: odd or even numbers?
Message-Id: <37F9CEF7.ED925E5D@xs4all.nl>
You could try this:
$value = 5;
$t = $value/2;
if ($t =~ /\./) {
print "It's odd!";
}
else {
prit "It's Even!";
}
Fokko Wesselius wrote:
> Hello,
>
> Does anybody know if there is an easy way to check whether a scalar value
> contains a odd or even integer?
>
> Is there a perl function for this problem?
>
> P.S. I'm using ActivePerl's win32 port of Perl.
--
Penpal International
http://ppi.searchy.net
ppi@searchy.net or debot@xs4all.nl
------------------------------
Date: 5 Oct 1999 11:27:55 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: odd or even numbers?
Message-Id: <37f9d2ab_2@newsread3.dircon.co.uk>
Frank de Bot <debot@xs4all.nl> wrote:
> Fokko Wesselius wrote:
>
>>
>> Does anybody know if there is an easy way to check whether a scalar value
>> contains a odd or even integer?
>>
>> Is there a perl function for this problem?
>>
>> P.S. I'm using ActivePerl's win32 port of Perl.
>
> You could try this:
>
> $value = 5;
>
> $t = $value/2;
>
> if ($t =~ /\./) {
> print "It's odd!";
> }
> else {
> prit "It's Even!";
> }
>
Well you could or you could do:
if ($value % 2)
{
#odd
}
/J\
--
"I can't believe Elton John recorded that song again. Exactly how do you
live your life like a spurgis in the wind?" - Ronnie, Veronica's Closet
------------------------------
Date: 5 Oct 1999 06:16:36 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: odd or even numbers?
Message-Id: <slrn7vjo0d.e85.abigail@alexandra.delanet.com>
Fokko Wesselius (fokko.wesselius@ict.nl) wrote on MMCCXXVI September
MCMXCIII in <URL:news:7tckj7$qnq$1@tasmania.dev.ict.nl>:
__ Hello,
Bing!
__
__ Does anybody know if there is an easy way to check whether a scalar value
__ contains a odd or even integer?
__
__ Is there a perl function for this problem?
Yes there is!
sub is_even {
my $number = abs shift;
$number ? is_odd -- $number : 1;
}
sub is_odd {!is_even shift}
Or if you don't want to type that much:
sub is_even {"${\5*$_[0]}" =~ /0$/}
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 05 Oct 1999 12:08:34 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: odd or even numbers?
Message-Id: <37F9EA43.348B7716@home.com>
[posted & mailed]
Abigail wrote:
>
> sub is_even {"${\5*$_[0]}" =~ /0$/}
Operator precedence problem.
sub is_even {"${\(5*$_[0])}" =~ /0$/}
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 05 Oct 1999 12:58:52 +0200
From: Thomas Hoffmann <hoffmann@ehmgs2.et.tu-dresden.de>
Subject: OS/2 and <$ARGV[0]/foo/*.bar>: will it work?
Message-Id: <u8ogeem5ub.fsf@ehmgs2.et.tu-dresden.de>
I came across a Perl script, which tries to inspect files. The script
starts with
#! @PERL@
use File::Basename;
while(<$ARGV[0]/foo/*.bar>){
$ARGV[0] =~ /([^\/]*)$/;
(the first line contains the name of the perl interpreter, e.g.
#! /usr/local/bin/perl on my HP-UX box, or
#! g:/emx/bin/perl.exe on my OS/2 box).
Using HP-UX, I can access all the *.bar files, on OS/2 the while loop
exits immediately.
Has this something to do with "globbing" and is there a cure for OS/2?
(I have fiddled around with different shell there).
--
=============================================================================
Thomas Hoffmann, Institut fuer Halbleiter- und Mikrosystemtechnik, TU Dresden
E-mail: hoffmann@ehmgs2.et.tu-dresden.de
------------------------------
Date: Tue, 05 Oct 1999 15:02:48 +0200
From: Gregor Bruhin <gregor.bruhin@bluewin.ch>
Subject: PERL CGI script works in concole but not with IIS or Apache
Message-Id: <37F9F6F8.E5B588C8@bluewin.ch>
Hi,
I have some problems with this simple perl script...
Please, pelase, please help me !
When I run it from a console, it works fine, I get the mail, the std.
output is ok, all is ok, BUT :-)
when I try to run it through a web server (IIS or apache), I get a error
code 500 Internal Server Error, and in the log file:
[Tue Oct 05 10:20:06 1999] [error] [client 10.253.1.135] Premature end
of script headers: c:/program files/apache group/apache/cgi-bin/mail.pl,
this means my script died why ???
or
when I print the header at the beginning of the script, I get no error,
but I get no mail, why ???
Here is the famous script:
_________________________________
#!c:/perl/bin/perl.exe
$port = 25;
$them = 'mail.gtn.ch';
$AF_INET = 2;
$SOCK_STREAM = 1;
$SIG{'INT'} = 'dokill';
sub dokill {
kill 9,$child if $child;
}
$sockaddr = 'S n a4 x8';
($name,$aliases,$proto) = getprotobyname('tcp');
($name,$aliases,$port) = getservbyname($port,'tcp')
unless $port =~ /^\d+$/;;
($name,$aliases,$type,$len,$thisaddr) =
gethostbyname($hostname);
($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
}
else {
die $!;
}
if (bind(S, $this)) {
}
else {
die $!;
}
if (connect(S,$that)) {
}
else {
die $!;
}
select(S);
$| = 1;
select(STDOUT);
print S "MAIL FROM:<CGI_SCRIPT_WEBPAGE>\n";
print S "RCPT TO:<greg.bruhin\@gtn.ch>\n";
$a=<S>;
print S "DATA\n";
$a=<S>;
print S "Subject: test\n\n";
print S "This is a test 1\n";
print S ".\r\n";
$a=<S>;
print S "QUIT";
exit 1 ;
{
local ($oldbar) = $|;
$cfh = select (STDOUT);
$| = 1;
print "Content-type:text/html\n\n";
print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
print "<html>\n<body>TEST <i>by Greg</i></body>\n</html>";
$| = $oldbar;
select ($cfh);
}
_________________________________
Thank you very much
Greg
P.S. It should run an a win NT 4 (i386), all patches applied, latest
release of perl, and latest Apache...
------------------------------
Date: 05 Oct 1999 04:03:01 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Simple - yet won't work!
Message-Id: <m1ln9ink7u.fsf@halfdome.holdit.com>
>>>>> "Anon" == <nihad@yahoo.com> writes:
Anon> flock(INF, 8);
That line is pointless where it is, and dangerous if moved.
Delete it. And distrust any place that you got it from.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 5 Oct 1999 13:00:48 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: sort routine - can it ignore numeric values?
Message-Id: <7tcsq0$rdt$1@pegasus.csx.cam.ac.uk>
Abigail <abigail@delanet.com> wrote:
>
> @sorted = map { $_ -> [0]}
> sort { $a -> [1] cmp $b -> [1]}
> map {[$_ => /\s+([^,]+)/]}
^^^^^^^^^^^^^^^^^^^
> @unsorted;
That happens to work under current Perls, but you're living dangerously.
Perl does not, in general, define order of evaluation. Some future
optimisation might blow that up.
Mike Guy
------------------------------
Date: Tue, 05 Oct 1999 11:44:11 GMT
From: flevli@my-deja.com
Subject: Sorted -- Thanks (Re: Create file ok, write fails)
Message-Id: <7tcoa9$ocp$1@nnrp1.deja.com>
Someone was kind enough to point out that the disk might be full, which
was not only percectly true but also the main reason why I feel
embarrassed at not noticing such an obvious thing myself.
Thanks! cheers!
Fred
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 988
*************************************