[22419] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4640 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 28 06:06:03 2003

Date: Fri, 28 Feb 2003 03:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 28 Feb 2003     Volume: 10 Number: 4640

Today's topics:
        "Achilles Members Area" cgi script & author.... (Willy Kreim)
        accessing functions from other perl programs <hugo@geoinformex.com>
    Re: accessing functions from other perl programs <noreply@gunnar.cc>
    Re: Also religious: brackets <newsfeed2@boog.co.uk>
    Re: Anyway to do away with ?: in the map function <goldbb2@earthlink.net>
    Re: Brute Force Golf Solver <usenet@tinita.de>
    Re: Brute Force Golf Solver <sfandino@yahoo.com>
    Re: Calling a WAV file <hideki@massassi.net>
    Re: Capturing STDOUT from Proc::Background processes on <goldbb2@earthlink.net>
    Re: Creating PDF files that include images (Mike Solomon)
    Re: FAQ proposal: Why can't I compare two strings using <nospam-abuse@ilyaz.org>
    Re: FAQ proposal: Why can't I compare two strings using <nospam-abuse@ilyaz.org>
    Re: FAQ proposal: Why can't I compare two strings using (Philip Lees)
    Re: How Do I Clone An Object (Anno Siegel)
    Re: moving sub routine to module (Mike Solomon)
    Re: Necessary modules? <edgue@web.de>
    Re: newbie question <Wayne.Plummer@NTLworld.com>
    Re: Newbie: Trouble with time() from "learning perl" bo (Villy Kruse)
    Re: Question about text processing <uri@stemsystems.com>
    Re: Question about text processing <newsfeed2@boog.co.uk>
    Re: Question about text processing <newsfeed2@boog.co.uk>
    Re: Question about text processing <uri@stemsystems.com>
    Re: regexp to *not* match a certain character sequence <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: regular expression question *NOT PERL-SPECIFIC* <jurgenex@hotmail.com>
    Re: regular expression question *NOT PERL-SPECIFIC* <someone@microsoft.com>
    Re: regular expression question *NOT PERL-SPECIFIC* <someone@microsoft.com>
    Re: regular expression question *NOT PERL-SPECIFIC* <someone@microsoft.com>
    Re: regular expression question *NOT PERL-SPECIFIC* <someone@microsoft.com>
        search algorithm needed (FMAS)
    Re: search algorithm needed <rev_1318@hotmail.com>
    Re: Silencing Default Error Output of getopts (Johan Vromans)
    Re: Top Perl jobs in the UK <newsfeed2@boog.co.uk>
    Re: Writing my own scripting language. Need advice. <sfandino@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 28 Feb 2003 00:33:46 -0800
From: willykk@my-deja.com (Willy Kreim)
Subject: "Achilles Members Area" cgi script & author....
Message-Id: <20a02d3.0302280033.698ea086@posting.google.com>

I'm badly needing this perl script called "Achilles Members Area":

--------------# Achilles Members Area
FREE - Platform(s): UNIX
Achilles Members Area is a password protected members area script that
does not use .htaccess, but instead uses Cookies. It includes a fully
functional Admin Area, sign up form, and built-in mailing list. You
can define what information you wish to collect from the members and
integrate it into all of your system.
--------------

As listed in
http://perlarchive.com/guide/search.cgi?so=DESC&query=achilles&catid=
and here
http://www.icthus.net/CGI-City/scr_passwd.shtml
and here:
http://216.239.57.100/search?q=cache:WvaUQDatdasC:www.scriptsearch.com/details/3449.html+%22achilles+members+area%22&hl=en&ie=UTF-8
and here:
http://w100w.com/english/perl/password_protection/

Unfortunatelly, all the smart-*sses that build those nifty "cgi script
indexes" only include POINTERs to the download links, they do not
cache any of the files.

So when a script provider disappears/dies/or whatever, the script is
gone forever!!. (cool, isn't it? NOT).

As you can see on archive.org, "ES Design", was indexed last time on
June 02, 2002, and the page is now gone from hypermart.net's servers.

The old page is here:
http://web.archive.org/web/20020528101309/http://esdesign.hypermart.net/

But sadly the download link was cgi-based so archive.org didn't save
the script files.

Any ideas of:

1) Where I could find this script (there were over 928 downloads of it
according to one of the above index-sites).
2) Who was and where is the author now?
3) Any similar scripts with this functionality that do NOT use htacess
and do not require mysql, just PHP?

Thanks
Willy


------------------------------

Date: Fri, 28 Feb 2003 14:16:10 +0800
From: hugo <hugo@geoinformex.com>
Subject: accessing functions from other perl programs
Message-Id: <3E5EFEAA.8080402@geoinformex.com>

Hi

I have a perl program which I can foresee becoming very large and so I 
thought of split up functions over several files.

