[24240] in Perl-Users-Digest
Perl-Users Digest, Issue: 6431 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 20 14:05:46 2004
Date: Tue, 20 Apr 2004 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 20 Apr 2004 Volume: 10 Number: 6431
Today's topics:
Re: activeperl + -T option <robin @ infusedlight.net>
Re: activeperl + -T option <robin @ infusedlight.net>
Command correction <edgrsprj@ix.netcom.com>
Re: Encrypting files <Joe.Smith@inwap.com>
Free source guestbook - unfinished <robin @ infusedlight.net>
Re: Is it possible to 'word wrap' lines just using RegE (Malcolm Dew-Jones)
Re: Parallel Parser IPC and IO - Need Direction (dwknapp)
Re: Pattern matching question ... <Joe.Smith@inwap.com>
Re: Pattern matching question ... <bmb@ginger.libs.uga.edu>
Re: Pattern matching question ... <tadmc@augustmail.com>
Re: Pattern matching question ... axel@white-eagle.co.uk
Re: Perl is the answer? <jurgenex@hotmail.com>
Re: Problems with MS Telnet Server <jwillmore@remove.adelphia.net>
Re: regular expression module? (Walter Roberson)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Apr 2004 09:26:55 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: activeperl + -T option
Message-Id: <c63mu9$6fe$1@reader2.nmix.net>
> "Robin" <robin @ infusedlight.net> wrote in message
> news:c62hsr$qci$1@reader2.nmix.net...
> > I am running active perl 8.2.3 Build 809 and I'm wondering why when I
turn
> > on taint mode checking on the #!/usr/bin/perl line whenver I run the
> script
> > it gives me an error "Too late for -T option at bbs.pl line 1." and
> whenever
> > I run the script with perl -T bbs.pl it works fine
>
> You have not said which platform you are running on.
> What you hint at should behave correctly on most UNIX systems.
> There are several well documented bugs in how DROSS and Windoze systems
> invoke Perl programs . . .
> > ....is there any
> > configuration file I can edit so perl will automatically understand it
to
> be
> > run with a -T option? I want to run the script with a Perl IDE that I've
> > downloaded and it gives me this error unless I take out the -T option.
Do
> I
> > have to take out the -T evertime I run the script with the IDE or is
there
> > something I can do?
>
> I guess you could hard-wire "-T" into the Perl command line associated
with
> extension ".pl", but that would impose taint checking everywhere, which
> would give you headaches.
I was thinking the exact same thing...thanks.
> If you change the PATHEXT environment variable to include .pl files, like
> this:
>
> SET PATHEXT=.pl;%PATHEXT%
> you can just type the file name without an extension, and Windows NT/2000
> will find the first .pl file in your path with that name. You may want to
> set PATHEXT in the System control panel rather than on the command line.
> Otherwise, you'll have to re-enter it each time the command prompt window
> closes.
Thanks... this is probably what I'll do. I mainly write cgi scripts, so
having -T imposed on all my scripts won't be too bad.
Which IDE was it?
Optiperl. And it doesn't have an option for turning on taint checking.
--
Regards,
-Robin
--
[ webmaster @ infusedlight.net ]
------------------------------
Date: Tue, 20 Apr 2004 09:28:10 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: activeperl + -T option
Message-Id: <c63mub$6fe$2@reader2.nmix.net>
Thanks...
> You can probably tell your IDE to use 'perl -T' instead of 'perl' as the
> interpreter.
This is the problem...I can't...but I'll probably do what Clyde suggested.
Thanks.
--
Regards,
-Robin
--
[ webmaster @ infusedlight.net ]
------------------------------
Date: Tue, 20 Apr 2004 18:04:01 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Command correction
Message-Id: <lCdhc.16236$l75.11490@newsread2.news.atl.earthlink.net>
"edgrsprj" <edgrsprj@ix.netcom.com> wrote in message
news:9VVgc.13640$l75.1892@newsread2.news.atl.earthlink.net...
> "edgrsprj" <edgrsprj@ix.netcom.com> wrote in message
> news:iOVgc.13634$l75.5902@newsread2.news.atl.earthlink.net...
The startup command for Windows 98 should be the following:
print file 'c:\windows\progman.exe '.$fileresults, "\n";
People can try it. However, it really does not produce satisfactory results
as the startup command for Windows XP does. The XP version disappears after
opening the text file. The 98 command leaves the Program Manager program
running. And you have to manually close it. At least this is how my
versions of Windows appear to me to work.
------------------------------
Date: Tue, 20 Apr 2004 14:05:28 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Encrypting files
Message-Id: <I6ahc.174889$K91.441245@attbi_s02>
SlimClity wrote:
> sub get16 {
> my $data = shift;
> return "\0" x ( 16 - length($data)%16) . $data;
> }
What happens if $data is 1024 bytes long?
length($data) = 1024;
length($data)%16 = 0;
16 - length($data)%16 = 16;
return "\0" x 16 . $data; # Add corruption to every block read.
The nulls belong at the end, not the beginning, and there should
be 0 nulls, not 16, for full blocks.
-Joe
------------------------------
Date: Tue, 20 Apr 2004 10:13:12 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Free source guestbook - unfinished
Message-Id: <c63mud$6fe$3@reader2.nmix.net>
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI qw(:all);
$CGI::POST_MAX=1024 * 100; # max 100K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
$" = '';
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
my $homepage = "http://www.infusedlight.net"; #change this to your homepage
my $string = '<--->';
my $string2 = '<---->';
my $version = '1.0.0';
my $bookfile = 'book.txt';
my $headerfile = 'header.txt';
my $footerfile = 'footer.txt';
my $LOCK_SH = 1;
my $LOCK_EX = 2;
my $LOCK_UN = 8;
my $DATE = getdate();
my @head = gethead ($headerfile);
my @foot = getfoot ($footerfile);
if (url_param ('action') eq "sign")
{
sign();
}
elsif (url_param ('action') eq "dosign")
{
dosign();
}
else
{
if (! -e $bookfile)
{
if (open (BOOKFILE, ">$bookfile"))
{
flock (BOOKFILE, $LOCK_EX);
print BOOKFILE '';
flock (BOOKFILE, $LOCK_UN);
close (BOOKFILE);
}
else
{
print header and print "<center><strong>Viewing Guestbook - Version
$version - No guests</strong><hr><a href=\"$homepage\">To
homepage</a></center>" and exit;
}
}
view (1);
}
sub sign
{
print header;
print (@head);
print <<END;
<div align="center">
<p><strong>GBOOK2 - Sign Guestbook - Version $version</strong></p>
<hr size="1">
<form name="form1" method="post" action="gbook.pl?action=dosign">
<table width="85%" border="1" align="center" cellpadding="3"
cellspacing="0" bordercolor="#660000">
<tr>
<td width="50%" bgcolor="#CCCCCC">Your name:</td>
<td width="50%" bgcolor="#999999">
<div align="center">
<input name="name" type="text" id="name">
</div></td>
</tr>
<tr>
<td bgcolor="#999999">Your email: </td>
<td bgcolor="#CCCCCC"><div align="center">
<input name="email" type="text" id="email">
</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Your web site name (not required):</td>
<td bgcolor="#999999"><div align="center">
<input type="text" name="webname">
</div></td>
</tr>
<tr>
<td bgcolor="#999999">Your web site URL (not required):</td>
<td bgcolor="#CCCCCC"><div align="center">
<input name="url" type="text" id="url">
</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Your message: </td>
<td bgcolor="#999999"><div align="center">
<textarea name="message" cols="35" rows="4"
id="message"></textarea>
</div></td>
</tr>
<tr>
<td bgcolor="#333399">
<div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
<td bgcolor="#333399">
<div align="left">
<input type="reset" name="Submit2" value="Reset">
</div></td>
</tr>
</table>
</form>
<hr size="1">
</div>
END
print (@foot);
}
sub dosign
{
if (checkforcookie() eq "true")
{
#print header;
#print (@head);
#print ("<center>You have already signed the guestbook once today. Please
sign it again tommorow.<hr></center>");
#print (@foot);
#exit;
}
my $name = param ('name');
my $email = param ('email');
my $website = param ('webname') . $string2 . param ('url');
my $message = param ('message');
if (param ('url') !~ /<.*>/ and param ('webname') !~ /<.*>/ and param
('url') !~ /^\s*$/s and param ('webname') !~ /$string2|$string/ and param
('url') !~ /$string2|$string/)
{
my (@url);
@url = split (/$string2/, $website);
if ($url[1] ne '' and $url[0] eq '')
{
$website = <<END;
<a href="$url[1]">$url[1]</a>
END
}
elsif ($url[0] ne '' and $url[1] ne '')
{
$website = <<END;
<a href="$url[1]">$url[0]</a>
END
}
elsif ($url[0] ne '' and $url[1] eq '')
{
$website = 'None';
}
elsif ($url[0] eq '' and $url[1] eq '')
{
$website = 'None';
}
}
else
{
$website = 'None';
}
if ($name !~ /^\s*$/g and $email !~ /^\s*$/g and $message !~ /^\s*$/g and
$email !~ /<.*>/s and param ('webname') !~ /<.*>/g and param ('url') !~
/<.*>/g and $name !~ /<.*>/s and $name !~ /$string/g and $message !~
/$string/g and $website !~ /$string/g and $email !~ /$string/g and $name !~
/$string2/g and $message !~ /$string2/g and $email !~ /$string2/g and param
('webname') !~ /$string2/g and param ('url') !~ /$string2/g)
{
open (BOOKFILE, ">>$bookfile") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (BOOKFILE, $LOCK_EX);
print BOOKFILE <<"END";
<div align="center">
<table width="75%" border="1" cellpadding="3" cellspacing="0"
bordercolor="#660000" align="center">
<tr>
<td>Date of message: </td>
<td>$DATE</td>
</tr>
<tr>
<td width="50%">Name:</td>
<td width="50%">$name</td>
</tr>
<tr>
<td width="50%">Email:</td>
<td width="50%">$email</td>
</tr>
<tr>
<td>Website:</td>
<td>$website</td>
</tr>
<tr>
<td>Message:</td>
<td>$message</td>
</tr>
</table>
<hr size="1">
$string
END
flock (BOOKFILE, $LOCK_UN);
close (BOOKFILE);
chmod (0770, $bookfile);
setcookie ("gbook.pl");
exit;
}
else
{
printerror1 ();
}
}
sub view
{
my ($header) = @_;
open (BOOKFILE, $bookfile) or print header and print
"<center><strong>Viewing Guestbook - Version $version - No
guests</strong><hr><a href=\"$homepage\">To homepage</a></center>" and exit;
flock (BOOKFILE, $LOCK_SH);
my @contentsofbook=<BOOKFILE>;
flock (BOOKFILE, $LOCK_UN);
close (BOOKFILE);
my $contentsofbook=join('', @contentsofbook);
@contentsofbook = split (/$string/, $contentsofbook);
@contentsofbook = reverse (@contentsofbook);
my $len = @contentsofbook;
$len -= 1;
my $s;
$s = 's' if ($len > 1);
print header if ($header);
print (@head);
my $cookie2;
$cookie2 = getcookie();
print <<END;
<div align="center">
<strong>GBOOK2 - Viewing Guestbook - Version $version - $len
guest$s</strong>
<hr size="1"><a href="$homepage">To homepage</a><br><br>
END
if (url_param ('s') ne '' and url_param ('e') ne '')
{
printpages();
}
if (@contentsofbook)
{
print @contentsofbook;
}
else
{
print "No guests.";
}
#print "<br>";
if (url_param ('s') ne '' and url_param ('e') ne '')
{
printpages();
}
print <<END;
<br><a href="$homepage">To homepage</a></div>
END
print (@foot);
exit;
}
sub printpages
{
return;
}
sub printerror1
{
print header;
print (@head);
print ("<center>You did not supply the required fields or you used HTML
tags which are not allowed on this guestbook.<hr></center>");
print (@foot);
exit;
}
sub gethead
{
my ($header) = @_;
my @header;
if (-e "$header")
{
open (HEADER, "$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, $LOCK_SH);
@header = <HEADER>;
flock (HEADER, $LOCK_UN);
close (HEADER);
}
else
{
open (HEADER, ">$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, $LOCK_EX);
print HEADER <<END;
<html>
<head>
<title>GBOOK2 Version $version</title>
</head>
<body>
END
flock (HEADER, $LOCK_UN);
close (HEADER);
open (HEADER, "$header") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (HEADER, $LOCK_SH);
@header = <HEADER>;
flock (HEADER, $LOCK_UN);
close (HEADER);
}
chmod (0770, $header);
return @header;
}
sub getfoot
{
my ($footer) = @_;
my @footer;
if (-e "$footer")
{
open (FOOTER, "$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, $LOCK_SH);
@footer = <FOOTER>;
flock (FOOTER, $LOCK_UN);
close (FOOTER);
}
else
{
open (FOOTER, ">$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, $LOCK_EX);
print FOOTER <<END;
</body></html>
END
close (FOOTER);
open (FOOTER, "$footer") or print header and print "An error occured
during this operation: <b>$!</b>. Please press the back button on your
browser and try again.<hr>" and exit;
flock (FOOTER, $LOCK_SH);
@footer = <FOOTER>;
flock (FOOTER, $LOCK_UN);
close (FOOTER);
}
chmod (0770, $footer);
return @footer;
}
sub getdate
{
open (DATE, "date +%D|") or print header and print "Date could not be
obtained. Please contact your system's administrator.<hr>" and exit;
my $date = <DATE>;
$date =~ s/\n//g;
$date =~ s/\r//g;
close (DATE);
return ($date);
}
sub setcookie
{
my ($redir) = @_;
my $cookie;
$cookie = cookie (-name=>'signed', -value=>"signed", -expires=>'+1d');
print redirect (-url=>"$redir", -cookie=>"$cookie");
}
sub checkforcookie
{
my $cookieflag;
$cookieflag = '';
if (getcookie() eq 'signed')
{
$cookieflag = 'true';
}
return ($cookieflag);
}
sub getcookie
{
my $cookiein;
$cookiein = cookie ('signed');
return $cookiein;
}
---------------------------------
--
Regards,
-Robin
--
[ webmaster @ infusedlight.net ]
------------------------------
Date: 20 Apr 2004 08:59:18 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Is it possible to 'word wrap' lines just using RegEx?
Message-Id: <408548d6@news.victoria.tc.ca>
W. D. (NewsGroups@US-Webmasters.com) wrote:
: Hi Folks,
: Is there to split a line like the following, *ONLY* using a regular
: expression?
variations on
s/(.{1,72})(\s)/$1\n/g;
------------------------------
Date: 20 Apr 2004 06:37:49 -0700
From: dwknapp@uvm.edu (dwknapp)
Subject: Re: Parallel Parser IPC and IO - Need Direction
Message-Id: <3497629f.0404200537.30b646ff@posting.google.com>
For anyone else who is trying to do the same... I figured out what was wrong.
> use IO::Select;
> use Symbol;
> use IO::File;
> use IO::Handle;
>
> my $sel = new IO::Select;
> my $parent = 1;
> my $num_children = 0;
> my @filelist;
> my @holdfiles;
> my $files_per_proc = sprintf("%d", @filelist/4);
>
> while (@holdfiles = splice(@filelist, 0, $files_per_proc)) {
> my ($reader, $writer) = (gensym, gensym);
> pipe($reader, $writer) or die "pipe: $!";
>
> my $kid = fork();
> if ($kid) {
> close $writer;
> $sel->add($reader);
> $num_children += 1;
> }
> else {
> close $reader;
> gen_sub($writer, \@holdfiles, \@opts);
> $parent = 0;
> last;
> }
> }
> if ($parent) { # MOVED SO ONLY THE PARENT READS
>
> # HERE'S WHERE THE PROBLEM WAS. ONLY THE PARENT SHOULD BE READING. NOW THIS > # SCRIPT WORKS LIKE A CHAMP.
> while (1) {
> foreach my $client ($sel->can_read()) {
> my $line = <$client>;
> if (!$line) {
> $sel->remove($client);
> next;
> }
> print $line; # STDOUT HERE BUT MAYBE EVENTUALLY A FILEHANDLE
> }
> if ($sel->count == 0) {
> last;
> }
> }
>
> while ($num_children) {
> my $dead_child = wait;
> $num_children--;
> }
> }
>
> exit(0);
>
> sub gen_sub {
> my ($writer, $ra_holdfiles, $ra_options) = @_;
>
> foreach my $file (@{$ra_holdfiles}) {
> die "Error" unless (open(IN, $file));
> while (my $line = <IN>) {
> LOTS OF PARSING HERE
>
> print $writer "SOME DATA THAT I'VE PARSED\n"; # MANY
> TIMES PER FILE
> }
> close IN;
> }
> }
>
------------------------------
Date: Tue, 20 Apr 2004 13:38:58 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Pattern matching question ...
Message-Id: <SJ9hc.177528$JO3.103286@attbi_s04>
JK wrote:
> As I'm somewhat new to Perl, I'm having a problem with
> a pattern matching section of code where I'm simply looking
> for any occurrence of a URL, and converting that to a
> hyperlink, i.e.
>
> $link =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
> $newurl =~ s/$link/<a href=\"$link\" target=\"_blank\">$link<\/a>/ig;
>
> This works fine unless there are special characters in the
> $link value, in which case the $newurl returns the same value
> as $link.
>
> I know there is probably some way to escape the $link value,
> but not sure how.
You're clobbering the URL encoding when creating producing the
readable text, and not doing a complete job. The original
encoding needs to be kept for the href. And you're missing \Q.
$coded = "Joe%27s+page";
($plain = $coded) =~ tr/+/ /;
$plain =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
$newurl =~ s,\Q$coded,<a href="$coded" target="blank">$plain</a>,ig;
You'd be better off using the escape() and unescape() functions made
available by "use CGI".
-Joe
------------------------------
Date: Tue, 20 Apr 2004 10:58:03 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Pattern matching question ...
Message-Id: <Pine.A41.4.58.0404201057100.13162@ginger.libs.uga.edu>
On Tue, 20 Apr 2004, JK wrote:
> As I'm somewhat new to Perl, I'm having a problem with
> a pattern matching section of code where I'm simply looking
> for any occurrence of a URL, and converting that to a
> hyperlink, i.e.
>
> $link =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
> $newurl =~ s/$link/<a href=\"$link\" target=\"_blank\">$link<\/a>/ig;
>
> This works fine unless there are special characters in the
> $link value, in which case the $newurl returns the same value
> as $link.
This isn't a direct answer to your question, but you might want to look at
Regexp::Common::URI
Regards,
Brad
------------------------------
Date: Tue, 20 Apr 2004 11:39:49 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Pattern matching question ...
Message-Id: <slrnc8akil.9c6.tadmc@magna.augustmail.com>
axel@white-eagle.co.uk <axel@white-eagle.co.uk> wrote:
> Brian McCauley <nobull@mail.com> wrote:
>> > As I'm somewhat new to Perl,
I doubt that Brian is new to Perl.
axel, please take care with your attributions.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 20 Apr 2004 16:25:59 GMT
From: axel@white-eagle.co.uk
Subject: Re: Pattern matching question ...
Message-Id: <rachc.606$54.98@dentist.cableinet.net>
Tad McClellan <tadmc@augustmail.com> wrote:
> axel@white-eagle.co.uk <axel@white-eagle.co.uk> wrote:
> > Brian McCauley <nobull@mail.com> wrote:
> >> > As I'm somewhat new to Perl,
> I doubt that Brian is new to Perl.
> axel, please take care with your attributions.
My unreserved apologies to everyone, especially Brian.
Axel
------------------------------
Date: Tue, 20 Apr 2004 13:57:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl is the answer?
Message-Id: <Q_9hc.12784$Aq.7016@nwrddc03.gnilink.net>
Andries wrote:
> I have a list of thousands and thousands of the next lines:
Where are those lines? In one file?
Scattered in hundreds or thousands of files?
In an array? On your computer monitor as output of some SQL command?
The best approach very much depends upon _how_ you can access those lines?
> ----------------------------------------------------------------------
> <a href="hs80.htm#halveringstijd"target="topic">halveringstijd</a><br>
> <a href="hs80.htm#hartkleppen" target="topic"></a><br>
> <a href="hs80.htm#hartvolume" target="topic"></a><br>
> <a href="hs80.htm#hemoglobine" target="topic"></a><br>
> <a href="hs80.htm#heteroseksueel " target="topic"></a><br>
> <a href="hs80.htm#hijgen" target="topic"></a><br>
> <a href="hs80.htm#histamine" target="topic"></a><br>
> --------------------------------------------------------------------------
------------
> I need to copy the word between the # and " and put it after the > and
> </a>
>
> It can done by hand like the first line but it can be automated with a
> perl script isn't it?
If your data is as simple and as regular as stated above and if all your
"lines" are actually the content in one file without much junk around them
(these are a lot of "ifs" but I have a strong feeling your data might
actually be arranged like that), then writing a Perl script for this simple
task is overkill.
Just use the substitute-regexp or replace-regexp function in any decend text
editor and you are done faster then writing even this single-line Perl
script.
jue
------------------------------
Date: Tue, 20 Apr 2004 11:37:54 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Problems with MS Telnet Server
Message-Id: <pan.2004.04.20.15.37.49.360929@remove.adelphia.net>
On Mon, 19 Apr 2004 08:51:56 -0700, Mike wrote:
> I am trying to telnet to a Windows 2K server, running the MS Services
> for Unix Telnet Server.
>
> I can connect to the box and my commands execute correctly, but I am
> unable to gather the results of the commands I run. I have seen
> postings online saying that the MS Telnet Server is not a "real" telnet
> server and the fix for this problem is to install another telnet server.
> This is not an option for me. I am stuck with this server, and can't
> change it.
>
> Can anybody help?
[...]
Check the prompt. You might want to read the section of the Net::Telnet
documentation on MS Services.
If you can change the prompt in your telnet session (meaning, if you can
log into the telnet service from the command line and change your prompt
to something like '_MYPROMPT_'), then you can do that in the script as
well. This way, you don't have to try different regular expressions out to
find the "right one" for the prompt. You'll already know what it is :-)
Otherwise, the code posted works for me (with modifications - I use SuSE
and SuSE has decided that my terminal is a "network" terminal instead of a
vt100 or something "normal" ... so I have to modify the script in order
for it to work :-) ).
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
You're at the end of the road again.
------------------------------
Date: 20 Apr 2004 16:26:26 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: regular expression module?
Message-Id: <c63ivi$5il$1@canopus.cc.umanitoba.ca>
In article <c632jt$m3p$2@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
:> No, the OP is right - "standard" regular expressions can be done with
:> a Finite State Machine.
:I may be confused, but I don't see the contradiction. The finite-state-
:machine *does* the backtracking, no?
No, no backtracking is needed.
There are two major representations of finite state machines, one "DFA"
(Deterministic Finite Automata) and the other one "NDFA"
(Non-Deterministic Finite Automata). NDFA are smaller to diagram out,
and are possibly more popular. It is common for beginners to believe
that NDFA can "do more" than DFA can, but they both have the same expressive
power, and there is a mechanical procedure to convert any NDFA to an
exactly equivilent DFA. Some implimentations of NDFA use
backtracking in order to avoid the (non-trivial) overhead of doing
the NDFA -> DFA conversion; those backtracking implimentations are
often faster on simple expressions, but when one has a more complex
expression, then it becomes better to do the conversion and run the
equivilent-DFA.
DFA's never need to backtrack. Once you -have- the DFA, it runs in
time linear to the length of the input: you read the next input
symbol, index that symbol in the transition table of the current
state, and that tells you the new state number. Repeat and by the
end of processing each symbol in the string exactly -once-,
you have either "accepted" the input (in which case the pattern matched)
or else you run out of input at a non-accepting state, in which case
the pattern match failed. The difficulty, the reason this isn't
used much more often, is that if you are starting with an NDFA, the
conversion into a DFA takes exponential time. Going the
regex -> NDFA -> DFA route is thus best suited for cases in which you
expect to "compile once, run often". Too expensive of a process if
you are farting around doing on-the-fly typing in of expressions to
be processed against short files, but well worth doing if you have a
big input file.... especially if you can separate out the compiled
DFA and "save" it so that you don't have to recompile it from run
to run or when other parts of the program change.
'yacc' is a well known program that does all the work of building
up compiled DFA, complete with some kind of state-table compression
so that the result is both space and time efficient. But yacc produces
C code. I seem to recall hearing of a yacc implimentation that
had an option for spitting out perl. Or was that a 'lex' program?
I do not remember clearly.
--
Studies show that the average reader ignores 106% of all statistics
they see in .signatures.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6431
***************************************