[7656] in Perl-Users-Digest
Perl-Users Digest, Issue: 1282 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 6 19:07:17 1997
Date: Thu, 6 Nov 97 16:00:25 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 6 Nov 1997 Volume: 8 Number: 1282
Today's topics:
Re: 2 element associate array (Brian Mitchell)
Re: An excellent example of perl madness (or "split stu (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Re: An excellent example of perl madness (or "split stu (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Re: An excellent example of perl madness (or "split stu (Bart Lateur)
Re: An excellent example of perl madness (or "split stu (brian d foy)
Re: Another batch of some simple newbie questions. :) <rootbeer@teleport.com>
Re: Command line options (Jim Michael)
Re: Command line options <david_ransier@intercept.com>
Re: Command line options (Stephen O. Lidie)
Re: Command line options <rootbeer@teleport.com>
Re: crontab -l reformating (Reinvent the wheel?) (William R. Ward)
Re: Dbase and Fox Pro <jason@popstudios.com>
Re: Declare hash of hashes in Perl4 <rootbeer@teleport.com>
Re: Extended REs in Perl 5.00401: /x extension failure <rootbeer@teleport.com>
Re: Extended REs in Perl 5.00401: /x extension failure (brian d foy)
Re: Help Setting Up Perl 5.0 On Win95 ?? (Greg Teets)
Re: Help with ugly regex <dgwilson@gte.net>
Re: HELP! newbie ques: browser says HTTP 501 not suppor (Cornelius Griffin)
Re: HELP! newbie ques: browser says HTTP 501 not suppor <rootbeer@teleport.com>
HTTP File Upload <brad.bradley@bridge.bellsouth.com>
My, while, and continue (Doug Harrison)
Re: newbie seeks standardfile.pl for MacPerl <rootbeer@teleport.com>
Re: ODBC and Apostrophe (Cornelius Griffin)
Re: open() and pipes (Jason Gloudon)
Re: Passing Variables (brian d foy)
Re: Perl 553 Malformed Header error <rootbeer@teleport.com>
Re: Puzzle: palindromep (Eric Bohlman)
Re: Recursive Search and Replace question (brian d foy)
Re: Regular Expressions (Bart Lateur)
Re: Regular Expressions (brian d foy)
Self-Modifying Perl Scripts (Dan Zink)
Re: Sorting and Counting with PERL (Abigail)
Why cann't I redirect my STDOUT from Perl? (Frank Merrow)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 06 Nov 1997 16:44:07 -0500
From: brian@mindbendr.com (Brian Mitchell)
Subject: Re: 2 element associate array
Message-Id: <brian-0611971644080001@20934028.bellatlantic.net>
Mark Aurit wrote
> >I cant figure out how to work a 2-element associate array table. With a
> >...
> >with <array>(1,2). But Im having no luck, I can work a single element hash,
> >...
> >The book Im using (Teach Yourself perl 5... I know, its not the Camel book,
> >but isn't bad) doesnt mention how to do this.
Sox Clinton (firstcat@whitehouse.gov) wrote:
> It IS bad ... The Camel book has a whole chapter on multidimensional
> arrays... :)
correct ! page 257 ("mauipulating lists of lists")...this is quite an easy topic
to grasp, IMO.
B R I A N M I T C H E L L
________________________________________________________________
"Imagination is the eye of the soul..."
-- Joseph Joubert (1754-1824)
________________________________________________________________
"Reflections of my Imagination" - http://www.esva.net/~mitchell/
------------------------------
Date: Thu, 06 Nov 97 17:10:35 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: An excellent example of perl madness (or "split stupidity")
Message-Id: <346240a7$3$ofn$mr2ice@speaker>
In <8cd8keufos.fsf@gadget.cscaper.com>, on 11/06/97 at 09:53 AM,
Randal Schwartz <merlyn@stonehenge.com> said:
+-----
| Once you get that down, the yes/no above is easy. The scary parts for me is
| when you write "\|", which is a two char string, even though the backslash
| usually means "the following char is special" in a string.
+--->8
Hm. My 5.004_01 seems to think the backslash is treated like a normal
backslash in a double-quoted string (as I did) and is effectively passed to
split as '|'.
(I expect we're both about to get LARTed for "proving his point"....)
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) KF8NH
------------------------------
Date: Thu, 06 Nov 97 16:57:57 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: An excellent example of perl madness (or "split stupidity")
Message-Id: <34623f69$2$ofn$mr2ice@speaker>
In <3461EF7A.73B1@hotlava.com>, on 11/06/97 at 05:25 PM,
Gary Howland <ghowland@hotlava.com> said:
+-----
| Three of the following work as expected. A pint for anyone who can tell my
| which three (without running the code):
+--->8
Define "expected". *All* of them do what I expect, on a case-by-case basis.
(But I'll hazard that you're intending 4, 6, and 10. Yes, without trying it,
although I *did* try it to verify.)
Study regexps and double-quoting rules, which it looks like are what you're
tripping over; you may escape them for now, but they're used by a *lot* more
than just Perl. You certainly won't escape them forever by switching to
Python....
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) KF8NH
------------------------------
Date: Thu, 06 Nov 1997 23:36:33 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: An excellent example of perl madness (or "split stupidity")
Message-Id: <34645460.11780808@news.tornado.be>
aml@world.std.com (Andrew M. Langmead) wrote:
>OK, I'll be (at least one of the) people who point out the
>documentation. The perlfunc man page says split() can be called in the
>following forms:
>
> split /PATTERN/,EXPR,LIMIT
> split /PATTERN/,EXPR
> split /PATTERN/
>
>So any of your examples without a pattern as the first argument to
>split is WRONG.
Let me prove you wrong by pointing at the documentation, ok? (I love it
when this happens <grin>)
If you look a bit further down in the same documentation, you can see:
: The pattern PATTERN may be replaced with an expression to specify
: patterns that vary at runtime. (To do runtime compilation only once,
: use /$variable/o.)
"expression" means "a string" here (or, more general, a scalar).
Just read the docs completely before slapping anybody around the ears
with it, will you?
Bart Lateur
bart.mediamind@tornado.be
------------------------------
Date: Thu, 06 Nov 1997 17:32:35 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: An excellent example of perl madness (or "split stupidity")
Message-Id: <comdog-ya02408000R0611971732350001@news.panix.com>
>Randal Schwartz, merlyn@stonehenge.com writes:
>>>> "Gary" == Gary Howland <ghowland@hotlava.com> writes:
>>
>>Gary> Three of the following work as expected. A pint for anyone who can tell
>>Gary> my which three (without running the code):
>>
>>(Five, actually...)
i thought that they all worked as expected, for certain definitions
of expectation. :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
it's easy to see errors that you've once made
------------------------------
Date: Thu, 6 Nov 1997 15:49:18 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Pelt <pelt@madcoyote.com>
Subject: Re: Another batch of some simple newbie questions. :)
Message-Id: <Pine.GSO.3.96.971106154302.7105N-100000@usertest.teleport.com>
On 6 Nov 1997, Pelt wrote:
> For one, I'm trying get the 3 letter day out of the date command. I'm
> using:
>
> $day = `date | awk '{print $1}'`
>
> But the output of print $day is always the entire date command. I'm
> figuring the pipe isn't working, but I'm not sure why.
Well, for starters, that little program probably isn't doing what you
expect. Perl has its own $1 variable which is being interpolated there.
But why do you want to use awk? Not to mention the date command. You're
starting three processes there merely to get something which Perl can tell
you directly.
$day = substr(localtime, 0, 3);
Of course, if you need more than that you could (and probably should) use
one of the many date-related modules to get the information you need. Good
luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 6 Nov 1997 21:37:15 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: Command line options
Message-Id: <genepoolEJ8uq3.5v2@netcom.com>
kchadha@hotmail.com wrote:
: I want to do the following:
: runprogram.pl -tM1 -tM2
: and have an array/variable contain M1 and M2
($arg1,$arg2)=@ARGV;
$arg0 =~ s/-t//;
$arg1 =~ s/-t//;
print "$arg0\n$arg1";
This prints:
M1
M2
when given -tM1 -tM2 as arguments on the command line.
Question: Why does the following print 1's instead of Mn ?
$arg0 = $ARGV[0] =~ s/-t//;
$arg1 = $ARGV[1] =~ s/-t//;
print "$arg0\n$arg1";
Cheers,
Jim
------------------------------
Date: 6 Nov 1997 21:49:25 GMT
From: "David Ransier" <david_ransier@intercept.com>
Subject: Re: Command line options
Message-Id: <01bceafd$98a7a3c0$714b62c7@itibit>
--
It may not be the best way, but here is a code fragment showing how I do
commandline arguments.
while ($arg = shift(@ARGV)) {
if ($arg =~ /^-/) {
if (lc($arg) eq "-h" || lc($arg) eq "-help") {
$help = "TRUE";
} elsif (lc($arg) eq "-s" || lc($arg) eq "-step_only") {
$stepOnly = "TRUE";
$arg = shift(@ARGV);
push(@stepOnlyNames, $arg);
} elsif (lc($arg) eq "-c" || lc($arg) eq "-clean") {
$clean = "TRUE";
} elsif (lc($arg) eq "-clean_actions") {
$cleanActions = "TRUE";
} elsif (lc($arg) eq "-u" || lc($arg) eq "-undo") {
$undo = "TRUE";
} else {
print "ERROR: Unknown switch: $arg\n";
$exitNow = "TRUE";
}
} else {
push(@inputArgs, $arg_;
}
}
David R
------------------------------------------------------------------------
_/_/_/ _/_/_/_/_/ _/_/_/ David M. Ransier
_/ _/ _/ Senior Consultant
_/ _/ _/ Intercept Technology Inc.
_/ _/ _/ David_Ransier@Intercept.com
_/ _/ _/ 503-692-0111 www.intercept.com
_/_/_/ _/ _/_/_/ 503-691-9535 (fax)
404-352-0111 (Corp Headquarters)
kchadha@hotmail.com wrote in article <878845488.2938@dejanews.com>...
> Hi,
>
> I want to do the following:
>
> runprogram.pl -tM1 -tM2
>
> and have an array/variable contain M1 and M2
>
> I normally use getopts('t:') and GetOpt::Std
>
> but that doesn't work if there are two arguments.
>
>
> Any ideas ?
>
> Please MAIL your replies to kchadha@hotmail.com
>
> Thanks,
> Kamal
>
> -------------------==== Posted via Deja News ====-----------------------
> http://www.dejanews.com/ Search, Read, Post to Usenet
>
------------------------------
Date: 6 Nov 1997 22:11:20 GMT
From: lusol@turkey.cc.Lehigh.EDU (Stephen O. Lidie)
Subject: Re: Command line options
Message-Id: <63tfa8$1aho@fidoii.cc.Lehigh.EDU>
Jim Michael (genepool@netcom.com) wrote:
: kchadha@hotmail.com wrote:
: : I want to do the following:
: : runprogram.pl -tM1 -tM2
: : and have an array/variable contain M1 and M2
: ($arg1,$arg2)=@ARGV;
: $arg0 =~ s/-t//;
: $arg1 =~ s/-t//;
: print "$arg0\n$arg1";
: This prints:
: M1
: M2
: when given -tM1 -tM2 as arguments on the command line.
: Question: Why does the following print 1's instead of Mn ?
: $arg0 = $ARGV[0] =~ s/-t//;
: $arg1 = $ARGV[1] =~ s/-t//;
: print "$arg0\n$arg1";
Context - scalar vs. array.
In scalar context you get a match count. In array context you
get the matches.
($arg0) = $ARGV[0] =~ s/-t//;
($arg1) = $ARGV[1] =~ s/-t//;
should do it.
------------------------------
Date: Thu, 6 Nov 1997 15:28:20 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Jim Michael <genepool@netcom.com>
Subject: Re: Command line options
Message-Id: <Pine.GSO.3.96.971106152733.7105L-100000@usertest.teleport.com>
On Thu, 6 Nov 1997, Jim Michael wrote:
> Question: Why does the following print 1's instead of Mn ?
>
> $arg0 = $ARGV[0] =~ s/-t//;
> $arg1 = $ARGV[1] =~ s/-t//;
> print "$arg0\n$arg1";
Because that's what s/// does in a scalar context: it returns a boolean
value. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 06 Nov 1997 14:35:17 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: crontab -l reformating (Reinvent the wheel?)
Message-Id: <waapvod647t.fsf@ese.UCSC.EDU>
mgjv@comdyn.com.au (Martien Verbruggen) writes:
> In article <63nbgu$jdv@suriname.earthlink.net>,
> bodhi1@nonamesleft.com (bodhi1@nonamesleft.com) writes:
> > I am looking for any Perl scripts that will allow me to take the output of
> > crontab -l and format it into something that is readable by normal human
> > beings. It would be ideal if it would put it into a .html format.
I liked this idea so much I figured I'd throw something together to do
it. Try this:
#!/usr/local/bin/perl -w
# showcrontab
#
# Displays the contents of a crontab file in a human readable form.
# Copyright (C) November 1997, William R. Ward <wrw@bayview.com>.
#
# Copying and distribution permitted under GNU public license, or the
# Perl "Artistic License". See GNU and Perl documentation for more info.
require 5.003; # minimum Perl version
use strict; # strict syntax checking
use Text::Wrap; # use wrap function
# Set the margin for wrapping
$Text::Wrap::columns = 72;
# Text for days of the week
my @weekdays = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
# If no command line arguments given, use output of 'crontab -l'
unshift (@ARGV, "crontab -l |") unless @ARGV;
# For each line of the input, parse and display.
while (<>)
{
chomp; # remove trailing newline
next if /^#/; # skip comments
# The crontab format is six fields separated by spaces. The first
# five are the minute, hour, day of month, day of year, and day of
# week, respectively. Each is either '*' which means 'all', or a
# list of ranges of numbers. Example values include '6', '1,3,7',
# '20-40', '1-5,7', etc. No space may be included in any field
# except for the sixth, which is the command to run.
my ($min, $hour, $mday, $yday, $wday, $cmd) = split(/\s+/, $_, 6);
# Display first the command that is to be run.
print wrap('', "\t\t ", "Run the command: $cmd\n");
# Display the time. If the hour is given...
if ($hour ne '*')
{
# ...and the minute is given...
if ($min ne '*')
{
# Split the hours and minutes into lists of times using
# str2list() and display a list of times such as '9:00 am, 5:30 pm'
my @hours = str2list($hour);
my @mins = str2list($min);
my ($i, $j, @times);
foreach $i (@hours)
{
# convert $i (the hour cursor) to am/pm style
my $ampm = ($i >= 12 ? 'pm' : 'am');
$i -= 12 if $i >= 12;
$i = 12 if $i == 0;
foreach $j (@mins)
{
push (@times, sprintf('%d:%02d %s', $i, $j, $ampm));
}
}
print wrap('', " ", " At ".list2str(@times)." each day\n");
}
# Hour given but minute not given.
else
{
print wrap('', " ", " Every minute during the ".
convertnum($hour)." hour each day\n")
if $hour ne '*';
}
}
# Hour is not given but minute is...
elsif ($min ne '*')
{
print wrap('', " ",
" At the ".convertnum($min)." minute past each hour\n");
}
# Display day of month info if given.
print wrap('', " ", " On the ".convertnum($mday)." day of the month\n")
if $mday ne '*';
# Display day of week info if given. Converts the number into the
# name of the day(s) given.
if ($wday ne '*')
{
my $msg = convertnum($wday);
$msg =~ s/(\d)(st|nd|rd|th)/$weekdays[$1]/g;
print wrap('', " ", " On $msg\n");
}
# Display day of year info if given.
print wrap('', " ", " On the ".convertnum($yday)." day of the year\n")
if $yday ne '*';
# Blank line after this entry.
print "\n";
}
# Subroutine str2list takes a string which contains a single item or a
# comma-separated list of items, where 'item' is either a number or a
# hyphen-separated range of numbers. It then returns an array of
# numbers represented by the list/ranges given. Input is scalar;
# output is list.
sub str2list
{
my ($nums) = @_;
my (@numbers);
my @list = split(/,/, $nums);
foreach (@list)
{
if (/(\d+)-(\d+)/) { push (@numbers, $1 .. $2); }
else { push (@numbers, $_); }
}
return @numbers;
}
# Subroutine convertnum converts entry such as '1,12,23-25' into a
# string such as '1st, 12th, and 23rd through 25th'. Input and output
# are both scalars.
sub convertnum
{
my ($str) = @_;
my @numbers = split(/,/, $str);
my ($num, @retval);
foreach $num (@numbers)
{
if ($num =~ /(\d+)-(\d+)/)
{
push (@retval, num2word($1).' through '.num2word($2));
}
else
{
push (@retval, num2word($num));
}
}
return list2str(@retval);
}
# Subroutine num2word converts a number into a word by adding 'st',
# 'nd', 'rd', or 'th' as appropriate. Input and output are both
# scalars.
sub num2word
{
my ($num) = @_;
$num += 0; # ensure value is numeric.
my $lastdigit = substr($num, length($num)-1, 1);
if ($lastdigit == 1) { $num .= 'st'; }
elsif ($lastdigit == 2) { $num .= 'nd'; }
elsif ($lastdigit == 3) { $num .= 'rd'; }
else { $num .= 'th'; }
return $num;
}
# Converts an array into a string by adding commas and 'ands' where
# appropriate. Uses the 'terminal comma' syntax, e.g. 'foo, bar, and
# baz' as opposed to 'foo, bar and baz'. For two elements, no comma
# is used. Input is array, output is scalar.
sub list2str
{
my (@list) = @_;
if (@list == 1) # single element, just return it.
{
return $list[0];
}
elsif (@list == 2) # two elements, return '1 and 2'
{
return join(' and ', @list);
}
else # three or more elements, return '1, 2, and 3'
{
my $last = pop @list;
return join(', ', @list).", and $last";
}
}
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
------------------------------
Date: Thu, 06 Nov 1997 15:42:16 -0800
From: Jason Burns <jason@popstudios.com>
Subject: Re: Dbase and Fox Pro
Message-Id: <346255D8.50EDC69E@popstudios.com>
Martin Bolduc wrote:
>
> Help,
>
> I want help for using Dbase III and Fox Pro database's on a Unix system
> with Perl 5.
>
> Martin
> martinbolduc@littera.com
Check this out then
http://www.fi.muni.cz/~adelton/perl/
Jason
--
-----------------------------------------------------
Jason Burns Pacific Ocean Post
Webmaster 625 Arizona Ave.
www.popstudios.com Santa Monica Ca. 90401
jason@popstudios.com Office (310) 587-1291
------------------------------
Date: Thu, 6 Nov 1997 15:05:41 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Yoz Grahame <yozg@tdv.com>
Subject: Re: Declare hash of hashes in Perl4
Message-Id: <Pine.GSO.3.96.971106150333.7105F-100000@usertest.teleport.com>
On Thu, 6 Nov 1997, Yoz Grahame wrote:
> As someone who has attempted things like this in an earlier, more
> innocent life, and who knows there *are* valid reasons to code Perl4
> (such as, you're running on DOS,
Not a valid reason: Perl version 5 is available for DOS.
> or your server sysadmin is stuck in 1991),
Not a valid reason: If your sysadmin can't be educated, you should get a
new one. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 6 Nov 1997 15:25:54 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Willie Anderson <willie.anderson@analog.com>
Subject: Re: Extended REs in Perl 5.00401: /x extension failure or bogus code?
Message-Id: <Pine.GSO.3.96.971106151718.7105K-100000@usertest.teleport.com>
On Thu, 6 Nov 1997, Willie Anderson wrote:
> #--------------------------------------------------------------------
> # This works:
> #--------------------------------------------------------------------
> $n = ($b =~ s/$a($c_open)(.*?)$c/$s/s); # $n: 0|1 comments elided
>
> #--------------------------------------------------------------------
> # but this doesn't:
> #--------------------------------------------------------------------
> $n = ( # $n: 0|1 comments elided
> $b =~ s/ # in $b, replace:
> $a # null-width anchor
> ($c_open) # open comment .
> (.*?) # minimal string .
> $c # close comment
> / # with:
> $s # the replacement string
> /sx # ignore whitespace
> );
You should know that whitespace will not be ignored in the replacement
string, so this code is different than the one above.
> The message that I get from the interpreter is:
> #--------------------------------------------------------------------
> Uncaught exception from user code:
> / # in $b, replace:
> (?=^) # null-width anchor
> (#|{|/\*) # open comment .
That first pound sign introduced a comment. You probably mean to
backslash it. (Pound signs aren't special in regexen unless /x is used.)
Also, to see that you've got all of the backslashes and other stuff that
you intend, you should probably add something like this for debugging:
my $pattern = qq/$a($c_open)(.*?)$c/;
print "The pattern is really /$pattern/\n";
Remember that whenever you want to put a real backslash into a literal
string, you should type two of them. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 06 Nov 1997 17:23:20 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Extended REs in Perl 5.00401: /x extension failure or bogus code?
Message-Id: <comdog-ya02408000R0611971723200001@news.panix.com>
In article <34621F07.22472776@analog.com>, willie.anderson@analog.com wrote:
> $b =~ s/ # in $b, replace:
> $a # null-width anchor
> ($c_open) # open comment .
> (.*?) # minimal string .
> $c # close comment
> / # with:
> $s # the replacement string
> /sx # ignore whitespace
>Uncaught exception from user code:
> / # in $b, replace:
> (?=^) # null-width anchor
> (#|{|/\*) # open comment .
> (.*?) # mi
> /: unmatched () in regexp at test.pl line 76, <> chunk 1.
look what $c_open interpolated to! there's a / in there, not to
mention all sorts of other meta characters!
there are a few ways to handle this (and you should do it any time
that you use a variable as a regex unless you really know what you
are doing!):
* use quotemeta to process the values before they get into the regex
* use \Q and \E
* escape the meta characters by hand
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Thu, 06 Nov 1997 23:32:02 GMT
From: teetshd@email.uc.edu (Greg Teets)
Subject: Re: Help Setting Up Perl 5.0 On Win95 ??
Message-Id: <3462532d.83813031@news.ececs.uc.edu>
Thanks Hans,
Someone at work had a disk from another SAMS book and it was really
easy to install. Much better.
Thanks
On Thu, 06 Nov 1997 07:21:05 GMT, hans.schrader@geol.uib.no (Hans
Schrader) wrote:
>In article <34610da4.463490@news.ececs.uc.edu>, teetshd@ucbeh.san.uc.edu wrote:
>
>Consult the PerlWin32 FAQ's that contain detailed information about how to
>install Perl in Win95 or WinNT- or you may want to consult the readme file
>or install me notes files that came with your distribution: Don't try to
>figure this out yourself- you will 99% make errors and that is NOT
>neccessarry. Newest PerlWin32 do come with VERY comfortable and easy setup
>programs! That do the hard work!
>
>>I have just unzipped the Perl 5.0 kit that came on a CD with the book
>>CGI Programming with Perl5. Unzipping the .GZ file gave me many files
>>of different file types.
>>
>>What do I do next? Do I need to compile this with my c++ compiler? I
>>use Perl at work on UNIX but I have no idea how to get going on my
>>Win95 machine at home.
>>
>>Thanks in advance for any help you can give me.
>>
>>Thanks,
>>Greg in Cincinnati
>
>Hans Schrader from Bergen in Norway "Web-Eureka"
>hansPERIODschraderSPAMbigfootPERIODcom = http://hjs.geol.uib.no/
>[PERIOD="."SPAM="@"]
------------------------------
Date: 6 Nov 1997 23:07:09 GMT
From: Douglas Wilson <dgwilson@gte.net>
Subject: Re: Help with ugly regex
Message-Id: <63tiit$kmq$1@gte1.gte.net>
schadsey@coralsys.com wrote:
> here's my regex that *works* up to a point (should be a single line,no
> whitespace):
> /^\s*(\s*%?\w+(\((\s*-?\w+\s*,?)*(\s*score\s*\d+)?\))?;)*(\s*%?\w+
> (\((\s*-?\w+\s*,?)*(\s*score\s*\d+)?\))?)\s*$/
>
> 1 questions:
> 1) is there a simpler working regex?
Simpler? I'm not sure offhand. But more legible? Yes, use the /x
modifier (perldoc perlre).
Cheers,
Douglas Wilson
------------------------------
Date: Thu, 06 Nov 1997 23:13:53 GMT
From: Escrubb@att.net (Cornelius Griffin)
Subject: Re: HELP! newbie ques: browser says HTTP 501 not supported
Message-Id: <34624ea0.550271444@netnews.att.net>
On Thu, 06 Nov 1997 16:31:06 +0000, Dean Lyons <Dean_Lyons@hp.com>
wrote:
>I'm running Perl for Win32, build 312, on a NT 4 server, trying to get a
>feedback form (HTML) to work, using a Perl script.
>
>When I press the submit button, a page appears that says:
>HTTP/1.0 501 Not Supported
>
>Is it something to do with my server or browser(NetscapeCommunicator 4)?
>
>All the paths are correct, and .pl files are associated with Perl.
>
>Any ideas, solutions or further queries?
>
>Thanks.
>Dean Lyons
>
Check out the newsgroup 'comp.infosystems.www.servers.ms-windows' for
more help. I know that you have to configure Internet Information
Server to be able to run perl. There exists a key in the registry that
needs to be modified for this to run correctly. Again, a better place
to check is the above NG.
------------------------------
Date: Thu, 6 Nov 1997 15:13:58 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Dean Lyons <Dean_Lyons@hp.com>
Subject: Re: HELP! newbie ques: browser says HTTP 501 not supported
Message-Id: <Pine.GSO.3.96.971106151250.7105H-100000@usertest.teleport.com>
On Thu, 6 Nov 1997, Dean Lyons wrote:
> When I press the submit button, a page appears that says:
> HTTP/1.0 501 Not Supported
>
> Is it something to do with my server or browser(NetscapeCommunicator 4)?
The server, almost certainly. Probably it's misconfigured somehow. Check
the docs and FAQs and newsgroups about your server. Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 06 Nov 1997 15:35:52 -0600
From: Brad Bradley <brad.bradley@bridge.bellsouth.com>
Subject: HTTP File Upload
Message-Id: <34623838.87555D27@bridge.bellsouth.com>
This is a multi-part message in MIME format.
--------------738217BAD32F92642A7521BB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I am working on an HTTP File Upload and writing the script in Perl. My
problem is that I am having trouble with the hash table with multiple
entries/files. Any Web resources or advice would be much appreciated.
Thanks in advance for any help.
Brad Bradley
--------------738217BAD32F92642A7521BB
Content-Type: application/x-perl; name="parse_file.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="parse_file.pl"
# This subroutine parses STDIN for forms submitted from
# WWW pages. This should ensure that no one can pass commands
# or other meta-characters from a form. It will process forms
# submitted via either a GET or a POST method.
# Written by Tim A. Irwin, BellSouth Intranet Services
# Phone: (205) 977-7545
# Date: 5/14/1996
$webmaster="Webmaster";
$webmaster_email="Inet\.Admin\@bridge\.bellsouth\.com";
sub parse_form_data
{
local (*FORM_DATA) = @_;
local ( $request_method, $query_string, @key_value_pairs,
$key_value, $key, $value, $boundary);
$request_method = $ENV{'REQUEST_METHOD'};
if ($request_method eq "GET")
{
$query_string = $ENV{'QUERY_STRING'};
}
elsif ($request_method eq "POST")
{
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
}
else
{
$query_string = "";
}
($boundary = $ENV{'CONTENT_TYPE'}) =~ s/^.*boundary=(.*)$/\1/;
@pairs = split(/--$boundary/, $query_string);
@pairs = splice(@pairs,1,$#pairs-1);
for $part (@pairs)
{
$part =~ s/[\r]\n$//g;
($dump, $firstline, $datas) = split(/[\r]\n/, $part, 3);
next if $firstline =~ /filename=\"\"/;
$firstline =~ s/^Content-Disposition: form-data; //;
(@columns) = split(/;\s+/, $firstline);
($name = $columns[0]) =~ s/^name="([^"]+)"$/\1/g;
if ($#columns > 0)
{
if ($datas =~ /^Content-Type:/)
{
($CGI{"$name"}->{'Content-Type'}, $blankline, $datas)
= split(/[\r]\n/, $datas, 3);
$CGI{"$name"}->{'Content-Type'} =~ s/^Content-Type: ([^\s]+)$/\1/g;
}
else
{
($blankline, $datas) = split(/[\r]\n/, $datas, 2);
$CGI{"$name"}->{'Content-Type'} = "application/octet-stream";
}
}
else
{
($blankline, $datas) = split(/[\r]\n/, $datas, 2);
if (grep(/^$name$/, keys(%CGI)))
{
if (@{$CGI{$name}} > 0)
{
push(@{$CGI{$name}}, $datas);
}
else
{
$arrvalue = $CGI{$name};
undef $CGI{$name};
$CGI{$name}[0] = $arrvalue;
push(@{$CGI{$name}}, $datas);
}
}
else
{
next if $datas =~ /^\s*$/;
$CGI{"$name"} = $datas;
}
next;
}
for $currentColumn (@columns)
{
($currentHeader, $currentValue)
= $currentColumn =~ /^([^=]+)="([^"]+)"$/;
$CGI{"$name"}->{"$currentHeader"} = $currentValue;
}
$CGI{"$name"}->{'Contents'} = $datas;
}
} # End of main routine
--------------738217BAD32F92642A7521BB--
------------------------------
Date: Thu, 06 Nov 1997 22:53:44 GMT
From: dHarrison@worldnet.att.net (Doug Harrison)
Subject: My, while, and continue
Message-Id: <63thq7$2f7@bgtnsc03.worldnet.att.net>
Is a variable declared with "my" in a while loop supposed to be
available in the loop's continue clause? It is in Perl for Win32,
5.003_07, but only in the first statement of the continue clause. For
example, when I run the following:
$x = 0;
while ($x++ != 2)
{
my $y = "test";
}
continue
{
print "1 $y\n";
print "2 $y\n";
}
The output is:
1 test
2
1 test
2
After "1 test" is printed, $y becomes empty. Anyone know what the
expected result is?
--
Doug Harrison
dHarrison@worldnet.att.net
------------------------------
Date: Thu, 6 Nov 1997 15:12:13 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: k w billerts <kbillert@cyberenet.net>
Subject: Re: newbie seeks standardfile.pl for MacPerl
Message-Id: <Pine.GSO.3.96.971106150948.7105G-100000@usertest.teleport.com>
On 5 Nov 1997, k w billerts wrote:
> I am new to the Perl environment and am using MacPerl. I would like to
> develop some basic CGI scripts and obtained the following info from a
> MacPerl FAQ:
>
> 2.3.1) How do I request an input or output file under MacPerl?
>
> require 'StandardFile.pl';
The Standard File package on the Macintosh has to do with requesting a
filename on your local system. That is, asking for a filename from the
person at the keyboard and mouse, not the person at the other end of a web
connection. It's not generally useful for CGI script programming. But, if
you do need that library file, it should have come with MacPerl. Hope this
helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 06 Nov 1997 23:09:15 GMT
From: Escrubb@att.net (Cornelius Griffin)
Subject: Re: ODBC and Apostrophe
Message-Id: <34624d30.549903992@netnews.att.net>
On Wed, 05 Nov 1997 22:50:24 -0800, Michael Cornelio
<cornelio@home.com> wrote:
>
>2. you need to escape the apostrophe in $joe with
> a double apostrophe.
>
> try $joe =~ s/'/''/g;
>
> ... then ...
>
> $sql_stmt="Insert into friends values('$joe','$bob')";
Does this mean that you cannot insert single quotes into the database?
I am having a similiar problem with single/double qoutes on an NT box,
using ODBC.pm. Any help of what I can do would be appreciated. Thank
you.
Cornelius
------------------------------
Date: 6 Nov 1997 22:07:32 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: open() and pipes
Message-Id: <63tf34$lp8$1@daily.bbnplanet.com>
Tom Phoenix (rootbeer@teleport.com) wrote:
: On Thu, 6 Nov 1997, Steve Kilbane wrote:
: > > pipe(R,W) or die "Can't make pipe: $!";
: > > my $pid = open(PIPE, "-|");
: >
: > This failed on Perl 5.004_01, on NT4.0 under M$ VC++. It
: > seems to be trying to execute "-".
: Sounds as if your system doesn't understand how to open on a pipe. Maybe
: you should install Linux. :-)
Or Solaris x86 or SCO since they don't seem to mind paying a lot of money
for tools.
Jason Gloudon
------------------------------
Date: Thu, 06 Nov 1997 18:57:45 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Passing Variables
Message-Id: <comdog-ya02408000R0611971857450001@news.panix.com>
In article <34621A45.D23E6296@horizonint.com>, dale@horizonint.com wrote:
>I've got a Web page that calls a Perl script which in turn, calls
>another Perl script. How can I pass variables from my first script to
>my second (or subsequent) scripts?
depends on how you are calling the other Perl scripts. could you
elaborate?
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Thu, 6 Nov 1997 15:51:30 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Greg <gshepard@remc7.k12.mi.us>
Subject: Re: Perl 553 Malformed Header error
Message-Id: <Pine.GSO.3.96.971106155023.7105O-100000@usertest.teleport.com>
On Thu, 6 Nov 1997, Greg wrote:
> What is a 553: Malformed header error?
A server's error message, defined in the HTTP specification. If you can't
find what you need in that spec, you should ask about it in a newsgroup
about HTTP.
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN. Hope this helps!
http://www.perl.com/CPAN/
http://www.perl.org/CPAN/
http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
http://www.perl.org/CPAN/doc/manual/html/pod/
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 6 Nov 1997 23:32:44 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Puzzle: palindromep
Message-Id: <ebohlmanEJ902K.HBu@netcom.com>
Steven W McDougall (swmcd@world.std.com) wrote:
: A Man of the 90's <brenner@lbrenner.ne.mediaone.net> writes:
: >I was reading the unrolling a loop section of Mastering Regular
: >Expressions and started thinking about palindromes.
: In general, recognizing palindromes requires a stack.
: Therefore, it can't be done with a regular expression alone.
Note that Perl "regular expressions" can include backreferences, which
allows them to recognize some constructs that can't be recognized by pure
regular expressions.
^(.+)\1$ matches any even-length palindrome and ^(.+).\1$ matches any
odd-length palindrome, so ^(.+).?\1$ should match any palindrome, albeit
rather slowly for large palindromes (since it will have to backtrack once
for every two characters). Recognizing palindromes embedded in longer
strings would be much harder.
------------------------------
Date: Thu, 06 Nov 1997 17:34:27 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Recursive Search and Replace question
Message-Id: <comdog-ya02408000R0611971734270001@news.panix.com>
In article <34622053.645863@news.peterboro.net>, killbell@peterboro.net (Drake Cleary) wrote:
>Is there any way to make the following command
>exclude one or more specific directories???
>
>find . -name '*.html' | xargs perl -pi -e
>'s/searchtext/replacetext/gm;'
the find man page has examples...
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Thu, 06 Nov 1997 23:36:35 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Regular Expressions
Message-Id: <346353d0.11636904@news.tornado.be>
"Gary C. New" <gnew@southernvirginia.edu> wrote:
>Trying to send an individuals name through a regular expression that
>will make sure the first letter in the First Middle and Last name are
>all upper case no matter how they were given.
You mean
$_ = 'john alfred doe';
s/(\w+)/\u\L$1/g;
print ;
"\u\L" means: one uppercase char, the rest lower case.
HTH,
Bart.
------------------------------
Date: Thu, 06 Nov 1997 17:07:56 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Regular Expressions
Message-Id: <comdog-ya02408000R0611971707560001@news.panix.com>
In article <34622109.48D6@southernvirginia.edu>, gnew@southernvirginia.edu wrote:
>Trying to send an individuals name through a regular expression that
>will make sure the first letter in the First Middle and Last name are
>all upper case no matter how they were given.
i hate this sort of data manipulation - it seems that a lot of systems
do this - and i should know :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
style guide <URL:http://computerdog.com/brian/style.html>
------------------------------
Date: Thu, 06 Nov 1997 17:01:25 -0600
From: zink@uiuc.edu (Dan Zink)
Subject: Self-Modifying Perl Scripts
Message-Id: <zink-0611971701260001@csu1.spcomm.uiuc.edu>
Is it possible to write a perl script that modifies itself? I tried to do
this, but was unable to open the script file for write access while it was
running. Is there any way to get around this?
Thanks,
Dan Zink
------------------------------
Date: 6 Nov 1997 22:37:38 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Sorting and Counting with PERL
Message-Id: <slrn664hpa.kcu.abigail@betelgeuse.wayne.fnx.com>
Randal Schwartz (merlyn@stonehenge.com) wrote on 1528 September 1993 in
<URL: news:8cpvoeuhlo.fsf@gadget.cscaper.com>:
++ >>>>> "Abigail" == Abigail <abigail@fnx.com> writes:
++
++ Abigail> No sense calling system.
++
++ Abigail> map {$hash {$_} ++;} @list;
++ Abigail> print map {"$_ occurs $hash{$_} times\n";} keys %hash;
++
++ No sense calling map in a void context and wasting CPU cycles building
++ up a monster return list just to throw it away:
++
++ for (@list) { $hash{$_}++ };
++ print map {"$_ occurs $hash{$_} times\n";} keys %hash;
++
++ (And yes, Abigail, I know you believe Perl should optimize this out,
++ but for *now*, it *doesn't*, so let's color within the lines for a
++ while, please?)
What, an even bigger monster list is ok, because you will
print it? ;) If you get rid of the first map, get rid of the
second one as well:
foreach (@list) {$hash {$_} ++;}
foreach (keys %hash) {print "$_ occurs $hash{$_} times\n";}
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^(11+?)\1+$/'
------------------------------
Date: 6 Nov 1997 08:59:35 -0800
From: fmerrow@qualcomm.com (Frank Merrow)
Subject: Why cann't I redirect my STDOUT from Perl?
Message-Id: <63st1n$pas@pure.qualcomm.com>
I recently discovered that for BOTH ObjRexx and Perl running on my WinNT
box, I cannot redirect STDOUT correctly. I think that it has
something to do with the PATHEXT and stuff. For instance:
somescript > foo
will fail to redirect STDOUT to foo, but
perl somescript.pl > foo
will work fine. Item 4.3 in the ActiveWare FAQ talks breifly about this
problem, but doesn't even offer the work around I show here, much less
discuss what is going on and why it is broken.
I get it is a well known problem. Can anyone explain WHY it is broken
and what is can be done about it?
Frank
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1282
**************************************