However, I have to confess I have never understood very well how 
functions from one perl program can be accessed by another perl program 
  e.g. if I have:

someprogram.pl which contains

sub dosomething { code here... }

how do I access the function

dosomething {   }

from anotherprogram.pl ?

I know about using modules i.e.
use Win32::Process;

but how do you share functions between perl program? Stupid question 
perhaps but the documentation I found is not very clear and so I would 
much appreciate it very much if someone could explain the basics using 
some simple examples.

Thanks very much

Hugo



------------------------------

Date: Fri, 28 Feb 2003 09:16:40 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: accessing functions from other perl programs
Message-Id: <b3n6fe$1nocfk$1@ID-184292.news.dfncis.de>

hugo wrote:
> I have never understood very well how functions from one
> perl program can be accessed by another perl program

http://www.perldoc.com/perl5.6/pod/perlmod.html

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Fri, 28 Feb 2003 07:04:28 -0000
From: "Peter Cooper" <newsfeed2@boog.co.uk>
Subject: Re: Also religious: brackets
Message-Id: <GSD7a.7196$EN3.56352@newsfep4-glfd.server.ntli.net>

Uri Guttman wrote:
> the general rule about fewer lines of code means fewer bugs applies
> here. many studies have shown that bug count is directly correlated to
> line count and braces count as lines.
>
> next if /^$/ ;

That's actually a good example of where this syntax is useful. It's aided by the
shortness of the statement to be run, as well as how it reads in real English,
making it incredibly readable

> now, they have to be used properly. very long statement bodies and long
> conditionals can ruin their clarity. then switching to if blocks makes
> sense. but for the very common and short cases they are much better IMO
> than the equivilent block forms.

I would agree. I think that, perhaps, programmers have different ideas of how
long 'very long' would be. If it forces me to read more than 20 characters into
the line to work out if it's going to be run, I'd probably change it on personal
grounds of readability.

Compare:

#1  -- print "Error: $error Variable 1: $variable1 Variable 2: $variable2" if
$debug;

with:

#2  -- $debug && print "Error: $error Variable 1: $variable1 Variable 2:
$variable2";

I can't argue with whatever other people find easier to read, but for me it'd be
#2 every time. Of course, the key is for one to be consistent in how they go
about this otherwise any readability benefits are soon destroyed.

Cheers,
Pete




------------------------------

Date: Fri, 28 Feb 2003 00:21:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Anyway to do away with ?: in the map function
Message-Id: <3E5EF1E4.D130D796@earthlink.net>

Peter Shankey wrote:
[snip]
> map {
>  / values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/
>  ?($dbh->do("insert into customers values ( $1, $2, $3, $4 ) ")):()}
>  <DATA>;

How about:

   while( <DATA> ) {
      $dbh->do("insert into customers values ( $1, $2, $3, $4 ) ")
         if / values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/;
   }
      
-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


------------------------------

Date: 28 Feb 2003 10:34:43 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Brute Force Golf Solver
Message-Id: <tinhb0lx5$120$tina@news01.tinita.de>

Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:

> Is anyone holding any golf contests anymore, now that 
> perlgolf.sourceforge.net seems to have dropped off the planet?

well, there's minigolf now...
http://terje.perlgolf.org/

hth, tina

-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
http://www.tinita.de/peace/link.html - Spread Peace


------------------------------

Date: Fri, 28 Feb 2003 11:38:18 +0000
From: =?ISO-8859-1?Q?Salvador_Fandi=F1o_Garc=EDa?= <sfandino@yahoo.com>
Subject: Re: Brute Force Golf Solver
Message-Id: <3E5F4A2A.3090702@yahoo.com>



Quantum Mechanic wrote:
> Under the auspices of "There are no stupid questions"...
> 
> Has anyone done any work on a brute force golf solver?
> 
> I'm not very good at golf, but I like the idea of tinkering with a
> program that writes programs.
> 
> I envision a semi-intelligent program that knows about the most useful
> command line options, builtin functions and operators, and tries to
> generate valid (i.e., "perl -c") programs, runs them against test
> input, and validates the output against the expected output.

google for "machine learning" and "inductive programming"

Bye,

   - Salva



------------------------------

Date: Fri, 28 Feb 2003 15:26:46 +0900
From: "Hideki Ono" <hideki@massassi.net>
Subject: Re: Calling a WAV file
Message-Id: <b3mvbq$f6l$1@news.sfc.keio.ac.jp>

Why not just insert a tag that plays a sound?
Like, object or img with dynsrc attribute.

Assuming you already placed your WAV on the
server for the customer to download.

For me, sounds are annoying on web, but that's just my opinion.

