[15564] in Perl-Users-Digest
Perl-Users Digest, Issue: 2977 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 8 14:09:28 2000
Date: Mon, 8 May 2000 11:05:31 -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: <957809129-v9-i2977@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 8 May 2000 Volume: 9 Number: 2977
Today's topics:
Accidental Creation of Static Variable <sariq@texas.net>
Re: Accidental Creation of Static Variable nobull@mail.com
Re: CGI Problem <tony_curtis32@yahoo.com>
Re: Checking if Child Process is still Alive abeall@ipcell.com
Re: Color under MS-DOS/WINNT <thunderbear@bigfoot.com>
Re: Color under MS-DOS/WINNT <mjcarman@home.com>
Re: Command Line input <andkaha@my-deja.com>
Re: converting input to <p></p> pairs via perl <iltzu@sci.invalid>
Re: converting input to <p></p> pairs via perl (Bart Lateur)
Re: date manipulations/library Gordon.Haverland@agric.gov.ab.ca
Re: date manipulations/library (Bart Lateur)
Does anyone use Perl on Alpha based NT systems? <lkb@lkba.com>
Re: Email Attachments using OLE MAPI.Session on NT <sigvald.refsum@siemens.no>
file permisions- setuid? <adams1015@worldnet.att.net>
Re: Getting the platform on which Perl is running <Joachim.Pimiskern@de.bosch.com>
Re: Getting the platform on which Perl is running (Bart Lateur)
Re: Getting the platform on which Perl is running <mjcarman@home.com>
Re: Getting variables from html <kerry@shetline.com>
Re: Getting variables from html <tony_curtis32@yahoo.com>
Re: Getting variables from html <kerry@shetline.com>
Re: Getting variables from html <flavell@mail.cern.ch>
Re: How single-line switch (/s) works in regexps? nobull@mail.com
how to clear a @list ... ? <kmojar@bmjgroup.com>
Re: how to clear a @list ... ? (Bart Lateur)
Re: how to clear a @list ... ? <Joachim.Pimiskern@de.bosch.com>
Re: how to clear a @list ... ? nobull@mail.com
How to make a grep utility for Win32 <EUSWMCL@am1.ericsson.se>
Re: How to make a grep utility for Win32 (Bart Lateur)
Re: How to make a grep utility for Win32 <gellyfish@gellyfish.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 08 May 2000 10:28:26 -0500
From: Tom Briles <sariq@texas.net>
Subject: Accidental Creation of Static Variable
Message-Id: <3916DD1A.41ACA36A@texas.net>
Given:
---
#!/usr/bin/perl -w
use strict;
foo(20);
foo(10);
sub foo {
my ($comp) = @_;
my $test = 1 if $comp == 30;
$test = 2 if $comp == 20;
print "$test\n";
}
__END__
Could someone kindly explain why $test seems to be static?
Is this behavior documented?
- Tom
------------------------------
Date: 08 May 2000 17:59:35 +0100
From: nobull@mail.com
Subject: Re: Accidental Creation of Static Variable
Message-Id: <u98zxlgeq0.fsf@wcl-l.bham.ac.uk>
Tom Briles <sariq@texas.net> writes:
> Given:
>
> ---
>
> #!/usr/bin/perl -w
>
> use strict;
> foo(20);
> foo(10);
>
> sub foo {
> my ($comp) = @_;
> my $test = 1 if $comp == 30;
> $test = 2 if $comp == 20;
> print "$test\n";
> }
> __END__
>
> Could someone kindly explain why $test seems to be static?
Because it has been declared by never initialised.
The line...
my $test = 1;
...does two things. First it declares $test at compile time as
lexically scoped to the encosing block. Secondly it assigns $test at
run time to one.
my $test = 1 if $comp == 30;
Still does the compile-time stuff but not the runtime stuff.
> Is this behavior documented?
Not that I know of, I'd call it a bug. You are probably accessing data
via an uninitialised pointer. That way lies segmentation faults.
c.f. goto over a variable declaration with initializer in C++.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 08 May 2000 10:07:43 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: CGI Problem
Message-Id: <873dntqdvk.fsf@shleppie.uh.edu>
>> On Mon, 08 May 2000 03:52:34 GMT,
>> "Jason Malone" <jamalone@earthlink.net> said:
> I am having the wierdest thing happen. I have written a
> script that opens a file and writes some data to it that
> it is getting from an HTML GET. The problem is that
> sometimes it writes the correct data and sometimes it
> writes old data.
Are you using LWP?
> i.e. it is like it is caching data that i submitted a
> couple of times before and it writes that instead of
> what i just submitted.
> Does anyone have any suggestions.
The error is on line 17.
(You haven't given enough information to allow anyone to
help you. You'll need to show code that exhibits this
behaviour, preferably a small example. Are you using
something like mod_perl? Platform? OS version? perl
version?)
hth
t
------------------------------
Date: 08 May 2000 12:44:50 EDT
From: abeall@ipcell.com
Subject: Re: Checking if Child Process is still Alive
Message-Id: <3916ef22.360727098@news.ipcell.com>
On Sun, 07 May 2000 21:25:03 GMT, Peter Wirdemo
<Peter.Wirdemo@Ericsson.COM> wrote:
>perldoc -f kill
> kill SIGNAL, LIST
> Sends a signal to a list of processes. Returns the
> number of processes successfully signaled (which is
> not necessarily the same as the number actually
> killed).
>
> $cnt = kill 1, $child1, $child2;
> kill 9, @goners;
>
> -> If SIGNAL is zero, no signal is sent to the process.
> -> This is a useful way to check that the process is
> -> alive and hasn't changed its UID. See the perlport
> -> manpage for notes on the portability of this
> -> construct.
>
>/Peter
>
>
>abeall@ipcell.com wrote:
>>
>> Does anyone know how the main process can check if a particular child
>> process has died without making the main process wait.
>>
>> Caveat: this must work with Activeperl on a NT box but if you know how
>> to do this in unix I would still like to know :).
>>
>> Below is an example of what I would like to do:
>> $pid = fork();
>> if ($pid == 0) { #Child process
>> system("sdf -2mif stuff.txt");
>> exit(0);
>> }
>>
>> if ($pid != 0) { #Parent Process
>> while (1) {
>> sleep 5;
>> if (child has not died yet) {
>> print "The child is still doing something. Please be
>> patient\n";
>> }
>> }
>> }
>>
>> Thanks in Advance,
>> Art Beall
I took your advice and tried the following code on a linux, sun, and
nt box with no success. I must be doing this wrong. The line kill 0 =>
$kidpid always returns a 1. What is the trick?
#!/usr/local/bin/perl
die "can't fork: $!" unless defined($kidpid = fork());
# the if{} block runs only in the parent process
if ($kidpid) {
print "I am the main process: $kidpid\n";
if (kill 0 => $kidpid){
print "I should see this if child is alive\n";
}
sleep 5;
kill("TERM", $kidpid); # send SIGTERM to child
if (kill 0 => $kidpid){
print "I should not see this because the child has died\n";
}
}
# the else{} block runs only in the child process
else {
print "I am the child process $kidpid\n";
exit;
}
------------------------------
Date: Mon, 08 May 2000 18:03:12 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: Color under MS-DOS/WINNT
Message-Id: <3916E540.FE7DB028@bigfoot.com>
Francois Dupradeau wrote:
> And here is the result:
>
> ?[31mThis text is in ed !
>
> I don't understand why this result. Someone can help me please ? Thanks
The console needs to interpret the ANSI codes for the method to work.
Yours doesn't.
--
Thorbjørn Ravn Andersen "... plus .. Tubular Bells!"
http://www.mip.sdu.dk/~ravn/
------------------------------
Date: Mon, 08 May 2000 11:20:41 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Color under MS-DOS/WINNT
Message-Id: <3916E959.427ECB3D@home.com>
Thorbjørn Ravn Andersen wrote:
>
> The console needs to interpret the ANSI codes for the method to work.
> Yours doesn't.
Which is to say that you need to load ANSI.SYS before creating you DOS
window. IIRC, you do this in CONFIG.SYS via either a 'device=' or
'loadhigh' command. I can't help you more (sorry) but that should at
least point you in the right direction.
-mjc
------------------------------
Date: Mon, 08 May 2000 14:38:38 GMT
From: Andreas Kahari <andkaha@my-deja.com>
Subject: Re: Command Line input
Message-Id: <8f6jhc$7v3$1@nnrp1.deja.com>
In article <8f5skv$fo2$1@nnrp1.deja.com>,
chris2037@my-deja.com wrote:
> Hello,
>
> Reading in command line inputs seems to be the simpliest of tasks. I
> have read all I can in books as well as in FAQs but still stuck. I
have
> tried Getopts, getopt, Getoptions, @ARG but none seem to work the way
I
> want it to. All I want to do is this:
>
> The user can type in a multitude of switches then filenames like so
>
> myscript -nvrs file1
> or
> myscript -n file1 file2
> or
> myscript file1 file2
> etc...
>
> Hope you can help. Thanks.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
As a previous reply pointed out, @ARGV contains your command line. Also,
the Getopt::Std package will help you parse it (see "perldoc
Getopt::Std").
/A
--
# Andreas Kähäri, <URL:http://hello.to/andkaha/>.
# All junk email is reported to the appropriate authorities.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 8 May 2000 13:53:46 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <957792334.20197@itz.pp.sci.fi>
In article <8f5567$mhc$0@216.155.33.54>, The WebDragon wrote:
>In article <957725299.28467@itz.pp.sci.fi>, Ilmari Karonen
><usenet11084@itz.pp.sci.fi> wrote:
> |
> | s!\r\n?!\n!g;
> | s!\n!<br>\n!g;
> | s!(<br>\n){2,}!</p>\n<p>!g;
>
>this produces nearly the most correct results I've seen so far, namely
>this:
>-=-output from snip two
><p>Enter your comments separated by double-returns like normal
>paragraphs. </p>
><p>If you want lines to break </p>
><p>like this, then enter it that way. </p>
Funny. It did insert the <br>:s when I tested it. Anyway, I came to
the conclusion that the "right" way to do this is with split /\n\n+/:
# preprocess text
# (this is where you might want to encode &, < and ")
$text =~ s/\r\n?/\n/g;
$text =~ s/\n+$//;
# convert text to HTML paragraphs
my $html = join "</p>\n\n<p>" =>
grep 1+(s/\n/<br>\n/g) => split /\n\n+/ => $text;
print "<p>$html</p>\n";
..or perhaps you might want to detect preformatted text and handle it
separately:
# preprocess text
# (this is where you might want to encode &, < and ")
$text =~ s/\r\n?/\n/g;
$text =~ s/\n+$//;
# convert text to HTML paragraphs and preformatted blocks
my $html = "";
foreach my $p (split /\n\n+/ => $text) {
if ($p =~ /^\s/m or $p =~ /\t/ or $p =~ / {3,}\S/) {
$html .= "<pre>\n\n$p</pre>\n";
} else {
$p =~ s/\n/<br>\n/g;
$html .= "\n<p>$p</p>\n";
}
}
print "$html";
Properly detecting lists and indented text and generating the
appropriate markup is left as an exercise to the reader. ;-)
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: Mon, 08 May 2000 15:29:03 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <391bdc8b.28206129@news.skynet.be>
Ilmari Karonen wrote:
> $text =~ s/\r\n?/\n/g;
> $text =~ s/\n+$//;
If you're doing to do split /\n\n+/ on this string, you don't need the
second statement. split() will throw away empty scalars at the end of
it's list.
And, just to be sure, I'd replace "\r\n?" with their hard-coded
counterparts, "\015\012?". "\r" and "\n" do not always mean the same
thing on different platforms; but you need these hardcoded characters
anyway.
--
Bart.
------------------------------
Date: Mon, 08 May 2000 15:18:30 GMT
From: Gordon.Haverland@agric.gov.ab.ca
Subject: Re: date manipulations/library
Message-Id: <3916da74.269299229@news.gov.ab.ca>
On Fri, 05 May 2000 18:33:34 -0500, Randon Loeb
<rloebusenet@cticonsulting.net> wrote:
>I am looking for a library that will do things like allow me to add and
>subtract days from a given date, giving me the new date. It would take
>into account # of days in each month, etc.. Most languages have some
>function called dateserial, something like this. I'm finding hard to
>explain, if you understand and have an answer please email me.
>Thanks,
In perl, there are a few. Date::Manip (I think I have that right) is
probably the most capable, and the slowest. But there are a few perl
modules which do the kinds of date arithmetic you are talking about.
Gord
------------------------------
Date: Mon, 08 May 2000 15:51:19 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: date manipulations/library
Message-Id: <391de061.29188518@news.skynet.be>
[posted and mailed]
Randon Loeb wrote:
>I am looking for a library that will do things like allow me to add and
>subtract days from a given date, giving me the new date. It would take
>into account # of days in each month, etc.. Most languages have some
>function called dateserial, something like this.
There are quite a few modules available that can do this. One of the
most popular ones is Date::Calc. See CPAN (<http://search.cpan.org/> to
get it; or Activestate's site (<http://www.activestate.com/packages/>)
for the Win32 binary version.
However, I personally consider these modules overkill. Most of them can
easily convert string into dates; if you need that, go ahead and use
them.
If all you need is something like "dateserial()", than just remeber that
Perl dates and times are stored as seconds since the epoch (1970 on
Unix). localtime() and gmtime() will take this argument and either turn
this into a string, in scalar context, or to a list of date
specification fragments. Well: the standard module Time::Local, which
*is already in your installation*, will do the exact reverse. So you can
turn a date and time into seconds since the epoch, add $n * 24*60*60 to
it, and turn them back into date and time using localtime() or gmtime().
Bingo.
--
Bart.
------------------------------
Date: Mon, 08 May 2000 11:26:29 -0400
From: Larry Blische <lkb@lkba.com>
Subject: Does anyone use Perl on Alpha based NT systems?
Message-Id: <3916DCA5.288E4497@lkba.com>
I have a client who is interested in hosting a Perl/Oracle app on an
existing Alpha NT server. I'm having trouble locating the DBI and
DBD::ODBC modules. Does anyone have pre-built versions of these or
instructions on how I can build these myself?
Larry Blische
lkb@lkba.com
------------------------------
Date: Mon, 08 May 2000 15:33:22 +0200
From: Sigvald Refsum <sigvald.refsum@siemens.no>
Subject: Re: Email Attachments using OLE MAPI.Session on NT
Message-Id: <3916C222.E0FD4BE0@siemens.no>
Hi Arkadi
I have an outlook script which works with attachments. I have
included all the options I hva got to work.
The script is far from perfect and is only ment te demonstrate
functionallity,
any syntaxt can be wrong.
Hope this helps
Sigvald Refsum
Script for Outlook follows:
############################
use Win32::OLE qw(in with);
my $OutLook = Win32::OLE->new('Outlook.Application.8')
or die "Couldn't connect to Outlook";
my $NewMail;
# Create Mail object
$NewMail = $OutLook->CreateItem(0);
# Address Mail Object, can be repeated for several recipients
$NewMail->Recipients->Add('sigvald');
# CC Address Mail Object, can be repeated for several recipients
$NewMail->Recipients->Add('sigvald');
$NewMail->Recipients->Item('sigvald')->{Type} = 2;
# Resolve addresses
$NewMail->Recipients->ResolveAll();
# Categories string
$NewMail->{Categories} ="PVCS operation";
# Voting option string
$NewMail->{VotingOptions} ="Pizza;Salat;China";
# Originator Delivery Report Requested
$NewMail->{OriginatorDeliveryReportRequested} = 1;
# Subject string
$NewMail->{Subject} ="hei";
# Body
$NewMail->{Body} = "kåre heisan\n";
#Attachments
$NewMail->Attachments->Add('H:\C_wrk\parser\outlookSend.pl');
# Print
# $NewMail->PrintOut();
# Reminder
my $hour = (16 * 3600)*(1/86400);
my $minute = (20 * 60)*(1/86400);
$NewMail->{FlagDueBy} = 36538+$hour+$minute;
$NewMail->{FlagRequest} = 'Review Tue 13.01.00 16:20';
# Away it goes
$NewMail->Send;
# Quit
$OutLook->Close();
------------------------------
Date: Mon, 08 May 2000 17:28:22 GMT
From: "Veronica Adams" <adams1015@worldnet.att.net>
Subject: file permisions- setuid?
Message-Id: <WOCR4.44102$PV.3022606@bgtnsc06-news.ops.worldnet.att.net>
I have a function that needs to write to a file(called from a browser as as
cgi script). I do not want to leave the file permission 0777 (the function
also needs to read). I need to change the permission for the duration of the
function call. I trided just chmod in the function but evidently the host
will not allow me to do this.
Will setuid do what I need to do? If so how do I use it? WHat is it? Where
can I find documentation?
I looked for it in the faqs and documentation with active perl but cannot
find it anywhere.
thanks
------------------------------
Date: Mon, 8 May 2000 14:29:02 +0200
From: Joachim Pimiskern <Joachim.Pimiskern@de.bosch.com>
Subject: Re: Getting the platform on which Perl is running
Message-Id: <8f6bue$mno$1@proxy2.fe.internet.bosch.de>
$^O
------------------------------
Date: Mon, 08 May 2000 13:35:59 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Getting the platform on which Perl is running
Message-Id: <3916c13c.21214946@news.skynet.be>
Ilja wrote:
>> Does anybody know if there is a way (a standard function or some
>> predefined variable) to ask Perl on what platform it is running?
>The $^O variable ($OSNAME if you use English) contains the operating system
>that your perl binary was built for.
"was *built* for". It does not say waht OS it is actually running on,
which is a major limitation. Well... it's not a limitation on Unixy
platforms, where people always compile their own programs. But on
Windows, you cannot distinuish between Window 95 or NT4, for example.
All it says, is "Win95".
What you could do on Windows, is use the Win32::API module, and using
the GetVersion or GetVersionEx API calls, you can get details of what
platform the script is running on.
--
Bart.
------------------------------
Date: Mon, 08 May 2000 08:35:29 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Getting the platform on which Perl is running
Message-Id: <3916C2A1.20933954@home.com>
Hans Scholte wrote:
>
> Does anybody know if there is a way (a standard function or some
> predefined variable) to ask Perl on what platform it is running?
Type 'perldoc perlvar' at your command prompt for a list of all the
built-in variables and what they mean. The one you want is $^O ($OSNAME
under 'use English').
-mjc
------------------------------
Date: Sun, 07 May 2000 22:52:41 -0400
From: Kerry Shetline <kerry@shetline.com>
Subject: Re: Getting variables from html
Message-Id: <39162BF9.1595F971@shetline.com>
Jason Malone wrote:
>
> I have done this before but I can't find my code anywhere. I can't remember
> how I get the variables from an http request i.e. when a user clicks on a
> link (www.whatever.com/cgi-bin/test.pl?var1=value&var2=value2....) Is this a
> get or a post or neither.
>
> Can someone give me a snippet of code that will grap these variables into
> the script?
This handles both GET and POST:
sub getFormData
{
unless (defined($getFormData_initflag)) {
$getFormData_initflag = 1;
my $pairs;
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
my $buffer;
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
return undef;
}
my ($pair, $key, $value);
foreach $pair (@pairs) {
($key, $value) = split(/=/, $pair);
$key = unescape($key);
$value = unescape($value);
$value =~ s/<!--(.|\n)*-->//g;
$getFormData_formdata{$key} = $value;
}
}
return $getFormData_formdata{$_[0]};
}
sub unescape
{
my @out = @_;
for (@out) {
tr/+/ /;
s/%([a-fA-F0-9][a-fA-F0-9])/ pack("C", hex($1))/eg;
}
return wantarray ? @out : $out[0];
}
-Kerry
----------------------------------------------------------------------
See the stars (and Sun, and Moon, and planets) at the Sky View Cafe...
http://www.shetline.com/skyview.html
----------------------------------------------------------------------
------------------------------
Date: 08 May 2000 11:28:45 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Getting variables from html
Message-Id: <87vh0povk2.fsf@shleppie.uh.edu>
[ removed comp.lang.perl since it doesn't exist ]
>> On Sun, 07 May 2000 22:52:41 -0400,
>> Kerry Shetline <kerry@shetline.com> said:
> This handles both GET and POST:
but the POST handler introduces a security hole:
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
How big is $ENV{CONTENT_LENGTH} ?
The CGI.pm module does all of this without introducing
these explicit and buggy parse routines into your code and
can restrict upload data sizes easily. A single line
saying "use CGI;" lets you get on with solving your real
problem.
perldoc CGI
for more info about the CGI module.
hth
t
------------------------------
Date: Mon, 08 May 2000 16:41:08 GMT
From: Kerry Shetline <kerry@shetline.com>
Subject: Re: Getting variables from html
Message-Id: <8f6qn2$gln$1@nnrp1.deja.com>
Jason Malone wrote:
>
> I have done this before but I can't find my code anywhere. I can't remember
> how I get the variables from an http request i.e. when a user clicks on a
> link (www.whatever.com/cgi-bin/test.pl?var1=value&var2=value2....) Is this a
> get or a post or neither.
>
> Can someone give me a snippet of code that will grap these variables into
> the script?
This handles both GET and POST:
sub getFormData
{
unless (defined($getFormData_initflag)) {
$getFormData_initflag = 1;
my $pairs;
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
my $buffer;
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
return undef;
}
my ($pair, $key, $value);
foreach $pair (@pairs) {
($key, $value) = split(/=/, $pair);
$key = unescape($key);
$value = unescape($value);
$value =~ s/<!--(.|\n)*-->//g;
$getFormData_formdata{$key} = $value;
}
}
return $getFormData_formdata{$_[0]};
}
sub unescape
{
my @out = @_;
for (@out) {
tr/+/ /;
s/%([a-fA-F0-9][a-fA-F0-9])/ pack("C", hex($1))/eg;
}
return wantarray ? @out : $out[0];
}
-Kerry
[PS: My apologies if this message is repeated when my ISP fixes it's news
server!]
-----------------------------------------------------------------------
See the stars (and Sun, and Moon, and planets) at the Sky View Cafe...
http://www.shetline.com/skyview.html
-----------------------------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 8 May 2000 19:41:12 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Getting variables from html
Message-Id: <Pine.GHP.4.21.0005081925070.3709-100000@hpplus01.cern.ch>
[obsolete group comp.lang.perl removed]
On Mon, 8 May 2000, Kerry Shetline wrote:
> Jason Malone wrote:
[..]
> > how I get the variables from an http request i.e. when a user clicks on a
> > link (www.whatever.com/cgi-bin/test.pl?var1=value&var2=value2....) Is this a
> > get or a post or neither.
That's a "GET", but the correct HTML coding for the link is
HREF="http://www.whatever.com/cgi-bin/test.pl?var1=value&var2=value2...."
^^^^^^^ ^^^^^
> > Can someone give me a snippet of code that will grap these variables into
> > the script?
CGI.pm
> This handles both GET and POST:
So does CGI.pm, it's a standard part of any reasonably current Perl
installation.
> sub getFormData
[snippage]
> elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
> my $buffer;
> read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
It might not be wise to read in arbitrary quantities of content
without futher thought... (and then there's the question of binmode,
and different submission codings, and all).
[much more hand-knitting omitted]
> $value =~ s/<!--(.|\n)*-->//g;
Hello, where did that piece of cargo crawl in from?
CGI.pm has years of expertise behind it, it's been peer reviewed, if
there are any bugs left they're likely to get fixed, unlike your stuff
which I've only fleetingly reviewed and could well contain anomalies
that I've missed.
Any programmer worth their salt should be able to code the functions
that are contained in it, as an exercise, _and_ know why using those
exercises as production code is probably a bad idea. That's my
advice, anyway.
> [PS: My apologies if this message is repeated when my ISP fixes it's news
> server!]
Oh, it's its, not it's.
> -----------------------------------------------------------------------
> See the stars (and Sun, and Moon, and planets) at the Sky View Cafe...
A proper sig separator wouldn't come amiss.
> Before you buy.
--
Partake of distilled wisdom of Usenet - read the FAQs.
Before you ask.
- and before you answer, too!
------------------------------
Date: 08 May 2000 17:44:02 +0100
From: nobull@mail.com
Subject: Re: How single-line switch (/s) works in regexps?
Message-Id: <u9bt2hgffx.fsf@wcl-l.bham.ac.uk>
Peter Hill <phill@modulus.com.au> writes:
> nobull@mail.com wrote:
> > >
> > > > Given a prefix of string and a pattern is it possible to test if is
> > > > necessary to read in more to know if (or what) the pattern will match
> > > > in that prefix.
> > > >
> > > > eg.
> > > >
> > > > ("foo" . $unread) =~ /f/ # Matches
> > > > ("foo" . $unread) =~ /o+/ # Matches but we dont know how many
> > > > ("foo" . $unread) =~ /od/ # Don't know if is maches
> > > > ("foo" . $unread) =~ /d/ # Doesn't match
> My turn for density; isn't that ^^^^^^^^^^^^^ #Don't (yet) know if
> it matches?
> Or do you mean something different when you said "match in that prefix"
> :- but no, that would invalidate your conclusions for results 2 and 3.
> Just curious.
When I say "match in that prefix" I mean "region of the complete
string matched by the pattern starts before the end of the prefix".
We know the pattern /d/ will never match in the first 3 characters of
any string starting "foo".
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 08 May 2000 16:54:57 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: how to clear a @list ... ?
Message-Id: <3916E351.A63BB088@bmjgroup.com>
dear all,
simple one! I should know this by now. cant find documentation with
examples... All I want to do is clear a list @lines_in within a loop
that reads in modifies and outputs each file in a dir. Ive got it all
working except each new file is kept in the list. I want to clear it
before reading in the next/new file.
so how do i do this (clear @list) ? How do I also reset a $var that I
might have used before?
thanking you in advance and for your kind attention,
Kourosh A Mojar
kmojar@bmjgroup.com
------------------------------
Date: Mon, 08 May 2000 15:52:40 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: how to clear a @list ... ?
Message-Id: <391ee2a5.29768361@news.skynet.be>
Kourosh A Mojar wrote:
>so how do i do this (clear @list)
undef @list;
or
@list = ();
D'uh...!
--
Bart.
------------------------------
Date: Mon, 8 May 2000 18:05:57 +0200
From: Joachim Pimiskern <Joachim.Pimiskern@de.bosch.com>
Subject: Re: how to clear a @list ... ?
Message-Id: <8f6ol8$6r4$1@proxy2.fe.internet.bosch.de>
Hi Kourosh,
Kourosh A Mojar schrieb in Nachricht <3916E351.A63BB088@bmjgroup.com>...
>so how do i do this (clear @list) ? How do I also reset a $var that I
>might have used before?
probably you know the Lisp or Pascal value nil or the C nullpointer.
The Perl pendant to this is undef (for scalar values).
$var = undef;
To clear a list, use $list = ();
Note that in array context a list variable set to undef
returns (undef), a list containing one element
which has the value undef.
Regards,
Joachim
--
When in doubt, remove the enemy stones from the board.
(Go proverb)
------------------------------
Date: 08 May 2000 17:40:03 +0100
From: nobull@mail.com
Subject: Re: how to clear a @list ... ?
Message-Id: <u9em7dgfmk.fsf@wcl-l.bham.ac.uk>
Kourosh A Mojar <kmojar@bmjgroup.com> writes:
> simple one! I should know this by now. cant find documentation with
> examples... All I want to do is clear a list @lines_in within a loop
> that reads in modifies and outputs each file in a dir. Ive got it all
> working except each new file is kept in the list. I want to clear it
> before reading in the next/new file.
>
> so how do i do this (clear @list) ? How do I also reset a $var that I
> might have used before?
If you declare all variables with the right scope and you rarely need
to explicitly clear them.
To explicitly undefine a variable use the undef() function.
You can also clear a list or hash by assigning the empty list value or
a scalar by assigning the undef value.
See also answers given to this question when it was asked last week,
and the week before (and probably the week before that).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 08 May 2000 10:30:49 -0400
From: William Cardwell <EUSWMCL@am1.ericsson.se>
Subject: How to make a grep utility for Win32
Message-Id: <3916CF99.CDCA458F@am1.ericsson.se>
I am trying to write a Perl utility to behave similar to grep for use on
WIN32. I have tried lots of things including a search for one-liners and
use of the perl grep function, but can't get very close.
Any suggestions?
Here's my latest approach:
File "test.pl":
#
-----------------------------------------------------------------------------------------------------
# This doesn't work for command: perl test.pl "/e/" * or any of many
variations
# to print all lines containing "e" in current directory
#
$pat=shift; # pattern
for(@ARGV) {
while (<>) {
if ($pat) { # Can't get pattern arg to substitute correctly here
if ($ARGV ne $ARGVSAVE) {print "\n";} # ensure new line for new
file (Is there a better way?)
print "$ARGV: $_";
$ARGVSAVE=$ARGV;
}
}
}
#
-----------------------------------------------------------------------------------------------------
Thank you,
Will Cardwell
------------------------------
Date: Mon, 08 May 2000 15:21:30 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: How to make a grep utility for Win32
Message-Id: <391ad910.27314971@news.skynet.be>
William Cardwell wrote:
>I am trying to write a Perl utility to behave similar to grep for use on
>WIN32. I have tried lots of things including a search for one-liners and
>use of the perl grep function, but can't get very close.
>
>Any suggestions?
Use a precompiled grep program. :-) There must be several of those
available, for example at Winsite. Google found this page for me:
<http://www.interlog.com/~tcharron/grep.html>
Otherwise, have you checked the Perl Power Tools page? See:
<http://language.perl.com/ppt/src/grep/>
--
Bart.
------------------------------
Date: Mon, 08 May 2000 15:39:36 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to make a grep utility for Win32
Message-Id: <YcBR4.629$Kc1.49442@news.dircon.co.uk>
On Mon, 08 May 2000 10:30:49 -0400, William Cardwell Wrote:
> I am trying to write a Perl utility to behave similar to grep for use on
> WIN32. I have tried lots of things including a search for one-liners and
> use of the perl grep function, but can't get very close.
>
> Any suggestions?
<http://language.perl.com/ppt/src/grep/index.html>
/J\
------------------------------
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 2977
**************************************