[22228] in Perl-Users-Digest
Perl-Users Digest, Issue: 4449 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 22 18:10:49 2003
Date: Wed, 22 Jan 2003 15:10:15 -0800 (PST)
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, 22 Jan 2003 Volume: 10 Number: 4449
Today's topics:
Re: Pattern Matching <espenmyr@start.no.cretinfilter>
Re: Pattern Matching <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: Pattern Matching <penny1482@attbi.com>
Re: Pattern Matching (David James)
Re: Pattern Matching (Anno Siegel)
Re: Pattern Matching (Anno Siegel)
Please Help Me <kttran@nortelnetworks.com>
Re: Please Help Me (Mark)
Problem printing January "The Perl Journal" (Justin Masters - remove at to reply)
Quick Perl Question (Kamal)
Re: Quick Perl Question <twhu@lucent.com>
Re: Regex: optional word boundary (Sara)
Re: Regex: optional word boundary (Tad McClellan)
Security with uploaded zip files (Mark)
Re: Security with uploaded zip files <mthunter@students.uiuc.edu>
Re: Security with uploaded zip files <flavell@mail.cern.ch>
Re: Security with uploaded zip files (Tad McClellan)
Re: Security with uploaded zip files (Jay Tilton)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Jan 2003 17:05:03 +0100
From: Espen Myrland <espenmyr@start.no.cretinfilter>
Subject: Re: Pattern Matching
Message-Id: <878yxd5fww.fsf@chello.no>
gabsaga_tata@hotmail.com (Taji) writes:
> I'm getting certain numbers in a process and if the number is one of
> the numbers as shown below (separated with pipes), then I want to do
> something but the pattern matching doesn't seem to be working
> properly. Any ideas?
>
> my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
>
> my $number = 12 ;
>
> if ( $numbers =~ /$number/ ) {
> print "Number found\n" ;
> } else {
> print "Number not found\n" ;
> }
Thats because 12 matches 126, for instance.
Suggestion:
my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
my @nums = split(/\|/, $numbers);
my $number = 12 ;
if ( my $n = grep /^$number$/, @nums ) {
print "Number found\n" ;
}
else {
print "Number not found\n" ;
}
But you could also make a cooler regex,
--
espen
------------------------------
Date: Wed, 22 Jan 2003 16:10:34 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: Pattern Matching
Message-Id: <b0mg68$a68$1@pheidippides.axion.bt.co.uk>
"Taji" <gabsaga_tata@hotmail.com> wrote in message
news:15619060.0301220755.3ed84f24@posting.google.com...
> I'm getting certain numbers in a process and if the number is one of
> the numbers as shown below (separated with pipes), then I want to do
> something but the pattern matching doesn't seem to be working
> properly. Any ideas?
>
> my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
>
> my $number = 12 ;
>
> if ( $numbers =~ /$number/ ) {
> print "Number found\n" ;
> } else {
> print "Number not found\n" ;
> }
Swap round $numbers and $number in the pattern match. This works because the
pipe symbol acts as an 'alternates' selector in a regular expression.
my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
my $number = 12 ;
if ( $number =~ /$numbers/ ) {
print "Number found\n" ;
} else {
print "Number not found\n" ;
}
------------------------------
Date: Wed, 22 Jan 2003 18:14:03 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: Pattern Matching
Message-Id: <LbBX9.46842$4u5.40498@rwcrnsc52.ops.asp.att.net>
BRILLANT suggestion. Way out of the box.
Dick Penny
"Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message
news:b0mg68$a68$1@pheidippides.axion.bt.co.uk...
>
> "Taji" <gabsaga_tata@hotmail.com> wrote in message
> news:15619060.0301220755.3ed84f24@posting.google.com...
> > I'm getting certain numbers in a process and if the number is one of
> > the numbers as shown below (separated with pipes), then I want to do
> > something but the pattern matching doesn't seem to be working
> > properly. Any ideas?
> >
> > my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
> >
> > my $number = 12 ;
> >
> > if ( $numbers =~ /$number/ ) {
> > print "Number found\n" ;
> > } else {
> > print "Number not found\n" ;
> > }
>
>
> Swap round $numbers and $number in the pattern match. This works because
the
> pipe symbol acts as an 'alternates' selector in a regular expression.
>
>
> my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
>
> my $number = 12 ;
>
> if ( $number =~ /$numbers/ ) {
> print "Number found\n" ;
> } else {
> print "Number not found\n" ;
> }
>
>
>
------------------------------
Date: 22 Jan 2003 10:55:36 -0800
From: moneran@hotmail.com (David James)
Subject: Re: Pattern Matching
Message-Id: <ce0257d.0301221055.192a860f@posting.google.com>
Instead of "if ( $numbers =~ /$number/ )", put "if ( $number =~ /$numbers/ )"
gabsaga_tata@hotmail.com (Taji) wrote in message news:<15619060.0301220755.3ed84f24@posting.google.com>...
> I'm getting certain numbers in a process and if the number is one of
> the numbers as shown below (separated with pipes), then I want to do
> something but the pattern matching doesn't seem to be working
> properly. Any ideas?
>
> my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
>
> my $number = 12 ;
>
> if ( $numbers =~ /$number/ ) {
> print "Number found\n" ;
> } else {
> print "Number not found\n" ;
> }
------------------------------
Date: 22 Jan 2003 20:13:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pattern Matching
Message-Id: <b0mu0s$b63$1@mamenchi.zrz.TU-Berlin.DE>
[Dick Penny's TOFU rearranged]
Dick Penny <penny1482@attbi.com> wrote in comp.lang.perl.misc:
> Dick Penny
> "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message
> news:b0mg68$a68$1@pheidippides.axion.bt.co.uk...
> >
> > "Taji" <gabsaga_tata@hotmail.com> wrote in message
> > news:15619060.0301220755.3ed84f24@posting.google.com...
> > > I'm getting certain numbers in a process and if the number is one of
> > > the numbers as shown below (separated with pipes), then I want to do
> > > something but the pattern matching doesn't seem to be working
> > > properly. Any ideas?
> > >
> > > my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
> > >
> > > my $number = 12 ;
> > >
> > > if ( $numbers =~ /$number/ ) {
> > > print "Number found\n" ;
> > > } else {
> > > print "Number not found\n" ;
> > > }
> >
> >
> > Swap round $numbers and $number in the pattern match. This works because
> the
> > pipe symbol acts as an 'alternates' selector in a regular expression.
> >
> >
> > my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
> >
> > my $number = 12 ;
> >
> > if ( $number =~ /$numbers/ ) {
> > print "Number found\n" ;
> > } else {
> > print "Number not found\n" ;
> > }
> >
> BRILLANT suggestion. Way out of the box.
Well, it does have a problem. The number 12 (used in the example code)
will match while it shouldn't, as will all numbers that happen to be
substrings of one of the given numbers. One solution is to anchor
the regex left and right:
if ( $number =~ /^(?:$numbers)$/ ) {
However, a regex may not be the best solution. The standard solution
in Perl would use a hash, but solutions using arrays (and even vec())
are also possible. See other parts of the thread.
Anno
------------------------------
Date: 22 Jan 2003 20:44:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pattern Matching
Message-Id: <b0mvs1$d3o$1@mamenchi.zrz.TU-Berlin.DE>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> [Dick Penny's TOFU rearranged]
>
> Dick Penny <penny1482@attbi.com> wrote in comp.lang.perl.misc:
> > Dick Penny
> > "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message
> > news:b0mg68$a68$1@pheidippides.axion.bt.co.uk...
> > >
> > > "Taji" <gabsaga_tata@hotmail.com> wrote in message
> > > news:15619060.0301220755.3ed84f24@posting.google.com...
> > > > I'm getting certain numbers in a process and if the number is one of
> > > > the numbers as shown below (separated with pipes), then I want to do
> > > > something but the pattern matching doesn't seem to be working
> > > > properly. Any ideas?
> > > >
> > > > my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
> > >
> > > my $number = 12 ;
> > >
> > > if ( $number =~ /$numbers/ ) {
> > > print "Number found\n" ;
> > > } else {
> > > print "Number not found\n" ;
> > > }
> > >
> > BRILLANT suggestion. Way out of the box.
>
> Well, it does have a problem. The number 12 (used in the example code)
> will match while it shouldn't, as will all numbers that happen to be
> substrings of one of the given numbers. One solution is to anchor
> the regex left and right:
>
> if ( $number =~ /^(?:$numbers)$/ ) {
>
> However, a regex may not be the best solution. The standard solution
> in Perl would use a hash, but solutions using arrays (and even vec())
> are also possible. See other parts of the thread.
Well, since none of the alternatives have come up in the thread yet,
I'll add them here (untested).
If a problem involves identifying the strings in a set of strings
(numbers are strings too), the standard solution in Perl is a hash
whose keys are the strings in the set.
Still assuming $numbers contains "|"-separated numbers:
my %numbers;
@numbers{ split /\|/, $numbers} = ();
This sets the keys of %numbers to the given numbers. The values are
undef, we don't care about them. Now the if-statement would be
written
if ( exists $numbers{ $number} ) {
Since in our case the hash keys are small integers, an array can also
be used:
my @numbers;
@numbers[ $_] = 1 for split /\|/, $numbers;
Here we care about the values in the array, we set them to a boolean
true for the numbers in the set. Others remain undef, which is boolean
false. Now the if-statement becomes
if ( $numbers[ $number] ) {
This will be slightly faster than the hash method. It may use more
or less space, depending on the distribution of the numbers.
Using a bit vector instead of an array will save some space over
the array method and may again be slightly faster. We use the vec()
function to access individual bits of a string, first setting the
interesting ones to 1:
my $num_vec = ''; # must be initialized for vec
vec( $num_vec, $_, 1) = 1 for split /\|/, $numbers;
The rest of the bits are zero (or behave as if they were, beyond the
end of the string), so we can check them via
if ( vec( $num_vec, $number, 1) ) {
The vec() method is only worth while if you have a *lot* of number
sets to manage. The array method is probably never worth while.
I'd recommend the hash in most cases, it is the most flexible and
hence least likely to give you trouble in the future.
Anno
------------------------------
Date: Wed, 22 Jan 2003 14:27:19 -0600
From: "Khanh Tran" <kttran@nortelnetworks.com>
Subject: Please Help Me
Message-Id: <b0muqe$l8s$2@zcars0v6.ca.nortel.com>
Hi There,
I wrote a perl script that get the input from the textfield, open the text
file for line matching, and then display the match line on the page. The
script works fine with unix platform. However, I need this script to work
on pc and I never write any perl script cgi in pc platform. I downloaded
and installed activeperl 5.8 on my pc. Unfortunately! I don't know how to
rewrite the script so it can work on my pc whitout any network connection.
I guess I don't know the setup requirement in order to run the code (Ashame
on me :-) ). I just want it runs locally. Please help me out on this or if
you have any suggestion let me know. I very appreciate that.
------------------ Perl Script called FindTable---------------------
#!/usr/bin/perl
&ReadParse();
my ($commands_in) = ($ENV{PATH_INFO}) ? $ENV{PATH_INFO} =~ s/^\/// :
$ENV{QUERY_STRING}; my $IMG_DIR = "/mobility/personal/khanh";
my @Result = ();
&Header();
&GetName();
if ($commands_in eq "Name" && $in{'name'} ne "") {
&TableSearch($in{'name'});
&DisplayResult() if ($#Result >= 0);
$commands_in = "";
}
&Footer();
exit;
#################################################
sub Header {
print << "STDOUT";
Content-type: text/html\n
<html>
<head><title>Khanh Tran and Thao Truong Wedding</title></head> <body
text=000000 bgcolor=white link=#00ffff vlink=#ffcccc alink=#3d659e>
<hr width="100%" size="2">
<table align=center width="80%" border=0 cellspacing=1 cellpadding=1>
<tr>
<td align=center valign=center>
<h1>
<img src="$IMG_DIR/welcome.gif" alt="" width=80 height=100 align=middle>
</h1>
<h1>
<img src="$IMG_DIR/wedding_kiss.gif" alt="" width=80 height=90 align=middle>
</h1>
<h1>
<img src="$IMG_DIR/our.gif" alt="" width=50 height=60 align=middle>
</h1>
<h1>
<img src="$IMG_DIR/wedding.gif" alt="" width=80 height=90 align=middle>
</h1>
</td>
<td valign=center align=center>
<h1>
<img src="$IMG_DIR/wedding_day.gif" alt="" width=100 height=60 align=middle>
</h1>
<h1>
<img src="$IMG_DIR/khanh_amy06.JPG" alt="" width=300 height=320
align=middle>
</h1>
<h1>
<img src="$IMG_DIR/wedding_year.gif" alt="" width=100 height=60
align=middle>
</h1>
</td>
<td valign=center align=center>
<h1>
<img src="$IMG_DIR/thao_truong.gif" alt="" width=150 height=100
align=middle>
</h1>
<img src="$IMG_DIR/rings.gif" alt="" width=90 height=100 align=middle>
</h1>
<h1>
<img src="$IMG_DIR/khanh_tran.gif" alt="" width=160 height=90 align=middle>
</h1>
</td>
</tr>
</table>
<hr size=2>
STDOUT
}
#################################################
sub GetName {
print << "STDOUT";
<center>
<form method = post action = "$ENV{'SCRIPT_NAME'}?Name">
<label><b>First Name (Only) : </b>
<input name = "name" type = text size = 50>
</label>
<input type = "submit" value = "Search">
<input type = "reset" value = "Clear">
</form>
</center>
STDOUT
}
#################################################
sub TableSearch {
local ($SearchName) = @_;
chomp($SearchName);
open (NAME, "< ${0}.cnf") or die "Can't open this file: $!\n";
while (<NAME>) {
chomp;
if ("\U$_" =~ /\U$SearchName/) {
local ($name, $table) = split(/-/,$_);
push (@Result, "\t<tr>");
push (@Result, "\t <td><font size=4 color=purple><b>$name</b></font>");
push (@Result, "\t <td><font size=4 color=purple><b>$table</b></font>");
push (@Result, "\t</tr>");
}
}
close (NAME);
print "<hr size=2>\n";
}
#################################################
sub DisplayResult {
print << "STDOUT";
<table align=center width=90% border=0 cellspacing=1 cellpadding=1>
<tr>
<td><font color=red size=4><b>Name</b></font></td>
<td><font color=red size=4><b>Table</b></font></td>
</tr>
STDOUT
foreach (@Result) { print "$_\n"; }
print "</table>\n";
}
##################################################
sub ReadParse {
# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
$in .= getc;
}
}
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Convert %XX from hex numbers to alphanumeric
$in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
# Split into key and value.
$loc = index($in[$i],"=");
$key = substr($in[$i],0,$loc);
$val = substr($in[$i],$loc+1);
$in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
}
#################################################
sub Footer {
print << "STDOUT";
<center>
<font>
<hr size=2>
<b>Send comments to
<a href="mailto:khanht_\@yahoo.com"> Khanh Tran</a>
</b><br>
Copyright © 2003 by Khanh Tran<br>
All Rights Reserved<br>
<hr size=2>
</font>
</center>
</body></html>
STDOUT
}
-------------------Configure File named FindTable.cnf ------------------
Helena Shen and Kevin - 18
Martha Baeza and Joe - 18
Martha Joe - 20
Jonathan Jones and Monica - 18
Bessie Ortiz - 18
Michael Hyatt - Sorry No Table For You
Ashish Singh and Joalyn - 19
John Chang - 19
Minh Nguyen - 20
Dung Quynh and Lisa - 04
Man Quynh and Fiancie - 04
Toan Ton and Mai - 22
Dan Nguyen and Van - 22
Khai Nguyen and Friend - 22
Vinh Dam and Wife - 22
Hung Nguyen - 32
Van Nguyen and Thao - 32
Nga Nguyen and Hung - 34
Thuy Nguyen and Van - 34
Vu Nguyen and Duyen - 35
Hai Nguyen and Wife - 35
Tam Nguyen and Oanh - 35
Thuan Le and Friend - 38
Dung Le and Friend - 38
Chinh Cao and Friend - 38
Thanks,
Khanh Tran
------------------------------
Date: Thu, 23 Jan 2003 04:44:58 GMT
From: mark@REMOVETHISkeyfutures.com (Mark)
Subject: Re: Please Help Me
Message-Id: <3e2f7251.38085300@news.tiscali.co.uk>
Hi,
Try installing Indigo perl on your pc which you can download from
www.indigostar.com/indigoperl.htm
It allows you to put scripts into a cgi-bin on your pc and then run
them from you browser, just as if you were running them from a web
server. I use it a lot for ofline testing and experimenting and
running the scripts from your browser is much better than working in
the dos window used by ativeperl.
Good luck
Mark
On Wed, 22 Jan 2003 14:27:19 -0600, "Khanh Tran"
<kttran@nortelnetworks.com> wrote:
>Hi There,
>
>I wrote a perl script that get the input from the textfield, open the text
>file for line matching, and then display the match line on the page. The
>script works fine with unix platform. However, I need this script to work
>on pc and I never write any perl script cgi in pc platform. I downloaded
>and installed activeperl 5.8 on my pc. Unfortunately! I don't know how to
>rewrite the script so it can work on my pc whitout any network connection.
>I guess I don't know the setup requirement in order to run the code (Ashame
>on me :-) ). I just want it runs locally. Please help me out on this or if
>you have any suggestion let me know. I very appreciate that.
>
>------------------ Perl Script called FindTable---------------------
>#!/usr/bin/perl
>
>&ReadParse();
>
>my ($commands_in) = ($ENV{PATH_INFO}) ? $ENV{PATH_INFO} =~ s/^\/// :
>$ENV{QUERY_STRING}; my $IMG_DIR = "/mobility/personal/khanh";
>
>my @Result = ();
>
>&Header();
>
>&GetName();
>
>if ($commands_in eq "Name" && $in{'name'} ne "") {
>
>&TableSearch($in{'name'});
>
>&DisplayResult() if ($#Result >= 0);
>
>$commands_in = "";
>
>}
>
>&Footer();
>
>exit;
>
>#################################################
>
>sub Header {
>
>print << "STDOUT";
>
>Content-type: text/html\n
>
><html>
>
><head><title>Khanh Tran and Thao Truong Wedding</title></head> <body
>text=000000 bgcolor=white link=#00ffff vlink=#ffcccc alink=#3d659e>
>
><hr width="100%" size="2">
>
><table align=center width="80%" border=0 cellspacing=1 cellpadding=1>
>
><tr>
>
><td align=center valign=center>
>
><h1>
>
><img src="$IMG_DIR/welcome.gif" alt="" width=80 height=100 align=middle>
>
></h1>
>
><h1>
>
><img src="$IMG_DIR/wedding_kiss.gif" alt="" width=80 height=90 align=middle>
>
></h1>
>
><h1>
>
><img src="$IMG_DIR/our.gif" alt="" width=50 height=60 align=middle>
>
></h1>
>
><h1>
>
><img src="$IMG_DIR/wedding.gif" alt="" width=80 height=90 align=middle>
>
></h1>
>
></td>
>
><td valign=center align=center>
>
><h1>
>
><img src="$IMG_DIR/wedding_day.gif" alt="" width=100 height=60 align=middle>
>
></h1>
>
><h1>
>
><img src="$IMG_DIR/khanh_amy06.JPG" alt="" width=300 height=320
>align=middle>
>
></h1>
>
><h1>
>
><img src="$IMG_DIR/wedding_year.gif" alt="" width=100 height=60
>align=middle>
>
></h1>
>
></td>
>
><td valign=center align=center>
>
><h1>
>
><img src="$IMG_DIR/thao_truong.gif" alt="" width=150 height=100
>align=middle>
>
></h1>
>
><img src="$IMG_DIR/rings.gif" alt="" width=90 height=100 align=middle>
>
></h1>
>
><h1>
>
><img src="$IMG_DIR/khanh_tran.gif" alt="" width=160 height=90 align=middle>
>
></h1>
>
></td>
>
></tr>
>
></table>
>
><hr size=2>
>
>STDOUT
>
>}
>
>#################################################
>
>sub GetName {
>
>print << "STDOUT";
>
><center>
>
><form method = post action = "$ENV{'SCRIPT_NAME'}?Name">
>
><label><b>First Name (Only) : </b>
>
><input name = "name" type = text size = 50>
>
></label>
>
><input type = "submit" value = "Search">
>
><input type = "reset" value = "Clear">
>
></form>
>
></center>
>
>STDOUT
>
>}
>
>#################################################
>
>sub TableSearch {
>
>local ($SearchName) = @_;
>
>chomp($SearchName);
>
>open (NAME, "< ${0}.cnf") or die "Can't open this file: $!\n";
>
>while (<NAME>) {
>
>chomp;
>
>if ("\U$_" =~ /\U$SearchName/) {
>
>local ($name, $table) = split(/-/,$_);
>
>push (@Result, "\t<tr>");
>
>push (@Result, "\t <td><font size=4 color=purple><b>$name</b></font>");
>
>push (@Result, "\t <td><font size=4 color=purple><b>$table</b></font>");
>
>push (@Result, "\t</tr>");
>
>}
>
>}
>
>close (NAME);
>
>print "<hr size=2>\n";
>
>}
>
>#################################################
>
>sub DisplayResult {
>
>print << "STDOUT";
>
><table align=center width=90% border=0 cellspacing=1 cellpadding=1>
>
><tr>
>
><td><font color=red size=4><b>Name</b></font></td>
>
><td><font color=red size=4><b>Table</b></font></td>
>
></tr>
>
>STDOUT
>
>foreach (@Result) { print "$_\n"; }
>
>print "</table>\n";
>
>}
>
>##################################################
>
>sub ReadParse {
>
># Read in text
>
>if ($ENV{'REQUEST_METHOD'} eq "GET") {
>
>$in = $ENV{'QUERY_STRING'};
>
>} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
>
>for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
>
>$in .= getc;
>
>}
>
>}
>
>@in = split(/&/,$in);
>
>foreach $i (0 .. $#in) {
>
># Convert plus's to spaces
>
>$in[$i] =~ s/\+/ /g;
>
># Convert %XX from hex numbers to alphanumeric
>
>$in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
>
># Split into key and value.
>
>$loc = index($in[$i],"=");
>
>$key = substr($in[$i],0,$loc);
>
>$val = substr($in[$i],$loc+1);
>
>$in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
>
>$in{$key} .= $val;
>
>}
>
>}
>
>#################################################
>
>sub Footer {
>
>print << "STDOUT";
>
><center>
>
><font>
>
><hr size=2>
>
><b>Send comments to
>
><a href="mailto:khanht_\@yahoo.com"> Khanh Tran</a>
>
></b><br>
>
>Copyright © 2003 by Khanh Tran<br>
>
>All Rights Reserved<br>
>
><hr size=2>
>
></font>
>
></center>
>
></body></html>
>
>STDOUT
>
>}
>
>-------------------Configure File named FindTable.cnf ------------------
>
>Helena Shen and Kevin - 18
>
>Martha Baeza and Joe - 18
>
>Martha Joe - 20
>
>Jonathan Jones and Monica - 18
>
>Bessie Ortiz - 18
>
>Michael Hyatt - Sorry No Table For You
>
>Ashish Singh and Joalyn - 19
>
>John Chang - 19
>
>Minh Nguyen - 20
>
>Dung Quynh and Lisa - 04
>
>Man Quynh and Fiancie - 04
>
>Toan Ton and Mai - 22
>
>Dan Nguyen and Van - 22
>
>Khai Nguyen and Friend - 22
>
>Vinh Dam and Wife - 22
>
>Hung Nguyen - 32
>
>Van Nguyen and Thao - 32
>
>Nga Nguyen and Hung - 34
>
>Thuy Nguyen and Van - 34
>
>Vu Nguyen and Duyen - 35
>
>Hai Nguyen and Wife - 35
>
>Tam Nguyen and Oanh - 35
>
>Thuan Le and Friend - 38
>
>Dung Le and Friend - 38
>
>Chinh Cao and Friend - 38
>
>
>
>Thanks,
>Khanh Tran
>
>
>
>
------------------------------
Date: 22 Jan 2003 12:06:00 -0800
From: jmasters@pcocd2.intelat.com (Justin Masters - remove at to reply)
Subject: Problem printing January "The Perl Journal"
Message-Id: <cavn0ltlzkn.fsf@pcocd2.intel.com>
I am a subscriber to The Perl Journal. I downloaded my January copy, and
cannot print it out. I attempted to contact Kevin Carlson (listed on The Perl
Journal homepage) and he has not responded after 2-3 weeks.
Does anybody know why it's not printable? I'd like to take it with me to read
without lugging a computer around with me.
The error I get out of the printer says:
ERROR: invalidfont
OFFENDING COMMAND: definefont
STACK:
/Font
-dictionary-
/OGLMKM+MSTT3lc80300
Any ideas? Is there a postscript parsing program that can help isolate the
problem?
Justin - remove "at" to reply.
--
------------------------------------------------------------------------------
Justin Masters (Systems Programmer) PH: 916 356-6735
Intel Corp. FM6-17 FAX: 916 377-2288
1900 Prairie City Rd, Folsom, CA 95630 jmasters@pcocd2.intelat.com
------------------------------
Date: 22 Jan 2003 11:50:52 -0800
From: kamalhyder@hotmail.com (Kamal)
Subject: Quick Perl Question
Message-Id: <cdddc935.0301221150.5b480b0a@posting.google.com>
Hello,
I have a Perl CGI script that has several modules, almost identical.
Each module does the same thing: a database query to the same
database, except that each module's query is slightly different and it
presents the results as different tables. The CGI script is called
from an HTML page and there is an if/else structure in Perl that
determines which module has to be executed.
If I comment out all modules except a couple of them - any two - the
code runs fine. If I uncomment all modules, the code becomes real
slow. I do a submit from teh HTML but the browser shows a bar at the
bottom of the window that keeps increasing in size.
After a little while, when I look at the Apache error log in
var/log/httpd/error.log I get a "Premature End of Script Headers"
error.
The same thing happens (browser hang and the same error in the log) if
I declare a large number of variables in my Perl script.
What's going on? Has anyone seen this before?
Thanks for your help.
-Kamal
------------------------------
Date: Wed, 22 Jan 2003 15:19:42 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Quick Perl Question
Message-Id: <b0mudl$6kn@netnews.proxy.lucent.com>
"Kamal" <kamalhyder@hotmail.com> wrote in message...
[snip]
> After a little while, when I look at the Apache error log in
> var/log/httpd/error.log I get a "Premature End of Script Headers"
> error.
>
> The same thing happens (browser hang and the same error in the log) if
> I declare a large number of variables in my Perl script.
>
> What's going on? Has anyone seen this before?
it means your program has errors in it.
1) run perl -c your_cgi_name to see if syntax is ok
2) run it without a browser to see it produces the html code you wanted.
------------------------------
Date: 22 Jan 2003 13:24:50 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Regex: optional word boundary
Message-Id: <776e0325.0301221324.43604b48@posting.google.com>
"Amittai Aviram" <amittai@amittai.com> wrote in message news:<b0ksdj$r073c$1@ID-124651.news.dfncis.de>...
> Hi! I am trying to create a single regular expression rule that will match
> _either_ a certain independent word _or_ certain specified compounds in
> which that word is the first element, but not other compounds in which the
> word is a specified element. For instance, the rule should match
> fan
> fanmail
> fanbase
>
> -- but not
> fantastic
>
> or any other compound other than, say, in this case, compounds with "mail"
> and "base." In other words, the rule is to say that there is either a word
> boundary at the end of "fan" _or_ "fan" is followed by one of the two other
> possibilities. This will not work:
>
> \bfan(mail | base)?
>
> -- because it will match "fantastic."
>
> I realize that this question really is entirely about regular expressions,
> not specifically about Perl. If I should not be posting the question to
> this NG, I'd appreciate specific advice about where else to post such
> questions. I did a few searches for NGs devoted to regular expressions and
> didn't turn any up.
>
> Thanks.
>
> Amittai Aviram
> amittai@amittai.com
You pretty much got it, but it looks like you added a ' ' in the
alternative clause. You can't "pretty it up" with spaces dude- they
are strictly interpreted inside the /'s. So your example would match
"fanmail " but not "fanmail,". It would also match " fan base" but not
" fanbase ". As I said you ALMOST had it.
Here's a simple example. Forget all of the "?"'s in the other
suggestions they are only clutter. Also you don't need the outside
parens in my example if you're only matching (and not substituting).
They are only there to snag $1. You can also put parens around just
(fan) if the nested parents are bothersome, and then use [$1$2] on the
right.
By the way, if you're looping through text and running the match on
lines, that's too much work! Join it (if its stored as an array) and
run it on the scalar in one big step, maybe use this intead of the
regex I used:
s/\b(fan(mail|dom|))\b/[$1]/gsm;
Shoot loops when you can, Perl regexes have some great switches to let
you do multiple operations in one step, and it's ever so much more
readable.
Or if you're COUNTING instances look at the "e" switch on the regex
perhaps.
Keep it simple:
----------------------------------
$_ = "this is a paragraph with a bunch of fan words like fan fanmail
fanblade fandom fantastic and that sort..\n\n";
print;
s/\b(fan(mail|dom|))\b/[$1]/g;
print;
---------------------- .. now run it....
./x.pl
this is a paragraph with a bunch of fan words like fan fanmail
fanblade fandom fantastic and that sort..
this is a paragraph with a bunch of [fan] words like [fan] [fanmail]
fanblade [fandom] fantastic and that sort..
Cheers,
Gx
------------------------------
Date: Wed, 22 Jan 2003 16:03:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex: optional word boundary
Message-Id: <slrnb2u59r.8ha.tadmc@magna.augustmail.com>
Sara <genericax@hotmail.com> wrote:
> "Amittai Aviram" <amittai@amittai.com> wrote in message news:<b0ksdj$r073c$1@ID-124651.news.dfncis.de>...
>> This will not work:
>>
>> \bfan(mail | base)?
> You pretty much got it, but it looks like you added a ' ' in the
> alternative clause. You can't "pretty it up" with spaces dude- they
> are strictly interpreted inside the /'s.
We can't really tell, because Amittai did not show us the operator,
only the regex.
/\bfan(mail | base)?/x
can indeed be prettied up with spaces. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 23 Jan 2003 04:53:56 GMT
From: mark@REMOVETHISkeyfutures.com (Mark)
Subject: Security with uploaded zip files
Message-Id: <3e2f735c.38351747@news.tiscali.co.uk>
Hi All,
My client needs to upload large quantities of files on to his
e-learning website. I have built him a 'multipart form-data' form so
that he can zip the files and upload them all in one go.
Though the form is held in a password protected directory the ability
to upload zip files obviously posses a serious security threat.
Therefore before decompressing the zip, it will be viewed and if it
contains any dodgy file extensions it will be deleted.
The extensions I wll look for will be .exe, .com, .cgi, .pl, .scr
Can anyone advise as to whether I should also dissallow these
extensions
.doc, .php, .asp and .js
Are there other file extensions I have missed?
Can anyone see other security holes that I am not aware of when
uploading zips?
Many thanks.
Mark
------------------------------
Date: Wed, 22 Jan 2003 20:56:53 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: Security with uploaded zip files
Message-Id: <slrnb2u1i8.rdi.mthunter@ux8.cso.uiuc.edu>
On Thu, 23 Jan 2003 04:53:56 GMT, Mark wrote:
> Hi All,
>
> My client needs to upload large quantities of files on to his
> e-learning website. I have built him a 'multipart form-data' form so
> that he can zip the files and upload them all in one go.
>
> Though the form is held in a password protected directory the ability
> to upload zip files obviously posses a serious security threat.
> Therefore before decompressing the zip, it will be viewed and if it
> contains any dodgy file extensions it will be deleted.
>
> The extensions I wll look for will be .exe, .com, .cgi, .pl, .scr
>
> Can anyone advise as to whether I should also dissallow these
> extensions
> .doc, .php, .asp and .js
>
> Are there other file extensions I have missed?
.pif ?
> Can anyone see other security holes that I am not aware of when
> uploading zips?
>
> Many thanks.
>
> Mark
------------------------------
Date: Wed, 22 Jan 2003 22:19:18 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Security with uploaded zip files
Message-Id: <Pine.LNX.4.40.0301222218420.12497-100000@lxplus072.cern.ch>
On Jan 23, Mark inscribed on the eternal scroll:
[...]
> Can anyone see other security holes that I am not aware of when
> uploading zips?
And your Perl language question was...?
------------------------------
Date: Wed, 22 Jan 2003 16:16:07 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Security with uploaded zip files
Message-Id: <slrnb2u617.8ha.tadmc@magna.augustmail.com>
Mark <mark@REMOVETHISkeyfutures.com> wrote:
> Therefore before decompressing the zip, it will be viewed and if it
> contains any dodgy file extensions it will be deleted.
>
> The extensions I wll look for will be .exe, .com, .cgi, .pl, .scr
>
> Can anyone advise as to whether I should also dissallow these
> extensions
> .doc, .php, .asp and .js
>
> Are there other file extensions I have missed?
What is your Perl question?
You appear to have wandered into the wrong newsgroup, I think
you want one that is specific to whatever OS it is that it will
be unzipped on.
For some systems, it makes no difference at all what the extension
is. On those systems, "prog.xyz", "prog.file_extension" and "prog"
could each be a Perl or Python or C++ or... program.
You will get better answers in a newsgroup specific to the
applicable operating system.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Jan 2003 22:33:42 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Security with uploaded zip files
Message-Id: <3e2f1b8b.486207396@news.erols.com>
mark@REMOVETHISkeyfutures.com (Mark) wrote:
: My client needs to upload large quantities of files on to his
: e-learning website. I have built him a 'multipart form-data' form so
: that he can zip the files and upload them all in one go.
:
: Though the form is held in a password protected directory the ability
: to upload zip files obviously posses a serious security threat.
: Therefore before decompressing the zip, it will be viewed and if it
: contains any dodgy file extensions it will be deleted.
The exact opposite is a saner approach.
Look for what is explicitly permitted instead of looking for what is
explicitly forbidden.
Instead of proceeding if no file matches a blacklist, proceed only if
all files match a whitelist.
Did you have a Perl question?
------------------------------
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 4449
***************************************