"Jack Gray" <jgray1@twcny.rr.com> wrote in message
news:qTx7a.123508$Xr1.29923746@twister.nyroc.rr.com...
> Can anyone tell me how I can call up a WAV file in my CGI script?
>
> The senario is:
> Customer has NOT filled in a 'required' field. A PRINT message is
displayed
> but I also want to add a WAV file to alert the customer. Here is a brief
> snippet of the script:
>
> <td colspan="4"><h3>Please fill out the following form to request a
> quote:</h3>
>    <p style="font-weight: bold;"><font color="red">*</font>Required
> Fields</p></td>
>     </tr>
>     <tr>
>       <td width="10%">&nbsp;</td>
>       <td width="8%"><p style="font-weight: bold;"><font
> color="red">*</font>Name:</p></td>
>       <td width="60%"><input type="text" name="name" size="24" value =
> $in{'name'}></td>
>       <td width="22%"><p style="font-weight: bold; color: #ff0000">
> eoh
>
>  #Write out error message if email is missing
> if($in{'name'} eq "")
> {print "Please enter your name";}
> print <<"eoh";
>
> How can I edit this script to play the WAV?
>
> Thanks for the help!
> Jack
>
>



------------------------------

Date: Fri, 28 Feb 2003 00:37:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Capturing STDOUT from Proc::Background processes on Win32
Message-Id: <3E5EF5A9.EF02D057@earthlink.net>

"Dean J. Pompilio" wrote:
> 
> Hello,
> I have written a script using ActivePerl on Win2000 to tail error log
> files.  The output of these error logs needs to be sent in real time
> to a home-grown monitoring console.
> I have used Proc::Background to launch multiple "tail -F" commands
> whose output currently goes to stdout.  (Check out Cygwin for some
> great Unix-style tools on Windoze systems!)
> I have tried to capture the output stream of each process using
> filehandles and redirects to a file, but nothing seems to work yet.
> Ideally the "ERROR MESSAGE" text will be replaced by each line from
> the error log file.
> 
> Here is the relevant code:
> 
> sub launch_tail_process {
>         $tail = "\\\\radon\\binlib\\eops\\cygwin\\bin\\tail";
> 
>  $process = Proc::Background->new( "$tail -F $logfile" );

At this point, the $process global variable contains a Proce::Background
object, and the $tail program has been started.

>         push( @pids, $process->pid );

Here, you push the process id of the started tail program into @pids.

>         open( PROC, "$process |" ) or die "Can't read from $process:
> $!\n";

Here, you stringify the process object (which probably produces a string
like "HASH(0xcafebbe)=Proc::Backgroun"), and use that as the name of a
program to start, and you're trying to read from that program.

>         $error_out = print PROC;

Here, you print the $_ variable to the read-only handle PROC, and you
store into $error_out either a 0 or 1, depending on whether or not the
print succeeded (of course, since the PROC handle is read-only, printing
to it allways fails).


>         $gas_pushpin = '\\\\radon\\binlib\local\\gas_send -m
> $error_out';
> 
> }
> 
> I get an error saying "The Filename, directory name or volume label
> syntax is incorrect" when using the filehandle approach.  Any help is
> appreciated!!!

Well, assuming you're actually running cygwin (rather than running from
windows, but using a few tools from cgwin), then you could do:

use strict;
use warnings;
my $tail  = "//radon/binlib/eops/cygwin/bin/tail";
my $xargs = "//radon/binlib/eops/cygwin/bin/xargs";
my $gas   = "//radon/binlib/local/gas_send -m";
sub launch_process {
   my $logfile = shift;
   system("$tail -F $logfile | $xargs $gas &");
}
[untested]

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


------------------------------

Date: 28 Feb 2003 00:42:54 -0800
From: mike_solomon@lineone.net (Mike Solomon)
Subject: Re: Creating PDF files that include images
Message-Id: <56568be5.0302280042.6446fabd@posting.google.com>

Thanks for all your help I will have a look at PDF::API2

Regards


Mike Solomon



> > >> I nead to create PDF files using Perl
> > >> 
> > >> I have tried PDF::create which works but I can't include images using it.
> > >> 
> > >> Does anyone know how to do this
>  ...
> > I've just started using PDF::API2
> > 
> > it works great for creating PDF's, I've not aded an image yet, but the
> > documentation seems to be straight forward. 
> 
> use PDF::API2;
> 
> $pdf = PDF::API2->new(-file=>"filename.pdf");
> $page = $pdf->page($number);
> $gfx = $page->gfx;
> $img = $pdf->image("image.jpg");
> $gfx->image($img, 0, 100, 264, 68);
> $page->update;
> $pdf->update;
> 
> exit;
> 
> > If you are going to bedoing alot of this.
> > Perl Graphics Programing by O'Reilly, just came out it  is great
> > ISBN 0-596-00219-x
> 
> Oh, yeah.
> 
> Henry.


------------------------------

