[23381] in Perl-Users-Digest
Perl-Users Digest, Issue: 5600 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 1 18:10:39 2003
Date: Wed, 1 Oct 2003 15:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 1 Oct 2003 Volume: 10 Number: 5600
Today's topics:
Perl CGI executing command line functions (Nick)
Re: Perl CGI executing command line functions <mbudash@sonic.net>
Re: Perl CGI executing command line functions <nospam@bigpond.com>
Re: Perl CGI executing command line functions <noreply@gunnar.cc>
regex behavior <mpapec@yahoo.com>
Re: regex behavior <abigail@abigail.nl>
Re: Saving html form into oracle database <emschwar@pobox.com>
select() on socket (Vorxion)
The answer you want! <nospam@bigpond.com>
Re: UserAgent's Max_Size and HTTP's header field Range (laura fairhead)
Working with a line of text ??? <NoSpamPlease@bellsouth.net>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Oct 2003 14:07:57 -0700
From: kvetchv@yahoo.com (Nick)
Subject: Perl CGI executing command line functions
Message-Id: <3eb8c8ea.0310011307.6f17ae73@posting.google.com>
I am just starting out with Perl and am trying to figure out how to
setup a CGI script to perform some command line functions. I work
with some people that need to run some command line functions but we
do not want to give them command line access. I thought that if I
write a Perl CGI script that executes some of the commands for them,
it would solve our problems.
I have found tons of examples and tutorials that show you how to get a
Perl CGI to write to files, display HTML pages and print lines. What
is the correct syntax for backticks in Perl? My goal was to give them
allow
them access to some HTML pages with some forms where they enter the
options for certain commands.
For example, if I had this as my HTML form and the user entered "-al"
<form action="dosomething.cgi" method="GET">
Enter an #ls option: <input type="text" name="commd" size=30><p>
<input type="submit">
</form>
How would I get Perl to run that #ls command with the user's option
values (#ls -al) and display the end result of that command?
Would it be something similar to
`ls` $commd;
How would I show the end result?
Thanks in advance,
Nick
------------------------------
Date: Wed, 01 Oct 2003 21:24:25 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Perl CGI executing command line functions
Message-Id: <mbudash-00DE11.14242401102003@typhoon.sonic.net>
In article <3eb8c8ea.0310011307.6f17ae73@posting.google.com>,
kvetchv@yahoo.com (Nick) wrote:
> I am just starting out with Perl and am trying to figure out how to
> setup a CGI script to perform some command line functions. I work
> with some people that need to run some command line functions but we
> do not want to give them command line access. I thought that if I
> write a Perl CGI script that executes some of the commands for them,
> it would solve our problems.
>
> I have found tons of examples and tutorials that show you how to get a
> Perl CGI to write to files, display HTML pages and print lines. What
> is the correct syntax for backticks in Perl? My goal was to give them
> allow
> them access to some HTML pages with some forms where they enter the
> options for certain commands.
>
> For example, if I had this as my HTML form and the user entered "-al"
> <form action="dosomething.cgi" method="GET">
> Enter an #ls option: <input type="text" name="commd" size=30><p>
> <input type="submit">
> </form>
>
> How would I get Perl to run that #ls command with the user's option
> values (#ls -al) and display the end result of that command?
> Would it be something similar to
> `ls` $commd;
> How would I show the end result?
>
> Thanks in advance,
> Nick
the most naive way would be this:
#----------------------------------------
#!perl -w
use strict;
use CGI qw/:standard/;
$|++;
print header();
my $commd = param('commd');
print `ls $commd`;
#----------------------------------------
however... think of what would happen if the user entered "; rm -fr *.*"
!!!!!!!
you might wanna constrain what is allowable...
--
Michael Budash
------------------------------
Date: Thu, 02 Oct 2003 07:26:37 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Perl CGI executing command line functions
Message-Id: <1211198.pjaMW0z05n@gregs-web-hosting-and-pickle-farming>
It was a dark and stormy night, and Nick managed to scribble:
> I am just starting out with Perl and am trying to figure out how to
> setup a CGI script to perform some command line functions. I work
> with some people that need to run some command line functions but we
> do not want to give them command line access. I thought that if I
> write a Perl CGI script that executes some of the commands for them,
> it would solve our problems.
Use the 'system' command. You will probably nned fully qualified paths if you use CGI.
gtoomey
------------------------------
Date: Wed, 01 Oct 2003 23:31:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl CGI executing command line functions
Message-Id: <blfh4d$bgeu8$1@ID-184292.news.uni-berlin.de>
Nick wrote:
> I work with some people that need to run some command line
> functions but we do not want to give them command line access. I
> thought that if I write a Perl CGI script that executes some of the
> commands for them, it would solve our problems.
*Some* of the commands? Do they have access to upload and run their
own CGI scripts? In that case, what prevents them from uploading a
script and executing *any* system command?
Just a thought.
> For example, if I had this as my HTML form and the user entered
> "-al"
> <form action="dosomething.cgi" method="GET">
> Enter an #ls option: <input type="text" name="commd" size=30><p>
> <input type="submit">
> </form>
>
> How would I get Perl to run that #ls command with the user's option
> values (#ls -al) and display the end result of that command?
> Would it be something similar to
> `ls` $commd;
> How would I show the end result?
An example:
$result = `ls $commd 2>&1`;
The '2>&1' part makes it capture also possible error messages in $result.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 01 Oct 2003 22:20:31 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: regex behavior
Message-Id: <4bdmnvcb9or2nbm2ne1euvhqp1e64s84g7@4ax.com>
I went through perldoc but didn't found similar regex,
print join ',', 'a bb ccc dddd' =~ /(\w)+/g;
the question is, what it exactly matches and why?
--
Matija
------------------------------
Date: 01 Oct 2003 20:52:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regex behavior
Message-Id: <slrnbnmfk7.tun.abigail@alexandra.abigail.nl>
Matija Papec (mpapec@yahoo.com) wrote on MMMDCLXXXIII September MCMXCIII
in <URL:news:4bdmnvcb9or2nbm2ne1euvhqp1e64s84g7@4ax.com>:
--
-- I went through perldoc but didn't found similar regex,
-- print join ',', 'a bb ccc dddd' =~ /(\w)+/g;
--
-- the question is, what it exactly matches and why?
/(\w)+/ matches a set of consecutive word characters, capturing
the *last* one. //g in list context means, do this as often as
possible (without overlap), returning a list of each of the submatches.
So, 'a bb ccc dddd' =~ /(\w)+/g; returns for each substring of
consecutive word characters the last one, resulting in 'a', 'b', 'c' and 'd'.
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
Date: Wed, 01 Oct 2003 15:50:03 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Saving html form into oracle database
Message-Id: <eton0ckbpbo.fsf@wormtongue.emschwar>
Michael Budash <mbudash@sonic.net> writes:
> In article <3db2b381.0310010704.665891ad@posting.google.com>,
> nick77074@hotmail.com (Nick) wrote:
>> I'm new to perl programming. Just wanted to know if there is a way I
>> could save the whole HTML FORM into database rather then saving it by
>> individual fields.
>> Someone mentioned it to me that it can be done. I just don't know how
>> to do it.
One approach is to save off the form parameters into a hash, and stuff
the hash into a BLOB with Data::Dumper or Storable or some such module.
> the problem i see is that a cgi script is not delivered a form, it's
> delivered the names/values _in_ a form when that form was submitted. one
> possibility: have your form handler read in the static html file
> containing the form, fill it in, and save it to your db in a blob field
> (ugh!)
Ick. Just save the form parameters and values, and use CGI.pm to
re-create the form along with the values you loaded from the
database. Why make things so needlessly complicated?
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 1 Oct 2003 15:54:03 -0400
From: vorxion@fairlite.com (Vorxion)
Subject: select() on socket
Message-Id: <3f7b30db$1_1@news.iglou.com>
I'm having a problem with select() on a socket. I'm setting the bits, and
it's really strange, because even when there's -nothing- to be read,
vec($rout,fileno(DATA) comes back as 0 instead of 1. The bits come back
0 1 0 in order of $rout $wout $eout.
Okay, so exactly how do you tell when the remote end is sitting there with
nothing to say? I've used select(2) in C, and there appears to be no ready
equivalent of FD_ISSET() in perl.
If someone can tell me how to do this properly, or what I'm doing wrong (I'm
checking for $rout to be set back to 0 (via vec) after the select(). It was
working this morning with one set of test conditions, but now it isn't with
another set of test conditions. Now it always comes back 0, which can't
be right, unless I'm doing something wrong due to underdocumentation.
# Set flags for select().
$rin = $win = $rout = $wout = $ein = $eout = '';
vec($rin,fileno(DATA),1) = 1;
vec($win,fileno(DATA),1) = 1;
$ein = ${rin} | ${win};
# Actually check our socket for data.
print("BEFORE SELECT\n") if ${debug};
select($rout=$rin,$wout=$win,$eout=$ein,${timeout_select});
print("PAST SELECT\n") if ${debug};
print("TIMEOUT AND rVEC: ${timeout} ", vec(${rout},fileno(DATA),1),"\n");
print("TIMEOUT AND wVEC: ${timeout} ", vec(${wout},fileno(DATA),1),"\n");
print("TIMEOUT AND eVEC: ${timeout} ", vec(${eout},fileno(DATA),1),"\n");
Basically, I need to know when there is data waiting for me, and when there is
no data waiting for me. I -thought- checking for $rout to be 0 via vec() was
the way you emulate FD_ISSET, but I must be mistaken.
Help? :)
--
Vorxion - Member of The Vortexa Elite
------------------------------
Date: Thu, 02 Oct 2003 07:19:43 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: The answer you want!
Message-Id: <2014548.gW3vXJVmvC@gregs-web-hosting-and-pickle-farming>
It was a dark and stormy night, and Chris Smith managed to scribble:
> Hi,
>
> Anyone know where to get an English dictionary word list in flat text
> format without definitions?
>
> I'm going to use the wordlist as test data for something rather large.
>
> Preferably British English but any English will do as it's only test data.
>
> Thanks,
>
Probably the best lists are at http://wordlist.sourceforge.net/
I use SCOWL, which has about 700,000 words in the combined lists.
I use this to help my mother solve word puzzles in magazines, and I can run a regular expression over 700,000 words in under 5 seconds.
gtoomey
------------------------------
Date: Wed, 01 Oct 2003 20:05:24 GMT
From: run_signature_script_for_my_email@INVALID.com (laura fairhead)
Subject: Re: UserAgent's Max_Size and HTTP's header field Range
Message-Id: <3f7b2d8d.52042953@NEWS.CIS.DFN.DE>
On 1 Oct 2003 08:38:17 -0700, deals@slip-12-64-108-121.mis.prserv.net (Great Deals) wrote:
>Here is my code:
>#!/usr/bin/perl
> use Net::HTTP;
> use LWP::UserAgent;
>
> $ua = LWP::UserAgent->new (agent => 'Mozilla/4.0', );
> $ua->max_size(2000);
> $url = 'http://news.google.com'; # for instance, no trailing /
>
> $htmlcode = $ua->get($url, Range => 'bytes=1000-')->content;
> print $htmlcode;
>
>#################
>First of all, if I put 2000 or 1000 or 750 in max_size, the result is
>the same, I don't know why, but if I put 400 there, the downloaded is
>much smaller.
>
>Secondly, Range => 'bytes=1000-' does not seem to work. I only want to
>fetch the middle part of the page, not from the beginning. How could I
>do that?
Your response from google should have a "Accept-Ranges:" header
so it just doesn;'t support ranges.
There is nothing you can do about this; if the server doesn't support
ranges it won't serve parts of files to you, in that case all you can
do is download the entire file each time and then splice out the part
that you actually wanted. That should be easy but there's no way around
having to waster the time downloading the first bit if the server
doesn't support ranges... It would be theoretically possible to cut
the download short if you didn;t want data at the end of a file by
simply aborting the connection but not from the start.
seeyafrom
l
>
>Here is the header I sent via nettransport
>2003-10-01 11:35:38.713 Connecting to news.google.com:80
>2003-10-01 11:35:38.713 Connecting to 216.239.33.104:80
>2003-10-01 11:35:38.963 Connected
>2003-10-01 11:35:38.963 GET / HTTP/1.1
>2003-10-01 11:35:38.963 Host: news.google.com
>2003-10-01 11:35:38.963 Referer: http://news.google.com
>2003-10-01 11:35:38.963 Accept: */*
>2003-10-01 11:35:38.963 User-Agent: Mozilla/4.0
>2003-10-01 11:35:38.963 Range: bytes=12485-
>2003-10-01 11:35:38.963 Connection: close
>
>Here is the header file which google gave me when I use net-transport:
>
>2003-10-01 11:35:40.085 HTTP/1.1 200 OK
>2003-10-01 11:35:40.085 Date: Wed, 01 Oct 2003 15:35:38 GMT
>2003-10-01 11:35:40.085 Server: GWS/2.1
>2003-10-01 11:35:40.085 Content-length: 67700
>2003-10-01 11:35:40.085 Cache-control: no-cache, must-revalidate
>2003-10-01 11:35:40.085 Expires: Fri, 01 Jan 1990 00:00:00 GMT
>2003-10-01 11:35:40.085 Pragma: no-cache
>2003-10-01 11:35:40.085 Last-Modified: Wed, 01 Oct 2003 15:30:28 GMT
>2003-10-01 11:35:40.085 Content-Type: text/html
--
echo alru_aafriehdab@ittnreen.tocm |sed 's/\(.\)\(.\)/\2\1/g'
------------------------------
Date: Wed, 1 Oct 2003 17:30:46 -0400
From: "Rodney" <NoSpamPlease@bellsouth.net>
Subject: Working with a line of text ???
Message-Id: <UEHeb.208$wC1.197@bignews3.bellsouth.net>
I have a situation where I want to send portions of a line of text to a
subroutine for processing. The text line could look like this:
blah blah <!--Start-- blah blah blah--End--> blah blah blah <!--Start-- blah
blah--End--> blah blah blah.
I only want to send the text that is NOT within the <!--Start-- and --End-->
tags. So example above would have 3 pieces of text the need to run through
the subroutine.
After they go through the subroutine, the line of text needs to be regrouped
in the same order it was before it was processed and the "Tags" have to be
in tact.
I've tried "splitting" the line and working with the array elements.... but
this process seems to take a VERY long time.
see example below:
#==================================================start
sub AddKeyWordsAndNumericConst {
my ($TextBlockToConvert) = @_;
my $TextBlockToConvert2 = "";
my $TextBlockToConvert3 = "";
### beginning tag looks like this: <!-- Quoted Text Start QTS-->
@CodeBreakApart = split(/<!-- Quoted Text Start /,
$TextBlockToConvert) ;
for($ArrayTicker3=0; $ArrayTicker3 < @CodeBreakApart; $ArrayTicker3++)
{
$CodeBreakTest = $CodeBreakApart[$ArrayTicker3];
if (not($CodeBreakTest =~ m/QTS-->/g)) {
$CodeBreakTest = &OpalNumberConstants($CodeBreakTest);
$CodeBreakTest = &OpalKeywords($CodeBreakTest);
$CodeBreakApart[$ArrayTicker3] = $CodeBreakTest;
$CodeBreakTest = "";
$TextBlockToConvert2 =
$TextBlockToConvert2.$CodeBreakApart[$ArrayTicker3];
}
else {
$CodeBreakTest = "<!-- Quoted Text Start ".$CodeBreakTest;
$CodeBreakApart[$ArrayTicker3] = $CodeBreakTest;
$CodeBreakTest = "";
$TextBlockToConvert2 =
$TextBlockToConvert2.$CodeBreakApart[$ArrayTicker3];
}
}
### end tag looks like this: <!-- Quoted Text End QTE-->
@CodeBreakApart2 = split(/QTE-->/, $TextBlockToConvert2) ;
for($ArrayTicker4=0; $ArrayTicker4 < @CodeBreakApart2; $ArrayTicker4++)
{
$CodeBreakTest2 = $CodeBreakApart2[$ArrayTicker4];
if (not($CodeBreakTest2 =~ m/<!-- Quoted Text End /g)) {
$CodeBreakTest2 = &OpalNumberConstants($CodeBreakTest2);
$CodeBreakTest2 = &OpalKeywords($CodeBreakTest2);
$CodeBreakApart2[$ArrayTicker4] = $CodeBreakTest2;
$CodeBreakTest2 = "";
$TextBlockToConvert3 =
$TextBlockToConvert2.$CodeBreakApart2[$ArrayTicker4];
}
else {
$CodeBreakTest2 = $CodeBreakTest2."QTE-->";
$CodeBreakApart2[$ArrayTicker4] = $CodeBreakTest2;
$CodeBreakTest2 = "";
$TextBlockToConvert3 =
$TextBlockToConvert2.$CodeBreakApart2[$ArrayTicker4];
}
}
return $TextBlockToConvert3;
}
#===============================================end
My question is:
1) Is there a RegEx statement that would do this.... only faster?
2. If not, is there a way to make the above process faster?
Thanks
--
...
`·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5600
***************************************