[24281] in Perl-Users-Digest
Perl-Users Digest, Issue: 6472 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 26 21:05:51 2004
Date: Mon, 26 Apr 2004 18: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 Mon, 26 Apr 2004 Volume: 10 Number: 6472
Today's topics:
Re: CGI Perl on IIS <robin @ infusedlight.net>
Re: foreach loop test <robin @ infusedlight.net>
Re: free source blogger (works) <spamtrap@dot-app.org>
Re: free source blogger (works) <tadmc@augustmail.com>
Re: free source blogger (works) <robin @ infusedlight.net>
Re: free source blogger (works) <robin @ infusedlight.net>
Re: free source blogger (works) <robin @ infusedlight.net>
Re: free source blogger (works) <tore@aursand.no>
Re: free source blogger (works) <emschwar@pobox.com>
Re: free source blogger (works) <spamtrap@dot-app.org>
Re: free source blogger (works) <spamtrap@dot-app.org>
Re: is there a way ..... any way <tadmc@augustmail.com>
Re: new bbs <robin @ infusedlight.net>
Re: other perl groups <abigail@abigail.nl>
Re: other perl groups <jurgenex@hotmail.com>
Re: Perl can't find packages that are there <noel.sant@ntlworld.com>
Perl style re. conditionals (was Re: free source blogge <jtc@shell.dimensional.com>
RegExp poser: matching two substrings <stjm2@cam.ac.uk.remove>
Re: RegExp poser: matching two substrings <tore@aursand.no>
Re: RegExp poser: matching two substrings <stjm2@cam.ac.uk.remove>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 26 Apr 2004 17:02:11 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: CGI Perl on IIS
Message-Id: <c6k4kh$u6e$3@news.f.de.plusline.net>
7
"dave h" <daveharney@wi.rr.com> wrote in message
news:qi2fc.92227$4B1.38911@twister.rdc-kc.rr.com...
> Hi,
>
> I have this page called index.shtml ----
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <title>index</title>
> </head>
> <body>
> The date is<br>
> <!--#echo var="DATE_LOCAL" --> <br>
> A Perl Print result is<br>
> <!--#exec cgi="/perltest/perltest.pl" --> <br>
> end of test
> </body>
> </html>
>
> ---------------------------------------
> and this perl script call perltest.pl --
> #!c:\perl\bin
> print "Content-type: text/html\n\n";
> print "xxx\n";
> #exit;
> --------------------------------------------------------
> when I run the index.shtml page the perl script returns a long string of
> header info in front of the "xxx" that I was looking for. The W2K IIS
host
> I running on recommends using <meta name="hideHeader" content=""> before
the
> <!--#exec cgi="/perltest/perltest.pl" --> statement to eliminate these
> unwanted headers. I've not been successful in getting rid of the headers
> with this approach..
>
> Any suggestions for getting rid of the unwanted headers - the actual line
> returned looks like -> "HTTP/1.1 200 OK Date: Wed, 14 Apr 2004 00:09:47
GMT
> Server: Microsoft-IIS/5.0 Content-type: text/html xxx "
>
> thanks
>
well, you could always invest in a new web server, one of the good ones is
Xitami ( however you spell it )
-Robin
------------------------------
Date: Mon, 26 Apr 2004 17:00:28 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: foreach loop test
Message-Id: <c6k4kf$u6e$1@news.f.de.plusline.net>
"Robin" <robin @ infusedlight.net> wrote in message
news:c5ho9l$cgt$1@reader2.nmix.net...
> foreach (@test)
> {
> print;
> }
>
> for this code, I'd like some way to test if $_ is the last first or middle
> of the array without having to use a while loop....any suggestions?
> Thanks.
> --
> Regards,
> -Robin
> --
> robin @ infusedlight.net
>
thanks for all the info, I'll use the for loop...
-Robin
------------------------------
Date: Mon, 26 Apr 2004 18:30:03 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: free source blogger (works)
Message-Id: <j7GdnSIfhdPxEBDdRVn-tA@adelphia.com>
Tore Aursand wrote:
> Yes it does. Readability! Which of these snippets do you think is
> easiest to read (and understand)?
>
> next unless ( defined $var ); # Snippet 1
> next if ( !defined $var ); # Snippet 2
To be honest, I have to agree with Robin this time. I don't see such a huge
difference between "next unless" and "next if not".
Although, I do generally use "next unless". I don't really care one way or
the other for myself, so it's just as easy to go with the flow.
> Robin wrote:
>> [...] and the Switch module isn't installed on some servers
>
> It's been distributed with Perl for some versions, though I don't know
> when it was brought in.
Looks like 5.8.x; I have a 5.6.1 partition, and it's not there.
I can understand why a beginner wouldn't want to do jump into module
installation right off, though - it's easy to get lost in a maze of twisty
little dependencies, all alike. (And no, CPAN.pm is not a panacea for this
- it has its own warts...)
> install them "locally" under your home directory. Read the documentation
> for more information.
Specifically, 'perldoc perlmodinstall'.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Mon, 26 Apr 2004 17:36:20 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: free source blogger (works)
Message-Id: <slrnc8r3n4.q1d.tadmc@magna.augustmail.com>
Robin <robin@infusedlight.net> wrote:
> some of it is just sucky advice though, for example, the
> fact that I'm using if (! ) instead of unless makes no difference.
Yes it does. You just have not been programming long enough to
recognize the difference.
You are communicating with the reader of your code.
If it communicates more clearly, then it is NON-sucky.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 26 Apr 2004 16:53:01 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: free source blogger (works)
Message-Id: <c6k41m$trk$1@news.f.de.plusline.net>
"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2004.04.26.21.35.03.395830@aursand.no...
> On Mon, 26 Apr 2004 14:31:20 -0800, Robin wrote:
> >> [...]
> >> So - in the end: Your programming skills generally sucks. You don't
> >> seem to want to learn anything, so in x months from now, your
> >> programming skills still will sucks. Sad, but true.
>
> > I saved your message.... I'll try to get it to work with some of the
> > stuff you suggested...some of it is just sucky advice though, for
> > example, the fact that I'm using if (! ) instead of unless makes no
> > difference....
>
> Yes it does. Readability! Which of these snippets do you think is
> easiest to read (and understand)?
>
> next unless ( defined $var ); # Snippet 1
> next if ( !defined $var ); # Snippet 2
>
> Do you think some of my other comments are "sucky advices", as well? If
> so, which one(s)?
>
> > [...] and the Switch module isn't installed on some servers
>
> It's been distributed with Perl for some versions, though I don't know
> when it was brought in.
>
> Anyway; Even if your ISP don't carry all modules, you could easily
> install them "locally" under your home directory. Read the documentation
> for more information.
They won't let me do that, I need a new host, I don't have shell access,
unless there's a way of installing them with ftp?
-Robin
------------------------------
Date: Mon, 26 Apr 2004 16:54:31 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: free source blogger (works)
Message-Id: <c6k41p$trk$2@news.f.de.plusline.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnc8r3n4.q1d.tadmc@magna.augustmail.com...
> Robin <robin@infusedlight.net> wrote:
>
> > some of it is just sucky advice though, for example, the
> > fact that I'm using if (! ) instead of unless makes no difference.
>
>
> Yes it does. You just have not been programming long enough to
> recognize the difference.
>
> You are communicating with the reader of your code.
>
> If it communicates more clearly, then it is NON-sucky.
which statement is faster for one thing? I thought if was always faster in
it's check?
Or am I totally wrong?
-Robin
------------------------------
Date: Mon, 26 Apr 2004 16:56:45 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: free source blogger (works)
Message-Id: <c6k45e$tro$1@news.f.de.plusline.net>
"Paul Lalli" <ittyspam@yahoo.com> wrote in message
news:20040426164819.Q1107@dishwasher.cs.rpi.edu...
> On Mon, 26 Apr 2004, Robin wrote:
>
> > "Uri Guttman" <uri@stemsystems.com> wrote in message
> > news:x7ekqadf1q.fsf@mail.sysarch.com...
> > >
> > > define 'works' in 500 words or less
> > >
> > > uri
> >
> > hmmm...it runs.
>
>
> #!/usr/bin/perl
> use strict;
>
> my $foo = "Good";
>
> if ($foo == "Bad"){
> print "BAD!!\n";
> } else {
> print "Good!\n";
> }
>
> __END__
>
> This 'runs' too. I wouldn't exactly call it working, though. Maybe it is
> by your definition?
>
> Paul Lalli
jesus, can't get a little respect.
-Robin
------------------------------
Date: Tue, 27 Apr 2004 01:03:12 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: free source blogger (works)
Message-Id: <pan.2004.04.26.22.59.36.234697@aursand.no>
On Mon, 26 Apr 2004 18:30:03 -0400, Sherm Pendley wrote:
>> Yes it does. Readability! Which of these snippets do you think is
>> easiest to read (and understand)?
>>
>> next unless ( defined $var ); # Snippet 1
>> next if ( !defined $var ); # Snippet 2
> To be honest, I have to agree with Robin this time. I don't see such a
> huge difference between "next unless" and "next if not".
I have never mentioned 'next if not'. I can't see that 'next if not' is
the same as 'next if !'. The latter is _much_ harder to read, IMO, and in
preferred order:
next unless defined $var;
next if not defined $var;
next if !defined $var;
--
Tore Aursand <tore@aursand.no>
"Writing is a lot like sex. At first you do it because you like it.
Then you find yourself doing it for a few close friends and people you
like. But if you're any good at all, you end up doing it for money."
(Unknown)
------------------------------
Date: Mon, 26 Apr 2004 17:20:20 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: free source blogger (works)
Message-Id: <etowu42e37v.fsf@fc.hp.com>
"Robin" <robin @ infusedlight.net> writes:
> which statement is faster for one thing? I thought if was always faster in
> it's check?
If you care about the difference in speed between 'if (!foo)' and
'unless foo', then you shouldn't be using Perl. But if you really
really really REALLY care, then use Benchmark.pm to find out which one
is faster:
$ perldoc Benchmark
But I will bet you significant amounts of money that the difference is
below infinestimal.
> Or am I totally wrong?
Why do you think you care? For one thing, you're running this as a
CGI program, which means that you have to fork and exec the Perl
interpreter for each request, the overhead of which vastly dwarfs
any amount you'll save worrying about 'if !' vs. 'unless'.
Program for readability and correctness first, and THEN worry about
optimizing.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Mon, 26 Apr 2004 20:05:23 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: free source blogger (works)
Message-Id: <5Lydneu4F6FZPhDd4p2dnA@adelphia.com>
Tore Aursand wrote:
> I have never mentioned 'next if not'.
Sorry, that's my own mental shorthand. When I see "!" I think "not." I was
actually referring to "next if (! foo())"
Like I said though - even though I don't personally care one way or the
other, I generally write "next unless(foo())" because I'm aware that the
next person in line to read the code probably *does* care.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Mon, 26 Apr 2004 20:08:38 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: free source blogger (works)
Message-Id: <5Lydneq4F6EbORDd4p2dnA@adelphia.com>
Robin wrote:
> They won't let me do that, I need a new host, I don't have shell access,
> unless there's a way of installing them with ftp?
It's possible, but it's a pain in the arse.
If you can mirror their system configuration *exactly* - same OS, same
libraries, same version of Perl compiled with the same options, etc. - you
could compile modules locally to upload onto the server.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Mon, 26 Apr 2004 17:29:06 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: is there a way ..... any way
Message-Id: <slrnc8r39i.q1d.tadmc@magna.augustmail.com>
anon <me@privacy.net> wrote:
[ snip 70 lines of quoted text ]
> I agree with this post.
Thanks, I was wondering what you thought of it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 26 Apr 2004 17:05:56 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: new bbs
Message-Id: <c6k4kj$u6e$4@news.f.de.plusline.net>
"Don Stefani" <nospam_007@yahoo.com> wrote in message
news:nBQec.51010$Rc7.15700@newssvr25.news.prodigy.com...
> Robin wrote:
> > http://www.infusedlight.net/robin/bbs/bbs.pl?action=view
> > my latest opus. I hope you like it. I'd like to see if some hacker can
hack
> > this baby. I uses cgi.pm and is way more secure.
> > Admin script isn't done yet.
> >
> > --
> > Regards,
> > -Robin
> > --
> > robin @ infusedlight.net
> >
> >
> This is REALLY cool! But it would be really cool if you could list all of
the email
> addresses you use in posting here, your all over the map dude! Your like,
unfiltered again.
>
> Thanks!
>
> ROCK ON code warrior!!!
hey thanks, it's just webmaster @ infusedlight . net or robin @ infusedlight
. net and I used to post with webmaster @ reachcac . org
the new url for the bbs is www.infusedlight.net/cgi-bin/bbs.pl?action=view
regards,
-Robin
------------------------------
Date: 26 Apr 2004 23:01:03 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: other perl groups
Message-Id: <slrnc8r55f.egl.abigail@alexandra.abigail.nl>
pfancy (pfancy@bscn.com) wrote on MMMDCCCXCI September MCMXCIII in
<URL:news:408d8007@news.greennet.net>:
^^
^^ Believe it or not. The first thing I did was read books look for beginning
^^ perl online and I did not find what is recommended to be download and what
^^ to use to run perl.
Ok, I want to know. Which books did you read? Please state title,
author and publisher.
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Tue, 27 Apr 2004 00:43:52 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: other perl groups
Message-Id: <c1ijc.45107$G_.20997@nwrddc02.gnilink.net>
pfancy wrote:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
[...]
>> People need to have a preliminary scan through the perldocs and the
>> FAQs. That's all there is to do before posting.
>
> I read through that and I did not understand. It doesn't tell me how
> to or where to find the program to write perl in.
What? You can write your Perl program in any editor you like. Use vi or
emacs or even Notepad or ed if you really don't have anything better.
The religious war about "what is the best editor to write Perl programs"
resurfaces here about every 2 to 3 months.
Besides, there is even an FAQ entry: "perldoc -q editor" yields
Is there an IDE or Windows Perl Editor?
Perl programs are just plain text, so any editor will do.
If you're on Unix, you already have an IDE--Unix itself. The
UNIX philosophy is the philosophy of several small tools that
each do one thing and do it well. It's like a carpenter's
toolbox.
If you want a Windows IDE, check the following:
CodeMagicCD
http://www.codemagiccd.com/
Komodo
ActiveState's cross-platform, multi-language IDE has Perl
support, including a regular expression debugger and remote
debugging
(http://www.ActiveState.com/Products/Komodo/index.html).
(Visual Perl, a Visual Studio.NET plug-in is currently
(early 2001) in beta
(http://www.ActiveState.com/Products/VisualPerl/index.html))
.
The Object System
(http://www.castlelink.co.uk/object_system/) is a Perl web
applications development IDE.
PerlBuilder
(http://www.solutionsoft.com/perl.htm) is an integrated
development environment for Windows that supports Perl
development.
Perl code magic
(http://www.petes-place.com/codemagic.html).
visiPerl+
http://helpconsulting.net/visiperl/, from Help Consulting.
For editors: if you're on Unix you probably have vi or a vi
clone already, and possibly an emacs too, so you may not need to
download anything. In any emacs the cperl-mode (M-x cperl-mode)
gives you perhaps the best available Perl editing mode in any
editor.
For Windows editors: you can download an Emacs
GNU Emacs
http://www.gnu.org/software/emacs/windows/ntemacs.html
MicroEMACS
http://members.nbci.com/uemacs/
XEmacs
http://www.xemacs.org/Download/index.html
or a vi clone such as
Elvis
ftp://ftp.cs.pdx.edu/pub/elvis/
http://www.fh-wedel.de/elvis/
Vile
http://vile.cx/
Vim http://www.vim.org/
win32: http://www.cs.vu.nl/%7Etmgil/vi.html
For vi lovers in general, Windows or elsewhere:
http://www.thomer.com/thomer/vi/vi.html.
nvi (http://www.bostic.com/vi/, available from CPAN in
src/misc/) is yet another vi clone, unfortunately not available
for Windows, but in UNIX platforms you might be interested in
trying it out, firstly because strictly speaking it is not a vi
clone, it is the real vi, or the new incarnation of it, and
secondly because you can embed Perl inside it to use Perl as the
scripting language. nvi is not alone in this, though: at least
also vim and vile offer an embedded Perl.
The following are Win32 multilanguage editor/IDESs that support
Perl:
Codewright
http://www.starbase.com/
MultiEdit
http://www.MultiEdit.com/
SlickEdit
http://www.slickedit.com/
There is also a toyedit Text widget based editor written in Perl
that is distributed with the Tk module on CPAN. The ptkdb
(http://world.std.com/~aep/ptkdb/) is a Perl/tk based debugger
that acts as a development environment of sorts. Perl Composer
(http://perlcomposer.sourceforge.net/vperl.html) is an IDE for
Perl/Tk GUI creation.
In addition to an editor/IDE you might be interested in a more
powerful shell environment for Win32. Your options include
Bash
from the Cygwin package (http://sources.redhat.com/cygwin/)
Ksh from the MKS Toolkit (http://www.mks.com/), or the Bourne
shell of the U/WIN environment
(http://www.research.att.com/sw/tools/uwin/)
Tcsh
ftp://ftp.astron.com/pub/tcsh/, see also
http://www.primate.wisc.edu/software/csh-tcsh-book/
Zsh ftp://ftp.blarg.net/users/amol/zsh/, see also
http://www.zsh.org/
MKS and U/WIN are commercial (U/WIN is free for educational and
research purposes), Cygwin is covered by the GNU Public License
(but that shouldn't matter for Perl use). The Cygwin, MKS, and
U/WIN all contain (in addition to the shells) a comprehensive
set of standard UNIX toolkit utilities.
If you're transferring text files between Unix and Windows using
FTP be sure to transfer them in ASCII mode so the ends of lines
are appropriately converted.
On Mac OS the MacPerl Application comes with a simple 32k text
editor that behaves like a rudimentary IDE. In contrast to the
MacPerl Application the MPW Perl tool can make use of the MPW
Shell itself as an editor (with no 32k limit).
BBEdit and BBEdit Lite
are text editors for Mac OS that have a Perl sensitivity
mode (http://web.barebones.com/).
Alpha
is an editor, written and extensible in Tcl, that
nonetheless has built in support for several popular markup
and programming languages including Perl and HTML
(http://alpha.olm.net/).
Pepper and Pe are programming language sensitive text editors
for Mac OS X and BeOS respectively (http://www.hekkelman.com/).
I hope this list is comprehensive enough?
jue
------------------------------
Date: Mon, 26 Apr 2004 23:09:13 +0100
From: "Noel Sant" <noel.sant@ntlworld.com>
Subject: Re: Perl can't find packages that are there
Message-Id: <3Lfjc.4$Fe3.1@newsfe1-win>
"James Willmore" <jwillmore@remove.adelphia.net> wrote in message
news:pan.2004.04.26.18.30.20.501380@remove.adelphia.net...
> On Sun, 25 Apr 2004 18:57:10 +0100, Noel Sant wrote:
>
> [ ... ]
>
> > =============== DOS box ====================================
> > Can't locate strict.pm in @INC (@INC contains: C:/Perl/lib
C:/Perl/site/lib
> > .) a
> > t D:\Housekeeping\BackupWithZip\Scripts\BackupWithZip.pl line 264.
> > BEGIN failed--compilation aborted at
> > D:\Housekeeping\BackupWithZip\Scripts\Backu
> > pWithZip.pl line 264.
> > Return code from BackupWithZip was 2
> > =============== End of DOS box ===============================
> >
> > Line 264 is "use strict;".
>
> Why isn't "use strict;" on, say, line 3? In order for strictures to be
> useful and effective, it should be used as early as possible. Unless you
> have about 250+ lines of comments :-)
262 lines of comments, actually - and a blank line!
>
> [ ... ]
>
> > My path is:
> >
C:\Perl\bin\;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;"C:\Program
> > Files\Norton SystemWorks\Norton Ghost\";C:\Program
Files\UltraEdit;C:\Batch.
> > I can't find an environment variable @INC but I assume this is a
temporary
> > one that Perl sets up when it runs.
>
> @INC is the equivlent to "include" in C/C++ and "import" in Java. It's
> Perl's include path and is a part of the language, not part of an
> environment variable (well, it is in a way, but let's focus on just the
> @INC, shall we :-) ).
>
> Just an idea - have you tried to run a small script to see if "use
> strict;" works? Something like ....
>
> ---------------------
> #!C:/perl/bin/perl
>
> use strict;
> use warnings;
>
> print "Okay!\n";
> ---------------------
>
> If this works, then the real issue is the way your script was written.
> If it doesn't, then something with your install of Perl got fouled.
Your test prog, exactly as you wrote it, works fine. Furthermore, the
scheduled program worked OK last night, again. So I've just tried to run it
again manually - and it's working!!! I simply don't know what I did
different - in each case, I right-clicked the scheduled job and then clicked
run. I don't think I've re-booted since I last tried it manually and it
didn't work, and I'm sure I did re-boot yesterday between two manual runs
that didn't work. Oh well, thanks very much for your help, anyway.
Regards,
Noel
------------------------------
Date: 26 Apr 2004 16:31:40 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Perl style re. conditionals (was Re: free source blogger...)
Message-Id: <slrnc8r3ec.s62.jtc@shell.dimensional.com>
In article <pan.2004.04.26.21.35.03.395830@aursand.no>, Tore Aursand wrote:
> On Mon, 26 Apr 2004 14:31:20 -0800, Robin wrote:
>>> [...]
>>> So - in the end: Your programming skills generally sucks. You don't
>>> seem to want to learn anything, so in x months from now, your
>>> programming skills still will sucks. Sad, but true.
>
>> I saved your message.... I'll try to get it to work with some of the
>> stuff you suggested...some of it is just sucky advice though, for
>> example, the fact that I'm using if (! ) instead of unless makes no
>> difference....
>
> Yes it does. Readability! Which of these snippets do you think is
> easiest to read (and understand)?
>
> next unless ( defined $var ); # Snippet 1
> next if ( !defined $var ); # Snippet 2
Sorry to change the subject slightly, but one pattern I tend to object to is:
<rather long statement that does something important> unless condition;
With this form, the unless is hard to spot. The result is there's a
tendency for the reader to think it's a simple statement, at least for a
while, until he finally spots the "unless" and as a result has wasted
several seconds thinking the code does one thing until finally realizing it
does something else. (I have the same objection with
/s/unless condition/if not condition/, by the way.)
I think in this case the following makes for much clearer, maintainable
code:
if (not condition) {
<rather long statement that does something important>;
}
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Mon, 26 Apr 2004 23:41:52 +0100
From: Stuart Moore <stjm2@cam.ac.uk.remove>
Subject: RegExp poser: matching two substrings
Message-Id: <c6k37g$2ef$1@pegasus.csx.cam.ac.uk>
I've been working on a uni project where you have to work out how
similar two strings are, and I was wondering if it could be done somehow
in a regular expression (or two...). This isn't part of my project,
there are far more sensible ways of doing it, this is just for fun.
Suppose you have two strings, $s and $t. You want to find the substrings
of $s and $t that have the highest score attached, where you have +1 for
each pair of letters that match, and -1 for each that don't.
So, $s='MEAT', $t='ATE' has a score of 2 because you match the 2 'AT'
substrings.
$s='ABCDE' $t='ABFDE' has a score of 3 - it's still worthwhile taking
the -1 on the middle letter, because there's +2 on either side.
Any thoughts? Feel free to assume $s and $t are alphabetic/alphanumeric.
Finding matching substrings of length $n is easy, using
"$s:$t" =~ /([^:]{$n}).*:.*$1/;
(untested) but I got no further...
Stuart
------------------------------
Date: Tue, 27 Apr 2004 01:03:11 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: RegExp poser: matching two substrings
Message-Id: <pan.2004.04.26.23.01.36.916012@aursand.no>
On Mon, 26 Apr 2004 23:41:52 +0100, Stuart Moore wrote:
> I've been working on a uni project where you have to work out how
> similar two strings are [...]
Have you had a look at the String::* modules, specifically String::Approx?
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Tue, 27 Apr 2004 00:26:17 +0100
From: Stuart Moore <stjm2@cam.ac.uk.remove>
Subject: Re: RegExp poser: matching two substrings
Message-Id: <c6k5qp$4tc$1@pegasus.csx.cam.ac.uk>
Tore Aursand wrote:
> On Mon, 26 Apr 2004 23:41:52 +0100, Stuart Moore wrote:
>
>>I've been working on a uni project where you have to work out how
>>similar two strings are [...]
>
>
> Have you had a look at the String::* modules, specifically String::Approx?
>
Ooh, I'd forgotten that one. I have to implement the matching routines
myself though, so can't cheat (anyway it's done!). Just wondered how
much could be done with regexps, it's surprising what you can pick up
from silly questions like this and actually use later...
------------------------------
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 6472
***************************************