Date: Fri, 28 Feb 2003 07:43:46 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <b3n3vi$6u9$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Tore Aursand
<tore@aursand.no>], who wrote in article <pan.2003.02.27.12.52.48.701291@aursand.no>:
> >>   "Why doesn't my use of operator do what I excpect?"
> >>
> >> It's a problem with this one, though; a lot of people don't even _know_
> >> what an operator is. :-/
> 
> > Plus the average user wouldn't find this entry using "perldoc -q".
> > Typically you would search for "compare", "equal", maybe "string".
> 
> Hmm.  POD should really support keywords associated with each question.
> That way, the question could be as perfect as possible, while searching
> wuold be a lot easier.

Did you look in

  perldoc perlpod

?  Pay attention to X<>.

Ilya


------------------------------

Date: Fri, 28 Feb 2003 07:47:33 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <b3n46l$6v7$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Abigail 
<abigail@abigail.nl>], who wrote in article <slrnb5tb1c.nh4.abigail@alexandra.abigail.nl>:
> You shouldn't blindly add "use strict" to your program if you don't
> know what it means, just because someone in some newsgroup said so.
> 
> Turning on strictness does change the way Perl parses your program.
> That's something that shouldn't be taken lighthearted.

IMO, your statement should better be inverted.  One should not blindly
omit if they don't know what it means, just because someone in some
newsgroup said so.

Strictness+warnings should the default.  -e should be renamed to -E.
-e should be -E with appended 'no strict; no warning;'.

Hope this helps,
Ilya


------------------------------

Date: Fri, 28 Feb 2003 09:48:22 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <3e5f3030.70829718@news.grnet.gr>

On 27 Feb 2003 12:29:53 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>Philip Lees <pjlees@ics.forthcomingevents.gr> wrote in comp.lang.perl.misc:
>> On Thu, 27 Feb 2003 07:37:42 GMT, pjlees@ics.forthcomingevents.gr
>> (Philip Lees) wrote:
>> 
>> >NOTE: If you use warnings (as you should) then Perl will alert you to
>> 
>> Gak! I did it again. Of course, I meant 'perl'.
>
>I don't think "Perl" is wrong in this context.  It's a language feature.
>Lowercase "perl" is only needed when you're talking about the executable
>file (/usr/bin/Perl is obviously be wrong).

Would it perhaps be more correct so say that the warnings pragma is a
Perl feature, but the warnings themselves come from perl?

Phil
-- 
Ignore coming events if you wish to send me e-mail


------------------------------

Date: 28 Feb 2003 08:35:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How Do I Clone An Object
Message-Id: <b3n71b$f5k$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMCDLXVI
> September MCMXCIII in <URL:news:b3jc9r$fa0$1@mamenchi.zrz.TU-Berlin.DE>:
> ??  
> ??  This clone routine will have to be changed (or at least checked) whenever 
> ??  the underlying object structure changes.  For a more general (but probably
> ??  less efficient) approach, a module can be used.  I'm not sure if there's
> ??  a dedicated deep-copy module (which is what you're looking for), but
> ??  Data::Dumper and similar serialization modules do a good job.  You
> ??  basically dump the object to a string and immediately restore it again.
> ??  The restored object will be a perfect clone of the original (blessed and
> ??  all).  This way you can change the object structure whichever way you
> ??  want, the clone method will automatically adapt.
> 
> 
> Eh, no. It all depends on how you create your objects. There is no
> general way of cloning objects in Perl (which is ill defined anyway,
> if an attribute is a reference, should the attribute of the clone
> reference the same data, or a copy of the data?).

True.  I should have said "deep copy" instead of "clone".  In general
these are not the same thing.

Anno


------------------------------

Date: 28 Feb 2003 00:56:41 -0800
From: mike_solomon@lineone.net (Mike Solomon)
Subject: Re: moving sub routine to module
Message-Id: <56568be5.0302280056.40c2d565@posting.google.com>

Tad,


That is exactly what I was looking for

Thanks very much


Regards


Mike Solomon





> 
> > I have a little sub routine I use for debugging and I want to put it
> > into a module rather than in each script
> > 
> > The problem I have is that the module needs to know the debug flag I
> > have set in the script and the file I have opened to write the
> > debugging information to
> 
>    perldoc -q filehandle
> 
>       "How can I make a filehandle local to a subroutine?  
>        How do I pass filehandles between subroutines?  
>        How do I make an array of filehandles?"
> 
> 
> > #test.pl
>  
> > my $g_debug = "Y";		#set debug status
> 
> 
>    our $g_debug = "Y";
> 
> 
> > open DEBUG, ">debug/exib_detail.txt" if $g_debug eq "Y";
> 
> 
>    open our $DB, ">debug/exib_detail.txt" if $g_debug eq "Y";
> 
> 
> > my $g_time = localtime;	#used with debug
> > &Debug($g_time);
> 
> 
>    Debug($g_time);
> 
> 
> > #testmodule.pm
> > package testmodule;				#declare package
> 
> 
> All lower-case module names are reserved for pragmas by convention.
> 
> Use at least one upper case char in your module's name.
> 
> 
> > sub Debug {
> > 	#debug routine
> > 	my ($text) = @_;
> > 	print DEBUG "$text\n" if $g_debug eq "Y";
> > } #end Debug
> 
> 
>    sub Debug {
>        return unless $main::g_debug eq "Y";
>        my ($text) = @_;
>        print $main::DB "$text\n";
>    } #end Debug


------------------------------

Date: Fri, 28 Feb 2003 08:44:34 +0100
From: Edwin Guenthner <edgue@web.de>
Subject: Re: Necessary modules?
Message-Id: <3E5F1362.5080406@web.de>



Abigail wrote:


> Alternatively, one could just inspect %INC. 
> Just stuff
> 
>     CHECK {print "$_\n" for keys %INC}

I have decided to concentrate on the other side:
I was told to check out the .a in the Perl\lib
directories - and to see what I might want to
omit there.
Encoding looks like a very good starting point.
It costs 3 megs - but my programm is only dealing
with simple ASCII files; so no need for strange
encodings.



------------------------------

Date: Fri, 28 Feb 2003 07:56:37 -0000
From: "Wayne Plummer" <Wayne.Plummer@NTLworld.com>
Subject: Re: newbie question
Message-Id: <TCE7a.7218$EN3.56315@newsfep4-glfd.server.ntli.net>

"Ryan Shondell" <shondell@cis.ohio-state.edu> wrote in message
news:xcw7kblozp2.fsf@psi.cis.ohio-state.edu...
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> writes:
> > Ryan Shondell <shondell@cis.ohio-state.edu> wrote in
> > > foreach my $index (@var) {
> > >   print $index;
> > > }
> > Nitpick:  In this case, $index is a very poor choice of variable name,
as
> > the variable takes on the *values* of the array in turn, not the
*indexes*.
> Yeah, you're absolutely correct. Sometimes the synapses fire sideways,

Nitpick^2 :-)

