[18934] in Perl-Users-Digest
Perl-Users Digest, Issue: 1129 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 13 18:06:03 2001
Date: Wed, 13 Jun 2001 15:05:10 -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: <992469910-v10-i1129@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 13 Jun 2001 Volume: 10 Number: 1129
Today's topics:
Re: assigning a directory as a variable in opendir (Rolf Krahl)
autoload troubles <der.prinz@gmx.net>
better way to break lines of data? <ccollier@lavastorm.com>
Re: Can an lvalue sub also be an rvalue? <nospam-abuse@ilyaz.org>
Re: cgi browser recognition <flavell@mail.cern.ch>
Re: cgi browser recognition <godzilla@stomp.stomp.tokyo>
Re: Compatibility of forms on all Browser (aol error) <godzilla@stomp.stomp.tokyo>
Re: efficient change file with locking? <jhall@ifxonline.com>
Re: Help with split?vvp (Steven)
Re: Help with split?vvp <bart.lateur@skynet.be>
Re: How do I get the current directory from Windows Exp <nospam@hotmail.com>
Re: how do I sort the output of this? <Patrick_member@newsguy.com>
how to extract URL source with LWP ? (DrColombes)
Re: how to extract URL source with LWP ? <der.prinz@gmx.net>
Re: I can not fork at windows (Joe Smith)
I Need Help <hugonv@home.com>
Re: I Need Help (David Efflandt)
Limiting special characters <davsoming@lineone.net>
Re: Limiting special characters <godzilla@stomp.stomp.tokyo>
Re: Limiting special characters <ren@tivoli.com>
newbie-- re:win32 system() calls -- rmdir /s/q <korac@dirig.com>
Re: Perl is dead! Long live Perl! (Tim Hammerquist)
Re: PIng status ? <carlos@plant.student.utwente.nl>
Re: PIng status ? <buggs-clpm@splashground.de>
Re: Serial Comms Win32 (David Efflandt)
Re: Spreadsheet::WriteExcel and cgi output <bart.lateur@skynet.be>
Re: Spreadsheet::WriteExcel and cgi output (isterin)
too late error? <webmaster@vorgasm.com>
Re: too late error? <bed@cic-mail.lanl.gov>
Re: too late error? <bart.lateur@skynet.be>
Re: Which C compiler to use for modules? <godzilla@stomp.stomp.tokyo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Jun 2001 19:04:38 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: assigning a directory as a variable in opendir
Message-Id: <9g8dg6$vtf$1@rotkraut.de>
In article <vBLV6.248739$Z2.2876816@nnrp1.uunet.ca>,
"Lev Altshuler" <lev@circadence.ca> writes:
>
> I have an @array of directories names, generated on the fly.
> Now I need to read the content of these directories. I try to do it
> something like this:
>
> opendir(FH, $array[0]) || die "cannot open $array[0]: $!";
^[2]
> @files = readdir(FH);
>
> I get a message: cannot open [correct name of the directory] : no
^[1]
> such file or directory.
> So, the program reads correctly the directory's name, but complains
> as a directory name is assigned as a variable and not as a
> constant. If $array[0] is replaced with the constant like
> C:/Windows/Cookies, it , of course, works.
I can't reproduce the problem here, works fine for me. Did you double
check, that your array actually does contain the correct name of the
dirs? Without any trailing or leading white space and other ugly
stuff? You cited a blank in the error message [1], where your die
statement does not contain one [2].
--
Rolf Krahl <rolf.krahl@gmx.net>
------------------------------
Date: Wed, 13 Jun 2001 22:58:18 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: autoload troubles
Message-Id: <3b27d39f$1@e-post.inode.at>
Hi,
I have a module that serves as a wrapper for external function calls.
The external library has a hash table with references to the subs I
want executed, but if a subroutine has the same name as a hash key,
the sub will be executed as a method instead of a simple function.
This happens only after the method was called (and AUTOLOADed) at
least once.
If this problem description sounds a litte confused, just run the
first script to see the effect (you'll need all three files in the
current directory). I've also tarred the files up and uploaded them
to http://www.foo.at/tmp/autoload.tar .
Could someone please explain to me why that happens? There's some
magic at play here that I don't understand...
tnx,
stefan
PS: sorry for the (relative) length, this is as short as I could
make it.
runme.pl
-----------------------------------------------------------
#!/usr/local/perl -w
use strict;
use XWrapper;
my $module = new XWrapper;
my $params = { a => 1, b => 2 };
$module->right($params);
$module->right($params);
$module->wrong($params);
$module->wrong($params); # this line shows the problem
XWrapper.pm
-----------------------------------------------------------
package XWrapper;
use strict;
use warnings;
sub new { bless {}; }
sub AUTOLOAD {
my $self = shift;
my $params = shift;
my $method = (split '::', our $AUTOLOAD)[-1];
return if $method eq 'DESTROY';
$self->callfunc($method, $params);
}
sub callfunc {
my $self = shift;
my $method = shift;
my $params = shift;
require "library.pl";
$XWrapper::methods{$method}->($params);
}
1;
library.pl
-----------------------------------------------------------
use strict;
use warnings;
sub wrong {
warn "called from ".(caller)[0].", received a ".ref(shift)." ref\n";
}
sub Xright {
warn "called from ".(caller)[0].", received a ".ref(shift)." ref\n";
}
our %methods = (
wrong => \&wrong,
right => \&Xright,
);
1;
------------------------------
Date: Wed, 13 Jun 2001 17:20:34 -0400
From: "Christopher Z. Collier" <ccollier@lavastorm.com>
Subject: better way to break lines of data?
Message-Id: <9g8l6l0jll@enews1.newsguy.com>
I need to write a program that pulls data stored in a plain ASCII text file
and writes it to another file; this one comma-separated. In the original
file, fields are designated only by a set number of characters for each
field. These field sizes come from a separate specification document. For
instance; suppose:
1002003456779104
were a line of data. The spec may say there are four fields, each four
characters long. So our data is:
1002,0034,5677,9194
My program uese regular expressions to pull out the fields. For my previous
example I'd do something like this:
$curLine =~ /(.{4})(.{4})(.{4})(.{4})/
my $field1 = $1, my $field2 = $2, my $field3 = $3, my $field4 = $4;
I can then do what I wish with the data in the $field variables.
My question is this:
Can anyone think of a more efficient or easier way do do this? Is this
going to be really slow? Are those $1, $2, etc. variables stored in any
kind of array that I can just iterate over? Or should I just be using
substr()?
Thanks
Chris
------------------------------
Date: Wed, 13 Jun 2001 20:55:59 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Can an lvalue sub also be an rvalue?
Message-Id: <9g8k0v$17k8$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <9g7goh$qv2$1@mamenchi.zrz.TU-Berlin.DE>:
> > *No* question about programming may be answered by experiments (unless
> > answered negatively ;-). This is the difference between programming
> > and scripting.
>
> Agreed, with reservations about the script/program semantics. But
> I think you will agree too, that before asking "What would 'print
> sqrt(-1)' print?" it's a good idea to run "perl -le 'print sqrt(-1)'".
I do not agree. It is a good idea to run
perldoc -f sqrt
If it does not help, no experiments will (unless you find two systems
which produce different results).
Ilya
------------------------------
Date: Wed, 13 Jun 2001 19:51:44 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: cgi browser recognition
Message-Id: <Pine.LNX.4.30.0106131943380.26540-100000@lxplus003.cern.ch>
On Wed, 13 Jun 2001, Brian E. Douglass wrote:
> In one of my programs I have a form. It works perfectly with Netscape,
> but not with IE.
Then you're doing something wrong, but that's off-topic here - you
don't appear to have a Perl language problem. While none of the 4
browser families which fit your description could be claimed to be
100% specification-conforming, they can all be used successfully for
forms submission, up to a considerable level of complexity.
> I was wondering how I could set up the script to
> recognize which browser was running it,
User agent strings are unreliable: you're heading for a dreadfully
flakey non-solution to your real trouble.
> so I can set up two different forms.
You're almost certainly trying to solve the wrong problem. The WWW
does not consist of only two browsers. Even "Netscape" could refer to
two fundamentally different implementations. User agent strings are
commonly filtered out, altered by proxies, etc. etc.
You may get a more informative (and constructive) answer from a group
with WWW in its name. But you'd need to offer an actual demonstration
URL of the problems that you claim to be experiencing, if you hope for
a really useful answer.
------------------------------
Date: Wed, 13 Jun 2001 12:50:16 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: cgi browser recognition
Message-Id: <3B27C3F8.4C84A3AA@stomp.stomp.tokyo>
Brian E. Douglass wrote:
> In one of my programs I have a form. It works perfectly with Netscape,
> but not with IE. I was wondering how I could set up the script to
> recognize which browser was running it, so I can set up two different
> forms.
You will have better luck investing time and effort
into discovering what MSIE is screwing up. As you
probably know, MSIE is not industry standard compatible;
it does pretty much whatever it "feels" like doing.
An examination of my header information will quickly
clue you in on why reliance on browser information
should not be used for critical operations. It is
great for curiosity or whatever, but not for use
as an important branching decision.
Godzilla!
------------------------------
Date: Wed, 13 Jun 2001 13:01:42 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Compatibility of forms on all Browser (aol error)
Message-Id: <3B27C6A6.CAB66308@stomp.stomp.tokyo>
Hugo Perez wrote:
(snipped)
> I created a basic form on dreamweaver and it works fine on my computer
> ( system: PC, browser: Explorer, email: Outlook express) but my client
> noticed that when using AOL the information filled out on the form is not
> sent....
> ...I need to have a form that's compatible with all browsers
> in order to satisfy my customers.
Use an America Onlame account or have a friend help you
to test what is going wrong. You will discover, in part,
AOL displays significant problems with form actions,
regardless of what browser is used. Some examples include
an inability to transmit selected html tags and html
entities, a problem with AOL's macro operating system
generating an infinite loop caused by certain html tags
and, most often noticed, any content over a very short
amount, I think around one kilobyte, maybe less, will
cause AOL to completely slaughter this content and
render it into something unexpected; garbage.
Truly your only choice is to actually test via AOL.
You will need patience and luck.
Godzilla!
------------------------------
Date: Wed, 13 Jun 2001 21:13:41 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: Re: efficient change file with locking?
Message-Id: <9IQV6.45205$%a.2325615@news1.rdc1.sdca.home.com>
My system for whatever reason doesn't have flock or lockf, so I did this
instead.. I don't know how great it is.. Simple semaphore-
sub open_db {
my $db = shift;
while(-f ("$datadir/$db".'db.lock')){ select(undef,undef,undef,0.1); }
dbmopen(%{"$db".'db'},"$datadir/$db", 0644) or die "dbmopen: $!";
link (("$datadir/$db".'.db'), ("$datadir/$db".'db.lock'));
}
Then of course I just unlink when i close..
------------------------------
Date: 13 Jun 2001 11:30:01 -0700
From: steve.busiello@gs.com (Steven)
Subject: Re: Help with split?vvp
Message-Id: <fa45b871.0106131030.9642a86@posting.google.com>
I still think this is the best way
$line = "a|b|c|d|e|f|g";
substr($line,0,1) = "0";
print "$line \n";
simple and nice
-Steven
"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> wrote in message news:<3B26297F.9BB8F76A@americasm01.nt.com>...
> Hello,
>
> I have a small script that takes a PIPE ( | ) delimited file that is
> suppose to strip the first field away, replace it with a 0 then keep the
> rest of the | delimited fields.
>
> ie.
>
> file (many lines)
>
> a|b|c|d|e|f|g
>
> output to new file should be
>
> 0|b|c|d|e|f|g
>
> what happens...the file contains this
>
> 0|2
>
> I have to use a PIPE (|) - because that is the standard for all our
> files.
>
> Script:
>
> open (rf,"$filename");
>
> open (faxtemp,">$filename.txt");
> while($line=<rf>) {
> ($a,$items)=split /|/,$line;
> print faxtemp "0|$items \n";
>
> }
> close (rf);
>
> help?
>
> Thanks,
>
> V
------------------------------
Date: Wed, 13 Jun 2001 19:20:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with split?vvp
Message-Id: <q8ffit8rjki14vsorr2urmqa8tqk198a5g@4ax.com>
Steven wrote:
>I still think this is the best way
>
>$line = "a|b|c|d|e|f|g";
>substr($line,0,1) = "0";
>print "$line \n";
>
>simple and nice
Oh yeah?
$line = "first field|b|c|d|e|f|g";
substr($line,0,1) = "0";
print "$line\n";
-->
0irst field|b|c|d|e|f|g
I don't think that is even close.
--
Bart.
------------------------------
Date: Wed, 13 Jun 2001 14:22:42 -0500
From: Mr. SunRay <nospam@hotmail.com>
Subject: Re: How do I get the current directory from Windows Explorer?
Message-Id: <64PV6.769$hw6.272456@news.uswest.net>
> I'm writing a script that is triggered by actions within Windows
> Explorer, and needs to know what the current working directory is.
> Unfortunately, the Win32::GetCwd function is returning with C:\Program
> Files\Common Files\ ...., and not the directory that's open in
> Explorer.
Sounds like a job for Win32::OLE - ick, ick, ICK!
<some stuff snipped>
>
> For those who know what I'm talking about, this script is supposed to
> work as a trigger within Rational ClearCase. The idea is that it
> checks to see what View a person is in, and what VOBs he has loaded,
> before working out whether to let him perform merges, rebases,
> deliveries, etc. Assuming the criteria are met, it then determines
> whether the user is in the correct NT group to be able to carry out
> this action.
>
> --
>
> Many thanks,
>
> Garry
I've used clearcase in unix, but not NT, and it's been a while. I did notice
that there are a few clearcase modules out on CPAN. Perhaps they can help you
out? I haven't looked at them myself.
Doesn't ClearCase use/set some special environment variables (clearcase_root
comes to mind) that perhaps you could use as well?
Regards,
Mr. Sunray
------------------------------
Date: 13 Jun 2001 11:39:55 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: Re: how do I sort the output of this?
Message-Id: <9g8c1r02338@drn.newsguy.com>
Ren,
In article <m3puc8js7v.fsf@dhcp9-173.support.tivoli.com>, Ren says...
>
>On 12 Jun 2001, Patrick_member@newsguy.com wrote:
>
>> Have the following procedure that I just wrote:
>
>You should really see about including:
>
>use strict;
>use warnings;
>
>at the top of your scripts. You will have to make some other changes
>to go along with those.
>
>> #
>> # Usage: perl dtrees.pl PATH
>> # if PATH not defined then PATH=.
>> #
>> use File::Find;
>> my $this_subtree;
>>
>>
>> @ARGV = ('.') unless @ARGV;
>> my $dir = $ARGV[0];
>>
>> # if there isn't a backslash at the end of ARGV[0] add one
>> if ( substr($dir,-1) ne "\" ) { $dir = $dir . "\";}
>
>That's a syntax error.
As I responded earlier to John Krahn, the source does have double back-slashes.
It's an artifact of my Usenet provider that they got converted to single
backslashes.
And the code was running. But you're right I should use strict and warnings.
>
> if ( substr($dir,-1) ne "/" ) { $dir .= "/" }
>
>> opendir DIR, $dir or die "can't opendir $dirname: $!";
>> while (defined($file = readdir(DIR))) {
>> if (-d ($dir . $file) && $file ne "." && $file ne "..") {
>> find sub { $this_subtree += -s }, ($dir . $file);
>
>Change this:
>
>> write();
>
>To:
>
> push @output, [ $file, $this_subtree ];
>
>> $this_subtree = 0;
>> }
>> }
>> closedir(DIR);
>
>And add this here:
>
>($file,$this_subtree)=@$_ and write for sort { $a->[1] <=> $b->[1] } @output;
>
>> format STDOUT =
>> @<<<<<<<<<<<<<<<<<<<<< @###########
>> $file $this_subtree
>> .
>>
>> This works well enough. It takes all the directories within pwd and
>> finds the subtree of each.
>>
>> Next iteration. I'd like to sort the output by the size field
>> ($this_subtree).
>>
>> I've tried saving each line produced by the write() statement via a
>> push to an array. But it's not clear to me how to use sort to sort
>> on a certain column range within each string? Or do I need to set
>> up my elements as data structures (with, presumably, a name and a
>> size)?
>
>The solution above pushes the data for the write and delays the write
>until the end when the data can be sorted. There are, of course,
>other ways to do this.
This worked perfectly. Thanx.
pat
>
>--
>Ren Maddox
>ren@tivoli.com
------------------------------
Date: 13 Jun 2001 12:40:26 -0700
From: EPurcell@ix.netcom.com (DrColombes)
Subject: how to extract URL source with LWP ?
Message-Id: <f6e5b1a0.0106131140.5eaa617@posting.google.com>
I want to extract source from a URL address.
The sample Perl LWP code below (from p. 453 of the "Perl in a
Nutshell" O'Reilly book), running on an ActiveState Perl installation,
fails with a "Can't locate host" error message.
----------------------------------------------------------------
use LWP::UserAgent;
$hdrs = new HTTP::Headers(Accept => 'text/plain',
User-Agent => 'MegaBrowser/1.0');
$url = new URI::URL('http:://www.latimes.com/');
$req = new HTTP::Request(GET, $url, $hdrs);
$ua = new LWP::UserAgent;
$resp = $ua->request($req);
if ($resp->is_success) {
print $resp->content;}
else {
print $resp->message;}
----------------------------------------------------------------
Any suggestions, corrections on how to extract source from a Web site
would be much appreciated.
Thanks for your help.
------------------------------
Date: Wed, 13 Jun 2001 23:19:34 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: how to extract URL source with LWP ?
Message-Id: <3b27d89b$1@e-post.inode.at>
DrColombes <EPurcell@ix.netcom.com> wrote:
Two typos:
> User-Agent => 'MegaBrowser/1.0');
this should be "User_Agent",
> $url = new URI::URL('http:://www.latimes.com/');
and this should be http://www.latimes.com/
cheers,
stefan
------------------------------
Date: Wed, 13 Jun 2001 19:11:02 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: I can not fork at windows
Message-Id: <9g8ds6$203q$1@nntp1.ba.best.com>
In article <992330594.302450@athnrd02.forthnet.gr>,
novastar <root@novastar.dtds.net> wrote:
>I tried the following code under windows NT4 but at the end I am getting an
>error. Please help.
>
>
>$|= 1;
>for $var (1..3)
>{
>
> for (1..2)
> {
> if ( $pid=fork() )
> {
> print "Parent $$ created child $pid\n" ;
> sleep 1;
> waitpid($pid,0);
> exit 0;
> }
> elsif ( ! defined $pid )
> {
> die "Can not go to multi thread mode\n"
> }
> else
> {
> print "Child $$ running\n";
> }
> }
>
>print "\nThread team $var finished\n\n";
>}
>
>print "Program $$ finished\n";
This appears to be a bug in perl for Win32; it fails on Windows-98 also.
When I ran it on Win98, I got
PERL caused an invalid page fault in
module PERL56.DLL at 0167:28073b9f.
Registers:
EAX=00000001 CS=0167 EIP=28073b9f EFLGS=00010202
EBX=02bc5420 SS=016f ESP=03cdfe54 EBP=03cdfe58
ECX=01663db0 DS=016f ESI=02bc5408 FS=6d97
EDX=81c433ec ES=016f EDI=02bc5480 GS=0000
Bytes at CS:EIP:
8b 50 fc 6a 01 59 84 d1 74 67 83 65 08 00 53 8b
Stack dump:
01663db0 03cdfea8 28074b46 00000001 2806fdfc 01662254 00000001
2800e9c5 00000001 02bc5420 02bcf020 000000ff 280581f2 02bcf020
02bc5420 02bcf020
C:\TEMP>perl temp.pl
Parent 412345 created child -326661
Child -326661 running
Parent -326661 created child -327257
Child -327257 running
Thread team 1 finished
Parent -327257 created child -326241
Child -326241 running
Parent -326241 created child -325225
Child -325225 running
Thread team 2 finished
Parent -325225 created child -324209
Child -324209 running
Child -298617 running
Thread team 3 finished
Parent -324209 created child -298617
Program -298617 finished
C:\TEMP>perl -v
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 625 provided by ActiveState Tool Corp. http://www.ActiveState.com
Built 16:20:01 Mar 22 2001
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Wed, 13 Jun 2001 19:47:09 GMT
From: "Hugo Perez" <hugonv@home.com>
Subject: I Need Help
Message-Id: <1rPV6.12653$036.3089420@news1.elcjn1.sdca.home.com>
Greetings,
I created a basic form on dreamweaver and it works fine on my computer
( system: PC, browser: Explorer, email: Outlook express) but my client
noticed that when using AOL the information filled out on the form is not
sent. I recognized that I wasn't doing enough so I educated my self on
scripts and languages. I just ended up confused. I need to have a form
that's compatible with all browsers in order to satisfy my customers.
I appreciate all comments. Thank You.
------------------------------
Date: Wed, 13 Jun 2001 21:07:35 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: I Need Help
Message-Id: <slrn9iflgn.pot.see-sig@typhoon.xnet.com>
On Wed, 13 Jun 2001 19:47:09 GMT, Hugo Perez <hugonv@home.com> wrote:
> Greetings,
> I created a basic form on dreamweaver and it works fine on my computer
> ( system: PC, browser: Explorer, email: Outlook express) but my client
> noticed that when using AOL the information filled out on the form is not
> sent. I recognized that I wasn't doing enough so I educated my self on
> scripts and languages. I just ended up confused. I need to have a form
> that's compatible with all browsers in order to satisfy my customers.
Didn't I see this post already. The fact that you mention an e-mail
client makes this look like you might be using a mailto: action, which is
not an html standard, totally unreliable for form processing, and has
nothing to do with Perl.
Now if you really are using CGI for this, the *.cgi newsgroup may be more
receptive about CGI questions. If you have a Perl specific question, post
some code or a URL to a text version of the source and/or working example.
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Wed, 13 Jun 2001 19:31:19 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Limiting special characters
Message-Id: <tifbvtkg6e3i0e@corp.supernews.co.uk>
[Also see similar subject posts above.]
hello, here again :-)
The commented-out portion below "disallowed" specific named characters and
promptly returned the offending character to browser errorpage ( )
The new code is a much safer method, see:
http://www.cert.org/tech_tips/cgi_metacharacters.html#4
disallowing anything other than what's specified- and works great!
(thanks to EBC for the above link)
My fields are: $firstname, $familyname, $email, $phone, $fax,
$serchkeywords, and $message
obviously I have adapted each to accept only certain characters specific to
its purpose example $phone and $fax = if ($phone =~ tr/0-9\n\t //c) and
$message with limited punctuality etc.
However I would like offending characters to be loaded to errorpage ( ) as
it did with the original version. How should I go about this/modifying the
scalar value example below?
#if ($message =~ /($+[?|()[\]{}^*<])/) {
if ($message =~ tr/a-zA-Z0-9.,?-\n\t //c) {
$errormessage = "Special characters such as: ( $+ ) are forbidden. You
used one in the message field";
&errorpage;
die;
}
############error page##########
sub errorpage{
print "Content-type: text/html", "\n\n";
print<<EOF;
<html>
<head>
<title>ERROR!</title>
</head>
<body bgcolor="#FFFFFF">
<h1>We are sorry!</h1>
<p>The form was not filled in correctly.</p>
Here is the problem: <b>$errormessage</b>
<p>
Please use the "back button" of your browser to return to the form and
correct the mistake.
<p>
<font color="656565"><i><b>admin\@my-domain.com</b></i></font>
</body>
</html>
EOF
}
#######
Thanks for all your input.
--
David Soming
'Just a head-banger- doing what I do best'
______________
------------------------------
Date: Wed, 13 Jun 2001 12:32:33 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Limiting special characters
Message-Id: <3B27BFD1.71B1950C@stomp.stomp.tokyo>
David Soming wrote:
(snipped)
> However I would like offending characters to be loaded to errorpage ( ) as
> it did with the original version. How should I go about this/modifying the
> scalar value example below?
> if ($message =~ tr/a-zA-Z0-9.,?-\n\t //c) {
> $errormessage = "Special characters such as: ( $+ ) are forbidden. You
> used one in the message field";
> &errorpage;
> die;
> }
> sub errorpage{
> print "Content-type: text/html", "\n\n";
> print<<EOF;
(snipped html)
There are a number of ways to do this. My test script
below my signature exemplifies a simple method using
a "safe copy" which is partially or completely destroyed
depending on input content of your $message via use
of transliteration delete. Another easy method is to
compare the numerical return of transliteration against
the length of your input. Still another, would be to
use a match regex to check content. All of these methods
and other methods can be wrapped in an if conditional.
Looking over your partial script, there are two quick
and easy ways to improve efficiency and reduce your
amount of needed coding. Your use of "die" is somewhat
inefficient. This die function performs a number of
operations before actually causing a script to terminate,
such as sending data to Standard Error. Use of "exit"
in its place is a cleaner and quicker method. Avoid
use of die unless you intend to capture STDERR messages.
Your subroutine &errorpage is not really needed for
what you show. This entire html print can be moved
up into your if conditional shown by my line:
## print html output here
Eliminating both die and your sub-routine will help
you in creating a shorter and more efficient script.
An error message sub-routine is helpful, however,
if you are generating an error message selected
from numerous potential error messages based upon
different functions within a script.
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
## Change $message to accepted characters as well for testing
$message = "!!真 ";
$safe_copy = $message;
$safe_copy =~ tr/a-zA-Z0-9.,?-\n\t //d;
if ($safe_copy)
{
## print html output here
print "Special characters such as: $safe_copy are forbidden.\n",
"You used $safe_copy in the message field.";
exit;
}
else
{ print "successful passage of $message"; }
exit;
PRINTED RESULTS:
________________
Special characters such as: !!真 are forbidden.
You used !!真 in the message field.
------------------------------
Date: 13 Jun 2001 13:48:52 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Limiting special characters
Message-Id: <m3lmmwjjvv.fsf@dhcp9-173.support.tivoli.com>
On Wed, 13 Jun 2001, davsoming@lineone.net wrote:
[snip]
> #if ($message =~ /($+[?|()[\]{}^*<])/) {
> if ($message =~ tr/a-zA-Z0-9.,?-\n\t //c) {
> $errormessage = "Special characters such as: ( $+ ) are forbidden. You
> used one in the message field";
> &errorpage;
> die;
> }
[snip]
tr/// does not have any mechanism for returning the characters it
found, so you'll have to go back to the m// method:
if ($message =~ /([^a-zA-Z0-9.,?\n\t -])/) {
or, noticing the character classes (and allowing "_"):
if ($message =~ /([^\w\s.,?-])/) {
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 13 Jun 2001 15:41:51 -0400
From: Korac <korac@dirig.com>
Subject: newbie-- re:win32 system() calls -- rmdir /s/q
Message-Id: <3B27C1FF.588D51B3@dirig.com>
I'm having trouble using "rmdir /s/q dirname" within the sytem call,
I've tried putting it in all one string, using join to jam it into a
variable and it still won't execute properly. Is there something
critical I'm missing here?
======================
$remdir_cmd = "rmdir /s/q "; # extra space at end
$remlist = ( <various directory names in quotes sep. by commas>);
...
for($i=0; $i < @remlist; $i++)
{
$temp_cmd = join '',$remdir_cmd,$remlist[$i];
system( $temp_cmd) == 0
or die "system $temp_cmd failed: $?\n";
}
=======================
I've tried not having the space in $remdir_cmd and adding a ," ", to the
join command also. All I get is a return error of -1 from system().
Any thoughts on this appreciated. Thanks.
Korac MacArthur
------------------------------
Date: Wed, 13 Jun 2001 20:24:34 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Perl is dead! Long live Perl!
Message-Id: <slrn9ifjjo.2ce.tim@vegeta.ath.cx>
agseuj <no@spam.org> wrote:
>
> tadmc@augustmail.com (Tad McClellan) wrote:
>
> >You can flip burgers with 22 characters of Perl.
> >
> > s/burgers/reverse$&/e;
> >
> >If anyone knows Java well, please post the guts of what it would
> >take to get that done in Java.
> >
>
> if defined as a StringBuffer called buf
> (StringBuffer buf = new StringBuffer( "burger"); )
>
> then:
> buff.reverse();
> would be even shorter in VB.
>
> However the length is irrelevent, its the code generated by the compiler
> that counts.
If all you want to do is reverse the single string 'burger', here's the
bare Perl for it:
$str = reverse 'burger';
But I think the poster asked for a Java solution to replace all
instances of the word 'burger' in a larger (possibly multi-line) string.
Does buf.reverse() accomplish this?
Python's string capabilities are also far less convenient in this case,
but here goes:
#!/usr/local/bin/python
import string, re
def method1(text):
return string.replace( text, 'burger', 'regrub' )
def method2(text):
re.sub( r'burger', 'regrub', text )
return text
--
-Tim Hammerquist <timmy@cpan.org>
She brought in herself and we all pay the penalty...
She took on the world and lost everything on the way;
Poor girl, they'll say."
-- "All About Paula", Limp
------------------------------
Date: Wed, 13 Jun 2001 20:11:40 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: PIng status ?
Message-Id: <9g8act$i6u$1@dinkel.civ.utwente.nl>
but Net::Ping needs r00t for icmp
that sucks
--carlos
:wq
"Tom Klinger" <admin@the-piper.net> wrote in message
news:VxGV6.14185$cF.310703@news1.nokia.com...
>
> "martin cassidy" <martin.cassidy@uk.sun.com> wrote in message
> news:3B27272C.4153CDC3@uk.sun.com...
> > Hi all,
> >
> >
> > Could any one let me know how to grab the return code of a ping command
> > ie 0 for successful and any other number for ping failure in a script im
> > working on ?
> >
> >
>
> May I suggest you to use Net::Ping?
> Information about is available here:
> http://search.cpan.org/doc/RMOSE/Net-Ping-2.02/Ping.pm
>
> Hope this helps.
>
> Cheers, Tom
>
>
------------------------------
Date: Wed, 13 Jun 2001 21:35:24 +0200
From: buggs <buggs-clpm@splashground.de>
Subject: Re: PIng status ?
Message-Id: <9g8fc7$e2$02$1@news.t-online.com>
carlos wrote:
> but Net::Ping needs r00t for icmp
> that sucks
Like your ping programm pobably does.
Usually it's a suid programm.
Buggs
------------------------------
Date: Wed, 13 Jun 2001 21:15:51 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Serial Comms Win32
Message-Id: <slrn9ifm07.pot.see-sig@typhoon.xnet.com>
On Wed, 13 Jun 2001 14:36:44 +0100, Gary Hall <GaryHall@Cadence.Com> wrote:
> Can anyone point me to some examples of how to communicate via a PC
> serial port using perl.
Win32::SerialPort module which has also been ported to Device::SerialPort
for Unix (Linux).
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Wed, 13 Jun 2001 19:15:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Spreadsheet::WriteExcel and cgi output
Message-Id: <b8cfit4epgmea72rs20d41r59gqsohsfvk@4ax.com>
mbower@ibuk.bankgesellschaft.de wrote:
>I'm trying to use Spreadsheet::WriteExcel to stream output to a
>browser . The following program works fine, but if I alter the
>output and run it again the browser uses the cached version instead
>and doesn't display the new data.
>
>If I could work out where to add the tag <META name="Expires"
>content="0">, maybe that would fix it ??
An Excel file is not a HTML file. So you can't use HTML tags to do what
you want. But you probably *can* use extra CGI headers, to achieve what
you want. Yes, that could be "Expires:" plus a date+time. You better add
a "Date:" header to, so the clocks of the server and of the browser can
be synchronized.
<http://www.w3.org/Protocols/HTTP/Object_Headers.html>
--
Bart.
------------------------------
Date: 13 Jun 2001 14:45:25 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: Spreadsheet::WriteExcel and cgi output
Message-Id: <db67a7f3.0106131345.5b4d8bb3@posting.google.com>
You don't add meta tags to application/x-msexcel header. You have a
browser cache set problem and not a perl problem. Please refer to
correct news group, although you can easily set it youself.
Ilya Sterin
mbower@ibuk.bankgesellschaft.de wrote in message news:<3b279479.117271031@news>...
> I'm trying to use Spreadsheet::WriteExcel to stream output to a
> browser . The following program works fine, but if I alter the
> output and run it again the browser uses the cached version instead
> and doesn't display the new data.
>
> If I could work out where to add the tag <META name="Expires"
> content="0">, maybe that would fix it ??
>
>
>
> #!/usr/bin/perl -w
> use strict;
> use Spreadsheet::WriteExcel;
>
> # Set the filename and send the content type and disposition
> my $filename ="cgitest$$.xls";
>
> print "Content-type: application/vnd.ms-excel\n";
> #print "Content-Disposition: attachment; filename=$filename\n\n";
> print "\n";
>
> my $workbook = Spreadsheet::WriteExcel->new("-");
> my $worksheet = $workbook->addworksheet('ha');
> my $worksheet = $workbook->addworksheet('ho');
> my $format = $workbook->addformat();
>
> $format->set_bold();
> $format->set_color('black');
> $format->set_align('right');
>
> my $x=0;
> my $y=0;
> for($y=0; $y<35; $y++) {
> for($x=0; $x<11; $x++) {
> $workbook->write($y, $x, $x*$y, $format);
> }
> }
>
> $workbook->write(0, 0, "hello testing", $format);
> $format->set_color('red');
> $workbook->write(1, 0, "Next line", $format);
> $workbook->close();
------------------------------
Date: Wed, 13 Jun 2001 11:37:58 -0700
From: "Vice" <webmaster@vorgasm.com>
Subject: too late error?
Message-Id: <9g8c0m$pa0$1@news.efn.org>
I get the error:
Too late for "-T" option at isbuild.pl line 1.
when trying to execute a .pl script from telnet
what does it mean?
------------------------------
Date: Wed, 13 Jun 2001 13:23:51 -0600
From: "Brian E. Douglass" <bed@cic-mail.lanl.gov>
Subject: Re: too late error?
Message-Id: <3B27BDC7.29B95598@cic-mail.lanl.gov>
Vice wrote:
> I get the error:
> Too late for "-T" option at isbuild.pl line 1.
> when trying to execute a .pl script from telnet
>
> what does it mean?
It means that you used #!/usr../perl -T, but didn't initialize it when
you ran the program, you need to type perl -T file.pl
------------------------------
Date: Wed, 13 Jun 2001 19:37:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: too late error?
Message-Id: <p4gfitcrbrvdrvhkv9r1v8ijn0qgk6q9k1@4ax.com>
Vice wrote:
>I get the error:
>Too late for "-T" option at isbuild.pl line 1.
>when trying to execute a .pl script from telnet
>
>what does it mean?
That you can't use the -T option on the shebang line. Your perl script
needs to be called using it as a command line option.
perl -T myscript.pl ...
Note that if your script passes the -T test, you no longer need it.
--
Bart.
------------------------------
Date: Wed, 13 Jun 2001 13:07:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Which C compiler to use for modules?
Message-Id: <3B27C7F0.45A299D4@stomp.stomp.tokyo>
isterin wrote:
(topic is compiling modules for Win 32)
> On Windows you should have ActiveState and install binary packages
> through ppm utility that comes with it. If you ever need to compile a
> module that is not available through activestate binaries, you must
> use VC++, because this is what ActiveState perl is compiled with. You
> must compile all packages with the same compiler that you perl was
> compiled with.
I read this in my research. My hopes are to be able
to use a free C compiler suggested by Bart Lateur.
Hopefully, there will not be compatibility issues
as you suggest.
It is becoming increasingly clear, there are significant
hurdles to overcome in C compiling modules. I believe a
person could win a lot of Brownie Points by writing a
program specifically designed to C compile modules
for Win 32 and similar systems. So far, it appears
the major problem is creating a Dynamic Library file
to point Win 32 in the right direction for loading.
Godzilla!
------------------------------
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 1129
***************************************