[7940] in Perl-Users-Digest
Perl-Users Digest, Issue: 1565 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 2 01:07:31 1998
Date: Thu, 1 Jan 98 22:00:19 -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, 1 Jan 1998 Volume: 8 Number: 1565
Today's topics:
Re: Avoiding regular expressions (was: Re: Newbie quest (John Moreno)
Re: Finding the TITLE to a HTML page <scribble@pobox.com>
Re: Finding the TITLE to a HTML page <scribble@pobox.com>
htmlcolorizer4U <jeffrey@halcyon.com>
Multi-dimensional Arrays? <admin@vsgcom.com>
Re: Perl not Y2K compliant (Abigail)
Re: Perl not Y2K compliant (Michael Fuhr)
Re: Perl not Y2K compliant (Michael Budash)
Re: Perl not Y2K compliant (Abigail)
Re: Perl not Y2K compliant (Michael Budash)
PERL programmer needed. <marcus@alex.net>
Re: PERLIPC - FIFO: parent, child, stalled! <jbattikha@highsynth.com>
Re: Running PerlIS on Win95 <eddie@cs.odu.edu>
Re: Search and replace questions (brian d foy)
Re: Search and replace questions (brian d foy)
Re: Simple(!) regular expression problem <scribble@pobox.com>
Re: Size in KB <scribble@pobox.com>
sockets (w1re)
test <jeffrey@halcyon.com>
Re: Win95 Perl <eddie@cs.odu.edu>
Re: Win95 Perl <eddie@cs.odu.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 1 Jan 1998 21:06:01 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Avoiding regular expressions (was: Re: Newbie question)
Message-Id: <1d271tl.okkjww1yu3htsN@roxboro-190.interpath.net>
In comp.lang.perl.misc Eli the Bearded <*@qz.to> wrote:
> John Moreno <phenix@interpath.com> wrote:
> > Tom Phoenix <rootbeer@teleport.com> wrote:
> > > On Wed, 31 Dec 1997, Joseph Cotton wrote:
> > > > I'm new to perl, too, and I retch at the sight of such code. Can any
> ...
> > If your retching at the sight of code using regular expressions you need
> > to switch to another language as regular expressions are the heart of
> > perl.
>
> In defense of Joseph, the particular s/// command provided for this
> was really bad. A tr//d would be much better for the same effect, and
> a better s// would be better (IMHO) for the desired task.
It wasn't that bad 'tho. Something like $foo =~ s/[^\d.]//g would
probably be better. What to write would depend upon how sure you were
of the actual format. But, it wasn't enough to make me retch.
> > > Perl isn't the right language for everyone; maybe you should consider
> > > learning another language that better suits the way you think.
> > I wouldn't put it this way - instead I'd say that perl isn't the right
> > language for every task, would you want to write Illustrator in it?
>
> Well perl does not have good GUI hooks, so that does hinder it for
> Illustrator. On the other hand, the string processing might be good
> for that postscript in Illustrator files.
I thought about that - it'd be better to incorporate part of a perl
interpreter in Illustrator instead of trying to program the whole thing
in perl.
> troff is the one even Larry has commented would be tough.
>
> > Although perl might not be the right language for everyone it is the
> > right tool for certain task - whether the writer likes it or not. Any
> > task that depends heavily on pattern matching or hashes is probably best
> > done in perl. Any task which doesn't use either is probably not
> > suitable for perl.
>
> How much pattern matching is involed in the typical guest book CGI?
>
> Elijah
> ------
> has never written CGI code
Neither have I, but I'd think that there was both regex and hashes -
regexes to normalize the input and hashes to prevent duplication (in
fact I'd think hashes would be the heart of it).
--
John Moreno
------------------------------
Date: 1 Jan 1998 20:10:16 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: Finding the TITLE to a HTML page
Message-Id: <68hia8$mgr@tekka.wwa.com>
joseph@5sigma.com:
>A comment inside <TITLE></TITLE> is a counterexample? Well,
>get rid of it then.
The point was, your regular expression did NOT get rid of it.
Unless you are telling me not to *compose* HTML with comments
in titles -- in which case I will point out that you have the
bullying power of neither Netscape nor Microsoft. You need it
if you want people to cripple themselves for the sake of your
deficient code.
>The point is, HTML is hard and slow to parse, and
>anything that makes it easier to do a "good enough" job
>is worthwhile.
I don't agree that stripping comments is hard and slow. And I
also think that banning comments from HTML is unreasonable.
In other words, I'm being just as practical and reasonable as
you are. But we are somehow reaching opposite conclusions.
------------------------------
Date: 1 Jan 1998 20:13:35 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: Finding the TITLE to a HTML page
Message-Id: <68higf$mp1@tekka.wwa.com>
joseph@5sigma.com:
>A theoretical answer to a pragmatic question. That is
>the dichotomy.
I sense a moral/immoral dichotomy lurking under this post's surface.
Is that true?
------------------------------
Date: 2 Jan 1998 02:13:07 GMT
From: Thanh Luu <jeffrey@halcyon.com>
Subject: htmlcolorizer4U
Message-Id: <68hifj$746$2@brokaw.wa.com>
So cool just had to share it.
--fgiorg@atl.com
#!perl
#test of eval
print "Hello1\n";
$hello_cmd = 'print "Hello2\n";';
eval $hello_cmd;
sub hello_sub {
print "Hello3\n";
}
eval &hello_sub;
sub hello_sub2 {
print "Sub "; eval $hello_cmd;
}
eval &hello_sub2;
sub small_sub{
if ($& eq $1) {
return "<$1>";
}elsif($& eq $2){
return "<$2>";
}elsif($& eq $3){
return "<$3>";
}
}
#same as this
$string = "xxx yyy \$zzz aaa zzz abc\n";
$string =~ s/(\$z+)|([abc]+)/&small_sub/eg;
print "$string";
$super_code = '$string =~
s/(\$[abc]+)|(\&[abc]+)|([xyz]+)/&small_sub/eg;';
print "$super_code\n";
$string = "xxx yyy zzz \$aaa zzz \&aabc\n";
print "$string";
eval $super_code;
print "$string";
#swiss army chainsaw in action! by fred giorgi fgiorg@atl.com
#hint1 - heads and tails might be html tags
#hint2 - keys can be ANY! pattern like '[a-z0-9_]+' or
'$[a-z0-9_]+' or '#.*'
#hint3 - put a ref to a function on each line of the hash to avoid
the case
# cascade within colorize.
#hint4 - format the output with word wrap and indent
#lets try it on this input string
#but you have to add slash(escape) to get any special characters
into the input
# or use single quotes
#special chars from <STDIN> are already in there so no sweat
$string = "print by" . 'fgiorg@atl.com' . "\$slashed" .
'&do_it_my_way_see' . "#just a comment";
print "Input string is:" . $string . "\n";
#hash of arrays, order does'nt matter
#you can easily load the hash from a file
# compose patterns exactly as they would appear s/(here)//
# these patterns are a subset of those needed to parse and html
colorize perl source
%my_hash = ( "print" => ["head1" ,"tail1"],
'\$[a-z0-9_]+' => ["head2" ,"tail2"],
'\&[a-z0-9_]+' => ["head3" ,"tail3"],
'#.*' => ["head4" ,"tail4"],
);
@the_keys = sort keys %my_hash; #could sort by pattern, head or
tail
#display the hash in sorted order
printf "%15s %15s %15s\n", "Pattern", "Head", "Tail";
foreach $key (@the_keys) {
printf "%15s %15s %15s\n", $key, $my_hash{$key}[0],
$my_hash{$key}[1];
}
#build the OR of all Keyexpressions in my_hash
$bigstr = '$string =~ s/(';
foreach $key (@the_keys) {
$bigstr .= $key . ')|(';
}
$bigstr = substr $bigstr,0,((length $bigstr) - 3); #cut off the
last )|(
$bigstr .= ')/&colorize/eg;';
print "Big s/// expression is:\n$bigstr\n";
eval $bigstr; #does the replacing
print "Final string is:\n";
print "$string\n";
sub colorize{
# be careful $& string as found is not the same as $the_keys[] as
pattern to match
print "<$&:$1,$2,$3,$4>\n"; #very useful for debug
if($1) {
return $my_hash{$the_keys[0]}[0] . $& .
$my_hash{$the_keys[0]}[1]; #or whatever you want
}elsif($2) {
return $my_hash{$the_keys[1]}[0] . $& .
$my_hash{$the_keys[1]}[1]; #or whatever you want
}elsif($3) {
return $my_hash{$the_keys[2]}[0] . $& .
$my_hash{$the_keys[2]}[1]; #or whatever you want
}elsif($4) {
return $my_hash{$the_keys[3]}[0] . $& .
$my_hash{$the_keys[3]}[1]; #or whatever you want
}else{
return "?"; #will print if match has no case above
}
}
------------------------------
Date: Fri, 02 Jan 1998 00:40:56 -0800
From: Denard Springle <admin@vsgcom.com>
Subject: Multi-dimensional Arrays?
Message-Id: <34ACA818.19BE@vsgcom.com>
Hey all,
Been awhile since I've had to post a Q here, but I've run into an
interesting little delima (again <grin>). Ok, I'm trying to build a
multi-dimensional array that will handle a simple database (kinda like
the 'ole BASIC var(x,y) thing). In this case, I have the following data:
map name, pointer_north, pointer_south, pointer_east, pointer_west,
pointer_up_level, pointer_down_level
(i.e. Damascus Building Floor One, 17, 5, 32, 44, 12, 0)
There is a relatively large amount of data (over 500 'rooms' per map)
which I would like to import in a comma delimited database format and be
able to build an interface which will allow the end user to follow the
map sequentially or jump from point to point in the map.
I've tried using the following routine to build the map, having read the
file in the array @rooms:
@roomkeys = ("ROOM", "NORTH", "SOUTH", "EAST", "WEST", "UP", "DOWN");
$room = 0;
foreach $rooms (@rooms) {
$roomname[$room++] = $rooms[0];
for ($count = 1; $count <= @roomkeys; $count++) {
$roombase{$rooms[0].$roomkeys[$count-1]} = $rooms[$count-1];
}
}
and am experiencing difficulties in getting this routine to work later
on when accessing using something like:
if ($roombase{$roomname."NORTH"} ! 0) {
** statement block **
}
etc. etc.
Any ideas would be greatly appreciated. Please email me at:
mailto:admin@vsgcom.com with any ideas or suggestions on getting this
code to work. Thanks.
Sincerely,
Denard Springle
------------------------------
Date: 2 Jan 1998 03:20:16 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl not Y2K compliant
Message-Id: <slrn6aonaj.50c.abigail@betelgeuse.wayne.fnx.com>
Michael Budash (mbudash@sonic.net) wrote on 1585 September 1993 in
<URL: news:mbudash-0101981722380001@d67.pm9.sonic.net>:
++ in perlfaq.html#Does_Perl_have_a_year_20_probl i see:
++
++ The date and time functions supplied with perl (gmtime and localtime)
++ supply adequate information to determine the year well beyond
++ 2000 (2038 is when trouble strikes).
++
++ can someone explain why 2038 is such a magic number?
$ perl -lwe 'print scalar localtime -1 + (1 << 31)'
Mon Jan 18 22:14:07 2038
$
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: 1 Jan 1998 21:18:00 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Perl not Y2K compliant
Message-Id: <68hppo$99g@flatland.dimensional.com>
mbudash@sonic.net (Michael Budash) writes:
>> The date and time functions supplied with perl (gmtime and localtime)
>> supply adequate information to determine the year well beyond
>> 2000 (2038 is when trouble strikes).
>
> can someone explain why 2038 is such a magic number?
% perl -le 'print scalar gmtime 2**31-1'
Tue Jan 19 03:14:07 2038
% perl -le 'print scalar gmtime 2**31'
Fri Dec 13 20:45:52 1901
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: Thu, 01 Jan 1998 20:32:26 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: Perl not Y2K compliant
Message-Id: <mbudash-0101982032260001@d202.pm13.sonic.net>
In article <slrn6aonaj.50c.abigail@betelgeuse.wayne.fnx.com>,
abigail@fnx.com wrote:
>> Michael Budash (mbudash@sonic.net) wrote on 1585 September 1993 in
>> <URL: news:mbudash-0101981722380001@d67.pm9.sonic.net>:
>> ++ in perlfaq.html#Does_Perl_have_a_year_20_probl i see:
>> ++
>> ++ The date and time functions supplied with perl (gmtime and localtime)
>> ++ supply adequate information to determine the year well beyond
>> ++ 2000 (2038 is when trouble strikes).
>> ++
>> ++ can someone explain why 2038 is such a magic number?
>>
>> $ perl -lwe 'print scalar localtime -1 + (1 << 31)'
>> Mon Jan 18 22:14:07 2038
Thanks, Abigail, but I still don't get it... call me what you will, but
could you please explain...? (sorry)
TIA,
Michael
--
Michael Budash, Owner * Michael Budash Consulting
mbudash@sonic.net * http://www.sonic.net/~mbudash
707-255-5371 * 707-258-7800 x7736
------------------------------
Date: 2 Jan 1998 05:04:18 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl not Y2K compliant
Message-Id: <slrn6aotdl.50c.abigail@betelgeuse.wayne.fnx.com>
Michael Budash (mbudash@sonic.net) wrote on 1585 September 1993 in
<URL: news:mbudash-0101982032260001@d202.pm13.sonic.net>:
++ In article <slrn6aonaj.50c.abigail@betelgeuse.wayne.fnx.com>,
++ abigail@fnx.com wrote:
++
++ >> Michael Budash (mbudash@sonic.net) wrote on 1585 September 1993 in
++ >> <URL: news:mbudash-0101981722380001@d67.pm9.sonic.net>:
++ >> ++ in perlfaq.html#Does_Perl_have_a_year_20_probl i see:
++ >> ++
++ >> ++ The date and time functions supplied with perl (gmtime and localtime)
++ >> ++ supply adequate information to determine the year well beyond
++ >> ++ 2000 (2038 is when trouble strikes).
++ >> ++
++ >> ++ can someone explain why 2038 is such a magic number?
++ >>
++ >> $ perl -lwe 'print scalar localtime -1 + (1 << 31)'
++ >> Mon Jan 18 22:14:07 2038
++
++ Thanks, Abigail, but I still don't get it... call me what you will, but
++ could you please explain...? (sorry)
Time is kept as seconds past 1 Jan 1970, 0:00, as a 32 bit int.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Thu, 01 Jan 1998 21:28:06 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: Perl not Y2K compliant
Message-Id: <mbudash-0101982128070001@d202.pm13.sonic.net>
In article <slrn6aotdl.50c.abigail@betelgeuse.wayne.fnx.com>,
abigail@fnx.com wrote:
>> Michael Budash (mbudash@sonic.net) wrote on 1585 September 1993 in
>> <URL: news:mbudash-0101982032260001@d202.pm13.sonic.net>:
>> ++ In article <slrn6aonaj.50c.abigail@betelgeuse.wayne.fnx.com>,
>> ++ abigail@fnx.com wrote:
>> ++
>> ++ >> Michael Budash (mbudash@sonic.net) wrote on 1585 September 1993 in
>> ++ >> <URL: news:mbudash-0101981722380001@d67.pm9.sonic.net>:
>> ++ >> ++ in perlfaq.html#Does_Perl_have_a_year_20_probl i see:
>> ++ >> ++
>> ++ >> ++ The date and time functions supplied with perl (gmtime and
localtime)
>> ++ >> ++ supply adequate information to determine the year well beyond
>> ++ >> ++ 2000 (2038 is when trouble strikes).
>> ++ >> ++
>> ++ >> ++ can someone explain why 2038 is such a magic number?
>> ++ >>
>> ++ >> $ perl -lwe 'print scalar localtime -1 + (1 << 31)'
>> ++ >> Mon Jan 18 22:14:07 2038
>> ++
>> ++ Thanks, Abigail, but I still don't get it... call me what you will, but
>> ++ could you please explain...? (sorry)
>>
>>
>> Time is kept as seconds past 1 Jan 1970, 0:00, as a 32 bit int.
>>
>>
OK, I think I got it now...thanks!
--
Michael Budash, Owner * Michael Budash Consulting
mbudash@sonic.net * http://www.sonic.net/~mbudash
707-255-5371 * 707-258-7800 x7736
------------------------------
Date: Thu, 01 Jan 1998 22:13:03 -0600
From: Marcus A. Davis <marcus@alex.net>
Subject: PERL programmer needed.
Message-Id: <883714026.45875202@dejanews.com>
The Alexander Group, Inc. provides custom Internet Applications and is
seeking qualified PERL programmers. Full and part-time positions are
available. Please contact Marcus A. Davis at 888.253.9637 or send email
with resume.
My best,
Marcus A. Davis
President
The Alexander Group, Inc.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 02 Jan 1998 00:20:01 -0500
From: Jihad Battikha <jbattikha@highsynth.com>
Subject: Re: PERLIPC - FIFO: parent, child, stalled!
Message-Id: <34AC7901.AD5FFF7E@highsynth.com>
Tom Phoenix wrote:
> > #!/usr/local/bin/perl
>
> I don't mean to sound rude here, but how can you ask us to look this over
> when you haven't even used -w and 'use strict' to get Perl to help you?
> Perl wants to help you to make good code; please work with it and we'll
> all be happier.
I already ran the script through -w and found no syntax errors. I
usually write all my scripts for remote servers (CGI) so the -w flag is
always useless to me since debugging remotely (via web browser) is
useless anyway without a syntacticly-correct script in the first place.
In the future, I'll be sure to post my script samples to include the -w
flag. Thanks for the heads-up.
As far as using strict, how would this help me in this script? I'm
using symbolic references in some variables (I have to) and 'strict'
will choke on this. Perhaps I'm wrong, but that's what happens when I
'use strict'.
> > pipe(FROM_CHILD, TO_PARENT);
> > $pid = fork;
>
> You should check whether the fork call succeeded, and possibly whether the
> pipe call did as well.
I since junked the pipe and also later learned that since I was using a
FIFO (with the Unix 'mkfifo' command), that the child script was
blocking (waiting for a READ on the file before continuing on to the
parent). Since my goal was a temporary FIFO, I got rid of the loop in
the child but I'm still running into a stall/hang (probably in the
parent).
Anyway, I'm pretty much a newcomer to Perl (and programming), so I guess
I just don't know HOW to verify the fork has succeeded. I haven't found
any docs, FAQs, or books that cover this. I also can't debug this on my
local 95/NT system since there's no equivalent to fork(). Can you give
me a sample of how to check this?
> > } elsif (defined $pid) {
>
> The if clause tested whether $pid was zero, so the only way you can get
> here is if it's non-zero (and thereby defined).
That's right. When the process forks, this condition checks to see itf
it's the parent. Is that wrong in this case? Since the first condition
checks for child, I'm assuming the next condition should check for
parent, and the last condition returns an error if it's neither (or
there wasn't any process space left for my user ID).
Here's the modified script that's still hanging on me...at this point I
think I should be inserting an alarm-based "terminator" in the child
process to avoid all those zombies I'm probably leaving on the remote
server (yes, I'm a novice, I know... :-)
Please note in this version of the script I'm using PGP in the process &
it's meant for CGI usage.
---- start newer script ----
#!/usr/local/bin/perl -w
chdir;
$ENV{PATH} .= ":/etc:/usr/etc:/sbin:/usr/bin";
$FIFO = "$ENV{DOCUMENT_ROOT}/temp/cryptpipe.txt";
$encrypted = "$ENV{DOCUMENT_ROOT}/temp/data.txt.pgp";
$pgpcmd = '/path/to/account/pgp/pgpe -at -r user@domain.com
--pubring=/path/to/account/pgp/pubring.pkr';
$pid = fork;
if ($pid == 0) { # child
unless (-p $FIFO) {
unlink $FIFO;
system('mknod', $FIFO, 'p') || &error('mkfifo');
}
# I'm thinking that this below where I'm stalling.
# Would flushing the buffer help here? How would I
# do this? Using $|=1;? Would I place that before
# the blocking process? Shouldn't the parent process
# be able to continue? I don't have access to the
# POSIX module, so I can't use WNOHANG in the parent.
open (FIFO, "> $FIFO") || &error('open fifo'); # to block
print FIFO "Text to encrypt...\n";
close FIFO;
exit(0);
}
elsif (defined $pid) { # parent
sleep(2); # give child a head start in life
unlink $encrypted;
open(PGP,"| $pgpcmd -o $encrypted $FIFO") || &error('pgp failed');
close(PGP);
unlink $FIFO;
print "Content-type: text/html\n\n";
&build_header;
print "Data encrypted via \$FIFO ($FIFO).<br>\n";
print "Command line: $pgpcmd -o $encrypted $FIFO.<br>\n";
&build_footer;
exit;
}
else {
print "Content-type: text/html\n\n";
&error('no process space');
}
sub error {
my ($error,@error_fields) = @_;
&build_header;
if ($error =~ /mkfifo/) {
print "There was a MKFIFO error.<br>\n";
} elsif ($error =~ /open fifo/) {
print "There was a OPEN FIFO error.<br>\n";
} elsif ($error =~ /pgp failed/) {
print "There was a PGP FAILED error.<br>\n";
} elsif ($error =~ /no process space/) {
print "There was a NO PROCESS SPACE error.<br>\n";
} else {
print "There was an unknown error.<br>\n";
}
&build_footer;
exit;
}
sub build_header {
print "<html>\n";
print "<head>\n";
print "<title></title>\n";
print "<body>\n";
}
sub build_footer {
print "</body></html>\n";
}
__END__
---- end newer script ----
Thank you for all the help. I'll take whatever I can get. :-))
P.S. Normally, I'd use STDIN/STDOUT (IPC::Open2 or IPC::Open3) with PGP
rather than a named pipe, but there's a bug with the 5.5 version of PGP
(on Windows95/NT) that defaults to using 'stdin' as the decrypted file
name. Hence, the need for a named pipe.
--
Jihad Battikha
jbattikha@highsynth.com
http://www.highsynth.com
------------------------------
Date: Thu, 01 Jan 1998 21:03:49 -0500
From: Eddie Brown <eddie@cs.odu.edu>
Subject: Re: Running PerlIS on Win95
Message-Id: <34AC4B04.22D2FCCB@cs.odu.edu>
I just asked the same question here a couple of days ago...
The people from this group said that a webserver must be running
on your machine and be configured correctly.. please refer to my
earlier thread..
Eddie
Rick Bailey wrote:
> I recently downloaded and installed perl and perlIS for Win95. I have
> written and debugged some scripts using perl.exe in DOS.
>
> Now that these scripts are debugged and working, I'd like to test them
> out in the browser. Whenever I try to reference one of the scripts like
> this (http://127.0.0.1/myscript.pl), the browser shows the text of the
> perl script instead of executing it.
>
> Is this something that's easy to fix? Any help would be greatly
> appreciated.
>
> Rick Bailey
> baileyr@cinternet.net
------------------------------
Date: Fri, 02 Jan 1998 00:43:39 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Search and replace questions
Message-Id: <comdog-ya02408000R0201980043390001@news.panix.com>
Keywords: from just another new york perl hacker
In article <68h56a$296@tecoma.mccc.edu>, pjh@mccc.edu (Pete Holsberg) wrote:
>Tom Phoenix suggested some simplifications but the major
>substitution still doesn't work! The problem is a plus
>sign.
> if ($_ =~ /(SIZE=\+1>)([A-Z]{2}) (\d{3})/)
> {
># $1 is SIZE=+1>
>
>#--# Because I use $1 in the replacement string,
>#--# the "+" gets interpreted there as a
>#--# metacharacter. Therein lies the problem!
>
># $2 is the two course letters
># $3 is the three course numbers
>
> $search = "$1$2 $3";
> $repl = "$1$url1$2$3$url2$2 $3<\/a>";
>
> s/$search/$repl/;
>How do I get the "+" in the $repl to be treated as an
>ordinary character?
the replacement string does not have metacharacters, although
the pattern does. you can disable metacahracters with the
\Q and \E thingys (see the perlre manpage).
s/\Q$search\E/$repl/;
you could also use the quotemeta() function (see the perlfunc
manpage)
$search = quotemeta( "$1$2 $3" );
this might solve the same problem that you had with ? in
forming the query string.
one would think that this question would have been answered
as part of
How can I quote a variable to use in a regex?
in perlfaq6, but it isn't. i'll have to see about that :)
good luck :)
--
brian d foy <comdog@computerdog.com>
Institute For the Organically-Challenged
<URL:http://computerdog.com/brian/Institute.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Fri, 02 Jan 1998 01:00:38 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Search and replace questions
Message-Id: <comdog-ya02408000R0201980100380001@news.panix.com>
Keywords: from just another new york perl hacker
In article <68gtat$lk@tecoma.mccc.edu>, pjh@mccc.edu (Pete Holsberg) wrote:
>In article <68fcso$3g8@bgtnsc02.worldnet.att.net>,
>brian d foy <comdog@computerdog.com> wrote:
>=In article <68e9kc$g3o@tecoma.mccc.edu>, pjh@mccc.edu (Pete Holsberg) posted:
>=
>=
>=> <FONT SIZE=+1><a
>=> href="/cgi-bin/htgrep.cgi/isindex=AC106&file=/SCHED/spr/msched.html&style=pre">AC106</a>
>=
>=oy! such an ugly PATH_INFO. it looks like a query string
>=without the ? at the beginning. perhaps you can post the
>=bits of code which produce that and we can turn that /
>=into a ?.
>
>Begorrah, my friend -- htgrep.cgi likes that PATH_INFO
>string just fine. :-)
oh, i didn't doubt that it was working. it just caused me to
wince when i saw it. i don't allow parameter names when we use
PATH_INFO since they are in a fixed position.
>my $url1 = "<a href='/cgi-bin/htgrep.cgi/isindex=";
if you make that last / a ? something bad happens? is this
the same way that you were
>while(<IN>)
>{
> if ($_ =~ /(SIZE\=\+1>)([A-Z]{2}) (\d{3})/)
see comments below about data storage.
> $search[$i] = "$1"."$2"." "."$3";
you don't need to use the quotes, although you could say
$search[$i] = "$1$2 $3";
it's just a way to avoid typing. :)
> if ($_ =~ /$search[$i]/)
> {
> s/$search[$i]/$repl[$i]/;
see my previous posting (same thread) about quoting metacharacters
in this situation.
>And here's a sample data file:
>
><P><A NAME="P17_232"></A><B><FONT SIZE=+1>AC 106 Office
>Accounting I (3)</FONT></B>
><P>Prerequisites: BA 103, MA 101 or equivalent proficiency
>
><P>Basic course for non-transfer students. Emphasizes the
>techniques of double-entry bookkeeping. Introduces
>computerized accounting through general ledger software. 3
>lecture hours.
><p><A NAME="P60_674"></A><B><FONT SIZE=+1>AC 109 Food,
>Beverage, and Labor Cost Control (3)</FONT></B>
><P>Prerequisites: AC 108 with a minimum C grade
just some suggestions that you can ignore:
there is a lot of redundant information in each of the records
which only serve to increase your file size (although this might
not matter to you). if you had a record format like
P60_674|AC 109|Food, Beverage, and Labor Cost Control (3)|...an so on
you could add the HTML bits later, even changing the HTML format
without mucking with the data file (these data are screaming for
a <dl>). you could also easily process the data file for other
applications. you also only have to read one "line" to get a record,
rather than testing a pattern match to see if you have the next record.
another technique, if you choose to keep this format (if you have it
working why muck with it?) is to use a special record delimiter
character. i like a form-feed (that's a \f or a ^L). when you
want to read in records, you set the $INPUT_RECORD_SEPARATOR (or $/
to the special character):
$/ = "\f"; #a line now ends with a form feed
now each <IN> gives you one record. no need to test if you are at
the start of a record.
--
brian d foy <comdog@computerdog.com>
Institute For the Organically-Challenged
<URL:http://computerdog.com/brian/Institute.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 1 Jan 1998 21:12:23 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: Simple(!) regular expression problem
Message-Id: <68hlun$slj@tekka.wwa.com>
joseph@5sigma.com writes:
>Others may offer conjecture, but I for one have absolutely no
>idea what you are hoping to do. Can you tell us what "make the
>following two variables match" means?
My guess is that the problem REALLY is about deciding whether the
two strings are equivalent somehow. So probably what's wanted is
some canonical form of both strings so they could be compared.
Maybe the canonical form is "first string of non-whitespace". In
any case, if I am right, then both $reqinput and $reqmatch need
to be modifed before the test is made.
>Laurel Shimer wrote:
>>
>> I am very embarassed that I just don't get how to do regular expressions
>> yet... Have been staring at the Camel, the Llama book and the Perl Reference
>> Guidetrying to figure out how to make the following two variables match
>>
>> $reqinput ="360-WG-002 ";
>> $reqmatch =" 360-WG-002";
------------------------------
Date: 1 Jan 1998 20:20:56 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: Size in KB
Message-Id: <68hiu8$ncv@tekka.wwa.com>
bugaj@bell-labs.com writes:
>$numK = (length $stuff) / 1024;
>
>Casting to an int, if you want to, is left as an exercise for
>the reader.
Or do length($stuff) >> 10 instead.
------------------------------
Date: Thu, 01 Jan 1998 03:02:54 GMT
From: agsec@linenoise.org (w1re)
Subject: sockets
Message-Id: <34ab06ff.62379399@news.mindspring.com>
does anyone know where i can either find a good tutorial on sockets in
perl (or c) or the source to an ip to ip chat or any ip to ip program?
w1re
agsec@linenoise.org
www.linenoise.org
www.sinnerz.com
------------------------------
Date: 2 Jan 1998 02:12:03 GMT
From: Thanh Luu <jeffrey@halcyon.com>
Subject: test
Message-Id: <68hidj$746$1@brokaw.wa.com>
somethings wrong here
------------------------------
Date: Thu, 01 Jan 1998 20:58:34 -0500
From: Eddie Brown <eddie@cs.odu.edu>
Subject: Re: Win95 Perl
Message-Id: <34AC49CA.DEB0238@cs.odu.edu>
:^) (embarrised and blushing)
Actually, I was a webmaster a couple of years ago and have set up
web servers on unix machines but never on a PC. Also, I've done quite a
bit of Java programming but only a little Perl. I've been doing software
engineering for a couple of years. Sheesh..
Thanks for the help..
David Grove wrote:
> Oh the bliss of being a newbie. :)
>
> Eddie,
>
> It won't work without running a web server on your machine. You also
> have to configure it. It isn't difficult, but you probably won't get
> through it in one night.
>
> I suggest getting Oreilly's WebSite server (free demo available) and
> playing with it for a while.
>
> NETSCAPE doesn't RUN the perl cgi. Neither does the #!/perl line
> (which can be left out under windows). Neither does the Operating
> System. The WEB server runs perl, and passes the html reslut back to
> Netscape to display.
>
> I fought with this for a while too.
>
> A good book would be helpful. You got a B&N near you?
>
> >I'm not running a web server locally on my PC. Do I have to??
> >
> >Eddie
> >
> >etta wrote:
> >
> >> What webserver are you using?
> >>
> >> Eddie Brown <eddie@NOSPAMMING.cs.odu.edu> wrote in article
> >> <34AAF65B.D28129BC@NOSPAMMING.cs.odu.edu>...
> >> > I have a html file on my Windows 95 box that calls a perl program:
> >> >
> >> > <form action="test.cgi" method="get">
> >> >
> >> > When I use Netscape locally on my win95 box, netscape displays
> >> > the source instead of executing it. I made it so that .cgi files open
> >> > with
> >> > perl but then an externaal dos shell spawns from netscape and executes
> >> > it.
> >> >
> >> > ????
> >> >
> >> > I know that the top line of the program has to be changed from the unix
> >> > path to a win95 path :
> >> >
> >> > #!/usr/bin/perl
> >> >
> >> > but #!C:/bin/perl
> >> >
> >> > doesn't seem at all right.
> >> >
> >> > HELP!! :^)
> >> >
> >> > Thanks,
> >> > Eddie
> >> >
> >> >
> >
> >
> >
------------------------------
Date: Thu, 01 Jan 1998 21:01:03 -0500
From: Eddie Brown <eddie@cs.odu.edu>
Subject: Re: Win95 Perl
Message-Id: <34AC4A5F.8A6E8B45@cs.odu.edu>
> NETSCAPE doesn't RUN the perl cgi. Neither does the #!/perl line
> (which can be left out under windows). Neither does the Operating
> System. The WEB server runs perl, and passes the html reslut back to
> Netscape to display.
>
> I fought with this for a while too.
>
> A good book would be helpful. You got a B&N near you?
>
Hmmm.. I've got the Perl, CGI, sys admin,sendmail, ... pretty much all
of the O'Reilly books but none of them touch on this subject that I know
of...
Eddie
------------------------------
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 1565
**************************************