But he's not "absolutely correct", is he? $index doesn't just take on the
*values*,
it *becomes* each element of the array in turn. This is important to
remember...
if you change the value of $index (or whatever other name you've chosen)
within
the foreach loop, you really are changing the current element within the
array!

Wayne.




------------------------------

Date: 28 Feb 2003 09:00:50 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Newbie: Trouble with time() from "learning perl" book example...please help explain?
Message-Id: <slrnb5u9a2.3j5.vek@station02.ohout.pharmapartners.nl>

On 27 Feb 2003 08:56:49 -0800,
    cayenne <chilecayenne@yahoo.com> wrote:


>
>The time entered is: 1046364804
>
>This doesn't appear to be the time in seconds as the example alluded
>to. Can someone explain what format this time is...and how to
>parse/manipulate it so that elapsed hours can be established?
>


$ perl -e 'print scalar localtime 1046364804;'
Thu Feb 27 17:53:24 2003


Villy


------------------------------

Date: Fri, 28 Feb 2003 06:00:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Question about text processing
Message-Id: <x7fzq9aqrg.fsf@mail.sysarch.com>

>>>>> "PC" == Peter Cooper <newsfeed2@boog.co.uk> writes:

  PC> Hi Uri,

  PC> "Uri Guttman" <uri@stemsystems.com> wrote...
  >> you should keep attributions with the stuff you quote.

  PC> The References header was accurate enough to attribute it to your
  PC> previous post, but if it makes you happy.. :-)

that isn't the point. if someone else (or their news server) deleted my
post, then the references wouldn't be of any use. so keeping
attributions is a good idea in general. makes it easier to know who you
are flaming^Wcorrecting. :)

  PC> s/\s+/\s/g;
  >> 
  >> then you tend to be wrong. the replacement part of s/// is a double
  >> quotish string and not a regex. \s is not meaningful there.

  PC> Okay, I must apologise. Fool on me for not actually bothering to
  PC> reread what I posted ;-) I am clearly the type who must double
  PC> check his code :-) I'd still shoot through with a s/\s+/\ /g;

why the \ before the space? not needed unless the /x option is on.

  PC> though, as opposed to the tr method. But I believe I have good
  PC> reason for this.. and I'd be interested to hear if you have any
  PC> disagreements or suggestions. After all, we're all still learning
  PC> things from time to time.

  PC> So why? Because I find doing a 'translation' where you really want
  PC> to do a 'substitution' a clumsy syntax, whether it's the approved
  PC> way or not.


  PC> tr, by its very name, was designed to /translate/ certain
  PC> characters into other characters. It does not, generally,
  PC> /substitute/ multiple characters into single ones, or vice
  PC> versa. When doing a substitution, I'd rather stick with the
  PC> function named after this process, than rely on a modifier on a
  PC> seemingly unrelated term, if not for anyone else's readability but
  PC> my own. What is your thought on this?

you need the /g option for s/// to work. so what is wrong with the /s
option on tr?

tr translates chars to other chars. but the replacement side can be
shorter than the search side. the last char is duplicated so they are
the same length.

	tr/ \r\n\t/    /
	tr/ \r\n\t/ /

those are the same and convert all to blanks. the /s option is very neat
and it [S]queezes all duplicate replaced chars to a single instance.

  >> tr is also faster as it is designed for single char operations.

  PC> But this isn't a single character operation, it involves
  PC> substituting multiple characters for a single one.

note that can be done in a simple tight char loop. as you build up the
translated string, you track the previous char (if translated) and if
the same, skip it. so it is still a single char to char translation.

  PC> The s version can also be hacked to compress all whitespace
  PC> down.. as in..  s/(\s|\n|\r)+/\ /g; whereas doing the same with a
  PC> tr would mean each different type of whitespace is compressed down
  PC> separately, still leading to gaps? Correct me if I'm wrong (I
  PC> actually bothered to test this time!) but of course I guess it
  PC> depends what result you want!

nope. see the above.

	s/\s+/ /g
	tr/ \r\n\t/ /s

those do the exact same thing but tr will be much faster as it is
designed for single char stuff. s///'s loop is more complex and slower
since it is much more general purpose.

there is no requirement to use tr but why use a wrench to hammer a nail?
the wrench is more versatile but it isn't as effective as a hammer.

now another problem is trimming leading/trailing white space and this is
where tr fails as it can only work on the whole string and s/// can be
anchored. so my point is to use the tool that is most appropriate for
the job (depending on your definition of most appropriate)

  PC> Of course, this is what makes Perl so interesting. TMTOWTDI, as
  PC> you know! :-)

but some ways are (much) better than others. and some are just bad. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


------------------------------

Date: Fri, 28 Feb 2003 06:55:55 -0000
From: "Peter Cooper" <newsfeed2@boog.co.uk>
Subject: Re: Question about text processing
Message-Id: <7JD7a.7191$EN3.56325@newsfep4-glfd.server.ntli.net>

"Uri Guttman" <uri@stemsystems.com> wrote...
> why the \ before the space? not needed unless the /x option is on.

I've not found any problems with escaping spaces in this way, and I find it
helps my readability (/ / could be misread as //- especially in areas where I'm
not using monospaced fonts.. like on here). Of course, if it's likely to break
something, I'd have to stop ;-)

> now another problem is trimming leading/trailing white space and this is
> where tr fails as it can only work on the whole string and s/// can be
> anchored. so my point is to use the tool that is most appropriate for
> the job (depending on your definition of most appropriate)

I don't think the original poster gave us all the facts to be too accurate on
here, so your point is well taken!

> but some ways are (much) better than others. and some are just bad. :)

I wouldn't go so far as to say it's 'bad' though. Might be slower, but it makes
logical sense. BAD would be:

foreach $stripme (('\n', '\s', '\t')) {
  if (/$stripme/) { s/($stripme)+/$1/g; }
}

!! ;-)

Thinking of the most longwinded way of doing something can often be just as much
fun as the opposite <g>

Pete




------------------------------

Date: Fri, 28 Feb 2003 06:58:20 -0000
From: "Peter Cooper" <newsfeed2@boog.co.uk>
Subject: Re: Question about text processing
Message-Id: <oLD7a.7193$EN3.55983@newsfep4-glfd.server.ntli.net>

> Confront your fear. Save the whal^H^H^H^Hcycles.

I think quite a few programmers have functions they steer away from and which
they replicate in their own idiomatic way. I will have to make sure I use tr at
least a few times in the next week to do my bit for saving CPU cycles ;-)

Next week, I actually hold a snake.

Pete




------------------------------

Date: Fri, 28 Feb 2003 07:18:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Question about text processing
Message-Id: <x765r4c1q1.fsf@mail.sysarch.com>

>>>>> "PC" == Peter Cooper <newsfeed2@boog.co.uk> writes:

  PC> "Uri Guttman" <uri@stemsystems.com> wrote...
  >> why the \ before the space? not needed unless the /x option is on.

  PC> I've not found any problems with escaping spaces in this way, and
  PC> I find it helps my readability (/ / could be misread as //-
  PC> especially in areas where I'm not using monospaced fonts.. like on
  PC> here). Of course, if it's likely to break something, I'd have to
  PC> stop ;-)

you may not find problems but needlessly escaping stuff confuses the
readers of your code and most of those won't be you. you wrote code for
the maintainer to read and not for yourself (even if you are currently
the only maintainer you may not always be that).

coding rules:

	code is for people, not computers.

	code is for others, not yourself.

	code is what, comments are why.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


------------------------------

Date: Fri, 28 Feb 2003 07:34:18 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: regexp to *not* match a certain character sequence
Message-Id: <Xns9330567C6EBCBelhber1lidotechnet@62.89.127.66>

Bennett Haselton wrote:

> "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in
> message news:<Xns932F4E7093D07elhber1lidotechnet@62.89.127.66>... 
>> Bennett Haselton wrote:
>> 
>> > Pretty elementary I know, but I've read the sections about regular
>> > expressions in 3 Perl books and I can't find anything about how to
>> > match a string of characters that does not contain a given
>> > character sequence.  For example, if I have a string of the form:
>> > 
>> > <a href = "http://www.yahoo.com/">first link</a><a href =
>> > "http://www.peacefire.org/">This <b>might</b> work</a>
>> > 
>> > and I'm not sure whether or not the first link will be present, but
>> > I want to get the text of the second link, then how do I extract
>> > the 'This <b>might</b> work' part?
>> 
>> 
>> How about this:
>> 
>> 
>> $string =~ m!<a href[^>]+>(.*)</a>$!;
> 
> That doesn't seem to work, same problem as before:


It works for me:

---------
#!/usr/bin/perl
use warnings;
use strict;

my $string = '<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>';

$string =~ m!<a href[^>]+>(.*)</a>$!;

print "[$1]";
---------


This results in:  [This <b>might</b> work]


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



------------------------------

Date: Fri, 28 Feb 2003 05:21:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: regular expression question *NOT PERL-SPECIFIC*
Message-Id: <BlC7a.40572$ep5.11666@nwrddc02.gnilink.net>

Tad McClellan wrote:
> C3 <someone@microsoft.com> wrote:
>     ^^^^^^^^^^^^^^^^^^^^^
>     ^^^^^^^^^^^^^^^^^^^^^
>
> Are you "johnsmith"?

Nope.
Just someone who is too stupid to recognize an example and replace it with
real data.

BTW: it is a valid address. You may want to try to send an email to it. No,
you won't pester a real person but you should get a nice automated reply
telling you to use a real address.

jue




------------------------------

Date: Fri, 28 Feb 2003 20:22:15 +1100
From: "C3" <someone@microsoft.com>
Subject: Re: regular expression question *NOT PERL-SPECIFIC*
Message-Id: <3e5f2965$0$12820$afc38c87@news.optusnet.com.au>

Perhaps you'd want to consider that you in fact are the stupid one in this
case. Not only stupid, but prejudiced by a combination of zealoted elitism
and lack of sense of humour.

If you ever want to be taken seriously, I suggest you hold it back in
future.


C3

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:BlC7a.40572
> Just someone who is too stupid to recognize an example and replace it with
> real data.




------------------------------

Date: Fri, 28 Feb 2003 20:29:53 +1100
From: "C3" <someone@microsoft.com>
Subject: Re: regular expression question *NOT PERL-SPECIFIC*
Message-Id: <3e5f2b2f$0$12817$afc38c87@news.optusnet.com.au>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb5tqcm.26v.tadmc@magna.augustmail.com...
> The danger of assuming an alias is that someone else might have
> assumed the same alias, you live subject to someone _else's_ history...

Too bad this isn't even an 'alias'.

> Your address is scored down very steeply.

Oh no, what ever am I going to do, now?

> Consider choosing a different one.

Consider keeping your irrelevant and saturnine opinion to yourself.

By the way, I specified it in capital letters in the subject that I'm not
using perl.


C3




------------------------------

Date: Fri, 28 Feb 2003 20:31:54 +1100
From: "C3" <someone@microsoft.com>
Subject: Re: regular expression question *NOT PERL-SPECIFIC*
Message-Id: <3e5f2ba8$0$12819$afc38c87@news.optusnet.com.au>


"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3e5ee4a6.15184442@news.erols.com...
> A mite confusing.  "A maximum of 4 slashes" doesn't quite jibe with
> "only if they are 4 levels deep".  Do you mean at least four levels
> deap, at most four levels deep, or exactly four levels deep?

It's my fault for not clarifying this. What I meant was up to and including
4 layers (slashes).

> Should the regex match both of those strings, or just one of them?
> Which one?

Just the first one, ie host/la/di/da/image.gif


C3





------------------------------

Date: Fri, 28 Feb 2003 20:40:55 +1100
From: "C3" <someone@microsoft.com>
Subject: Re: regular expression question *NOT PERL-SPECIFIC*
Message-Id: <3e5f2dc5$0$12816$afc38c87@news.optusnet.com.au>

"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3E5EEED3.DC181524@earthlink.net...
> Almost right.  Change it to:
>
> ^host(/([^/]+){,4})$
>
> And it should work as you intend.

You are absolutely right. I can't believe I forgot this little detail.
Thanks :)


C3




------------------------------

Date: 27 Feb 2003 23:39:41 -0800
From: massion@gmx.de (FMAS)
Subject: search algorithm needed
Message-Id: <f0b3f4c9.0302272339.3ec5a9b6@posting.google.com>

Hi folks,

I have written a script to select examples for terms in an array of
phrases. This is to build up a dictionary and give context information
for the use of the terms.

This is the core of the script:

###############################################
	$limit = 0;
foreach $term (@term) {
	for($phrasecounter=0 ; $phrasecounter <= $#phrase ; $phrasecounter++)
{
	$phrase = $phrase[$phrasecounter];
	chomp $term;
	chomp $phrase;
if ($phrase =~ m/(.*)(\b$term\b)(.*)$/gi)
{
if ($phrase ne $phrase[$phrasecounter++]) {
	if ($limit < 2){  # here I can define how many examples I select for
one term
	print  "$term\t$phrase\n\n";
	$limit++;
}
}
}
}
 	$limit = 0;
}
###############################################

The script works fine with the exception that it gets extremly slow
when I have a large amount of terms and phrases. E.g. I have
collections of terms of up to 5,000 and of phrases of up to 20,000.
Currently it takes more than the complete night to do that job!

Does anyone have a suggestion as to how I could shorten the search
time substantially? Thanks in advance for the replies.


------------------------------

Date: Fri, 28 Feb 2003 10:07:21 +0100
From: "Paul van Eldijk" <rev_1318@hotmail.com>
Subject: Re: search algorithm needed
Message-Id: <pan.2003.02.28.09.07.20.304440@hotmail.com>

FMAS wrote:

> if ($phrase =~ m/(.*)(\b$term\b)(.*)$/gi)

lose the (.*) and the /g, they're useless. Also, don't user capturing if
you don't need it:

if ( $phrase =~ m/\b$term\b/i )

HTH
Paul



------------------------------

Date: 28 Feb 2003 10:28:19 +0100
From: jvromans@squirrel.nl (Johan Vromans)
Subject: Re: Silencing Default Error Output of getopts
Message-Id: <m23cm8n498.fsf@phoenix.squirrel.nl>

"Spero" <spero126NOSPAM@yahoo.com> writes:

> > $SIG{'__WARN__'} = sub {
> >         print "My error\n";
> > };
> 
> That's perfect, thank-you Alan. Why does it require the extra semi colon? It
> seems unusual.

It's just like 

  $SIG{__WARN__} = expr;

with "expr" being "sub { ... }". It is an expression, although
is _looks_ like a subroutine declaration.

-- Johan


------------------------------

Date: Fri, 28 Feb 2003 05:07:46 -0000
From: "Peter Cooper" <newsfeed2@boog.co.uk>
Subject: Re: Top Perl jobs in the UK
Message-Id: <K7C7a.7162$EN3.56035@newsfep4-glfd.server.ntli.net>

> ECM Selection Ltd - High-Tech Recruitment Specialists

Hardly 'top Perl jobs'. I did a search on your site and came up with 5 jobs that
mentioned Perl.. as footnotes.

That said, I guess the industry is a bit smaller than it used to be ;-) Is there
actually such a thing as a full time Perl-focused job?

Pete






------------------------------

Date: Fri, 28 Feb 2003 11:12:16 +0000
From: =?ISO-8859-15?Q?Salvador_Fandi=F1o_Garc=EDa?= <sfandino@yahoo.com>
Subject: Re: Writing my own scripting language. Need advice.
Message-Id: <3E5F4410.6000907@yahoo.com>



Tassilo v. Parseval wrote:

>>There are lots of languages out there that are still incomplete or a 
>>work in progress, and that will appreciate new programmers joining their 
>>development and that was going to be my initial advice to the OP, if you 
>>want to learn, look for one of those and try to help to its 
>>development... 
> 
> 
> Joining an existing project will teach you different things (still
> invaluable, for sure). You are currently busy with teaching Perl how to
> do assertions. But while doing it do you feel as though you are creating
> your own language?

no, but it wasn't my intencion either.


> Also, the current Perl5 development is a good example that joining is
> sometimes as hard as creating something new from scratch, given the
> complexity of the software. The 5.8.0's source distribution is over
> 50meg in size. It takes a year to understand the whole system before
> writing a single line of code.

Perl 5 is not a good example, Python being almost the same is much 
easier to understand (its source code, I mean), and anyway those are 
mature languages, but look at the programming languages sections on 
sourceforge, they sum up more than 1500 projects, there should be some 
good ideas there.


>>but the OP didn't really tell us why he wants to create a 
>>new language, if he just want some fun, if he wants to learn, if he has 
>>some new ideas, if it's for a project with a very specific requirements, 
>>etc., so I asked.
> 
> I strongly hope the reason is either learning or having fun because
> instant success is not to be expected by the OP. :-)

Looking at the OP background (C++, C#, PHP, VB, ASP and Java) 
frustration should also be considered ;-)

Bye,

   - Salva



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4640
***************************************


home help back first fref pref prev next nref lref last post