[17336] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4758 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 30 00:05:44 2000

Date: Sun, 29 Oct 2000 21: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)
Message-Id: <972882308-v9-i4758@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 29 Oct 2000     Volume: 9 Number: 4758

Today's topics:
    Re: $whatisthis = %hash (Mark-Jason Dominus)
    Re: Comparing two files (Mark-Jason Dominus)
    Re: Comparing two files (Mark-Jason Dominus)
    Re: Comparing two files <jeff@vpservices.com>
    Re: Comparing two files <peter.sundstrom@eds.com>
    Re: Comparing two files (Tom Christiansen)
    Re: Comparing two files <peter.sundstrom@eds.com>
    Re: Comparing two files (Mark-Jason Dominus)
    Re: Comparing two files (Mark-Jason Dominus)
    Re: Comparing two files <peter.sundstrom@eds.com>
        NT Web Server and Perl Interpreter Problems <D.Heley@bom.gov.au>
    Re: Pattern Match (Tad McClellan)
    Re: Pattern Match (DoC)
    Re: Perl message on Linux: Setting locale failed. (Mark-Jason Dominus)
    Re: split match and escaped characters. <uri@sysarch.com>
        Stop the window closing? <the_wizards_bullitin_board@barclays.net>
    Re: Stop the window closing? <jeff@vpservices.com>
    Re: truncating lines fallenang3l@my-deja.com
    Re: undef values removed from argument list? <uri@sysarch.com>
        What about CGI.pm? fallenang3l@my-deja.com
    Re: What about CGI.pm? <steve@dvd.net.au>
    Re: What about CGI.pm? (brian d foy)
    Re: What about CGI.pm? <jeff@vpservices.com>
    Re: what does /warn "$x" if "$x"/ mean (Martien Verbruggen)
    Re: Working with time (Chris Fedde)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 30 Oct 2000 02:05:43 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: $whatisthis = %hash
Message-Id: <39fcd776.6e81$13c@news.op.net>

In article <39FCD25C.A979FDE0@home.com>,
Wayne Collins  <collinw@mail.mohawkc.on.ca> wrote:
>I am sure it is of no practical use, I am just curious. Could anyone
>explain the output of this code.

man perldata says:

       If you evaluate a hash in scalar context, it returns false
       if the hash is empty.  If there are any key/value pairs,
       it returns true; more precisely, the value returned is a
       string consisting of the number of used buckets and the
       number of allocated buckets, separated by a slash.  This
       is pretty much useful only to find out whether Perl's
       internal hashing algorithm is performing poorly on your
       data set.  For example, you stick 10,000 things in a hash,
       but evaluating %HASH in scalar context reveals `"1/16"',
       which means only one out of sixteen buckets has been
       touched, and presumably contains all 10,000 of your items.
       This isn't supposed to happen.

Your output of "4/8" shows that the hash contains eight buckets, which
is the default, of which four contain data, one for each key.



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

Date: Mon, 30 Oct 2000 02:15:52 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Comparing two files
Message-Id: <39fcd9d8.6ee1$369@news.op.net>

In article <8ti92m$pl1$1@hermes.nz.eds.com>,
Peter Sundstrom <peter.sundstrom@eds.com> wrote:
>sub Filecmp {
>  my ($file1,$file2) = @_;
>
>  system("cmp $file1 $file2 >/dev/null");
>  return $?;
>}

Just FYI, 'cmp' has an option that you can give it that says that you
are only interested in whether there are differences, and not what
they are:

DESCRIPTION

     -s	   Print nothing for differing files; return exit status only.


        # returns true if they differ
        return system("cmp -s $file1 $file2");

>I'm unsure as to the best way to change the system call to a Perl
>equivalent. 

        use File::Compare;   # Standard since at least 5.004_04

        # returns true if they differ
        sub Filecmp {
          my $result = compare(@_);
          return !$result;
        }

If you want to know how it works, you have the source code for 
File::Compare::compare on your disk.



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

Date: Mon, 30 Oct 2000 02:17:54 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Comparing two files
Message-Id: <39fcda51.6eef$34d@news.op.net>
Keywords: deferring, little, penurious, pus


In article <39FCD085.64A15FD1@vpservices.com>,
Jeff Zucker  <jeff@vpservices.com> wrote:
>I'd imagine that the perl power tools diff would do what you want:


Peter Sundstrom wrote:
>> 
>> I'm not interested in what the differences are, only if the files
>> are the same or different.

I think Jeff was not reading very carefully.

But

        http://language.perl.com/ppt/src/cmp/

might be relevant.


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

Date: Sun, 29 Oct 2000 18:28:00 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Comparing two files
Message-Id: <39FCDCB0.19C3D39D@vpservices.com>



Mark-Jason Dominus wrote:
> 
> In article <39FCD085.64A15FD1@vpservices.com>,
> Jeff Zucker  <jeff@vpservices.com> wrote:
> >I'd imagine that the perl power tools diff would do what you want:
> 
> Peter Sundstrom wrote:
> >>
> >> I'm not interested in what the differences are, only if the files
> >> are the same or different.
> 
> I think Jeff was not reading very carefully.

Oops, at least I was close :-)

-- 
Jeff


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

Date: Mon, 30 Oct 2000 15:34:18 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Comparing two files
Message-Id: <8timtm$ccs$1@hermes.nz.eds.com>


Jeff Zucker <jeff@vpservices.com> wrote in message
news:39FCD085.64A15FD1@vpservices.com...
>
> Peter Sundstrom wrote:
> >
> > I'm using the following code to compare two files:
>
> I'd imagine that the perl power tools diff would do what you want:
>
>     http://language.perl.com/ppt/src/diff/diff.mjd

Thanks for that Jeff, but it's a bit of overkill for what I need.  I don't
care what the differences are, I just want to know if there are differences.
Looking at that code and looking at some of the sample code from 'perldoc -q
array', I've come up with the following code.  How does this look?

#!/usr/local/bin/perl -w
use strict;

open(FILE1,"a.dat") or die "Can not open a.dat $!\n";
open(FILE2,"b.dat") or die "Can not open b.dat $!\n";
my @file1=<FILE1>;
my @file2=<FILE2>;
close(FILE1);
close(FILE2);

if (Filecmp(\@file1,\@file2)) {
  print "Differences\n";
}
else {
  print "Same\n";
}

sub Filecmp {
  my ($f1,$f2) = @_;

  return 1 unless @$f1 == @$f2;

  for (my $i = 0; $i < @$f1; $i++) {
        return 1 if $f1->[$i] ne $f2->[$i];
  }

  return 0;
}





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

Date: 29 Oct 2000 20:53:31 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Comparing two files
Message-Id: <39fcf0bb@cs.colorado.edu>

In article <8timtm$ccs$1@hermes.nz.eds.com>,
Peter Sundstrom <peter.sundstrom@eds.com> wrote:
:Thanks for that Jeff, but it's a bit of overkill for what I need.  I don't
:care what the differences are, I just want to know if there are differences.
:Looking at that code and looking at some of the sample code from 'perldoc -q
:array', I've come up with the following code.  How does this look?

Like incredible overkill.

:#!/usr/local/bin/perl -w
:use strict;
:
:open(FILE1,"a.dat") or die "Can not open a.dat $!\n";
:open(FILE2,"b.dat") or die "Can not open b.dat $!\n";
:my @file1=<FILE1>;
:my @file2=<FILE2>;
:close(FILE1);
:close(FILE2);
:
:if (Filecmp(\@file1,\@file2)) {
:  print "Differences\n";
:}
:else {
:  print "Same\n";
:}
:
:sub Filecmp {
:  my ($f1,$f2) = @_;
:
:  return 1 unless @$f1 == @$f2;
:
:  for (my $i = 0; $i < @$f1; $i++) {
:        return 1 if $f1->[$i] ne $f2->[$i];
:  }
:
:  return 0;
:}

This would be incredibly faster to write, read, and execute:

    sub same_filedata {
	my($f1, $f2) = @_;
	-s $f1 == -s $f2 && `cat $f1` eq `cat $f2`;
    } 

That version is optimized for speed-of-writing. :-)  It takes about
50% the memory that your version does.

You could obviously tweak that.  But it's a *lot* faster to just
call cmp(1).  You were afraid of system calls.  Well, I'll tell you
this: I'm sure that cmp(1) will do its job using fewer system calls
than your code is going to end up making.

Yes, in fact, when run on two copies of my system's /etc/termcap,
your code makes 1603 system calls (on my system, of course).  Using
cmp(1), however, results in merely 46 system calls.  A ratio of 35
to 1 is not to be scoffed at.  So much for saving system calls!
Trapping into kernel space is not free.  Neither is doing it 1500
more times than you need to.

Then there's the small matter blowing up your process's core image
by quite a hefty number of megabytes as it loads, parses, and slings
into arrays the contents of two 600k files.  Do you know how wicked
that is?  cmp(1) expanded in core size to merely 36k for the same
job.  

I'll take 36k over 3-5 megabytes any day of the week.  Wouldn't
anyone?  It really seems like self-defeating madness not to.  All
this pessimal speed and size wasted in the quixotic pursuit of false
efficiencies.  Sheesh!  If you truly want your program to run big
and fat and clumsy and slow, then by all means, do what you're
doing.  This is the kind of performance pessimization that gives
Perl a bad name.  Perl is supposed to be fast, not bogged down to
the size and speed of a moribund beached whale inching its way along
the sand.

But if you're brain-washed into going that route, be aware of the
standard File::Compare module.  It is of course guilty of some of
the same performance concerns as voiced above, but at least you're
not reinventing a wheel that's already here.  Here's the example
of it from the Camel:

    use File::Compare;

    printf "fileA and fileB are %s.\n",
        compare("fileA","fileB") ? "different" : "identical";

    use File::Compare 'cmp';
    sub munge($) {
        my $line = $_[0];
        for ($line) {
            s/^\s+//;   # Trim leading  whitespace.
            s/\s+$//;   # Trim trailing whitespace.
        }
        return uc($line);
    }

    if (not cmp("fileA", "fileB", sub {munge $_[0] eq munge $_[1]} ) {
        print "fileA and fileB are kinda the same.\n";
    }


--tom


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

Date: Mon, 30 Oct 2000 16:54:39 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Comparing two files
Message-Id: <8tirkh$mft$1@hermes.nz.eds.com>


Mark-Jason Dominus <mjd@plover.com> wrote in message
news:39fcd9d8.6ee1$369@news.op.net...
> In article <8ti92m$pl1$1@hermes.nz.eds.com>,
> Peter Sundstrom <peter.sundstrom@eds.com> wrote:
> >sub Filecmp {
> >  my ($file1,$file2) = @_;
> >
> >  system("cmp $file1 $file2 >/dev/null");
> >  return $?;
> >}
>
> Just FYI, 'cmp' has an option that you can give it that says that you
> are only interested in whether there are differences, and not what
> they are:
>
> DESCRIPTION
>
>      -s    Print nothing for differing files; return exit status only.

I was aware of that, but I was playing safe in case it was on a system that
doesn't have the -s flag.
>
>
>         # returns true if they differ
>         return system("cmp -s $file1 $file2");
>
> >I'm unsure as to the best way to change the system call to a Perl
> >equivalent.
>
>         use File::Compare;   # Standard since at least 5.004_04
>
>         # returns true if they differ
>         sub Filecmp {
>           my $result = compare(@_);
>           return !$result;
>         }

Slaps hand firmly on forehead.  I can't believe I could miss something so
obvious.  However, I did look in the Perl Cookbook and did 'perldoc -q
compare' and didn't come up with File::Compare.  I obviously couldn't see
the wood for the trees.





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

Date: Mon, 30 Oct 2000 04:25:25 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Comparing two files
Message-Id: <39fcf834.71fc$1ce@news.op.net>
Keywords: America, Slovakia, Stella, embryonic


In article <39fcf0bb@cs.colorado.edu>,
Tom Christiansen <tchrist@perl.com> wrote:
>This would be incredibly faster to write, read, and execute:
>
>    sub same_filedata {
>	my($f1, $f2) = @_;
>	-s $f1 == -s $f2 && `cat $f1` eq `cat $f2`;
>    } 
>
>That version is optimized for speed-of-writing. :-)  It takes about
>50% the memory that your version does.
>
>You could obviously tweak that.  But it's a *lot* faster to just
>call cmp(1).  You were afraid of system calls.  Well, I'll tell you
>this: I'm sure that cmp(1) will do its job using fewer system calls
>than your code is going to end up making.


Through an amazing coincidence, I wrote an article about this
yesterday.  Then I thought I'd save it for the right opportunity.  I
had not expected the right opportunity to come along so soon.

Subject: On Forking
Organization: Plover Systems
Date: Sat, 28 Oct 2000 12:39:30 -0400
From: Mark-Jason Dominus <mjd@plover.com>

I have a program, MAKE_SLIDES, that takes a file that contains the
slides for a talk and splits it into many separate text files, one for
each slide.  Then MAKE_SLIDES runs Seth Golub's text2html on each text
file, and the result is the slides.

text2html is pretty slow; it takes one or two seconds per slide.  So I
recently added code that checks to see if each slide file has changed
since the last time the program was run, and runs the slow text2html
step only if the slide has changed.

The first cut at the code looked like this:

        if (! -e ".bak/$filename" 
            || system("cmp -s $filename .bak/$filename")) {
          print STDERR "*";
          push @SLIDES, $filename;
        }

@SLIDES is the list of slide files that have text2html run upon them later.

I showed this to folks on IRC, and their immediate response was
"That's going to be slow, you should have it compute a hash of the
file and keep it in memory and compare hashes."

I replied that the entire run of MAKE_SLIDES took 1.5 seconds before,
and with the addition of 155 calls to 'cmp' it now took about 2.5
seconds, so I was not really interested in spending a lot of time and
effort writing code to maintain a database of hash fingerprints just
to save one second per run.

But people just couldn't accept this.  They continued to argue against
my code for quite a while.  I don't remember the arguments, because
they didn't make any sense to me, but the gist of it was that it is
expensive to fork so many subprocesses for something that Perl could
do internally.  I had a lot of trouble getting across the point that I
really didn't care, that in this case it was like paying ten cents for
a nickel candy bar.  Maybe I'm being charged twice the correct price,
but it's only a nickel, and I don't eat that much candy.

This sort of thing comes up in the newsgroups too.  A lot of people
have a funny blind spot about doing everything in Perl and not calling
any expternal programs.  Like everything else, what is approrpiate
depends on the circumstances.

Here's a counterexample: I taught a refresher class in introductory
Perl for a corporate client last spring.  During the lab after I had
discussed hashes, one of the students came to me with an exciting
idea.  She had a program that retrieved a list of identifiers from a
database, and which needed to decide which identifiers were present in a text
file.  She had been doing

        if (system("grep $IDENTIFIER datafile") == 0) {
          # identifier is present
          ...
        }

in a loop for every identifier.  Her idea was that if she loaded the
data file into a hash, she would be able to change this to 

        if ($datafile{$IDENTIFIER}) {
          # identifier is present
          ...
        }

and the program might get faster.  I said she might be correct.  She
made the change, and the running time of the program went from several
minutes to several seconds.  The student was overjoyed.

My points here are:

1. We like to hold up Perl as a rapid prototyping language.  Shell
   calls are good for that.

2. Then we like to say "And sometimes the result is so fast that you
   don't have to throw away the prototype."  In my opinion, this is
   one of the big wins of Perl as a protoyping language.  Lots of
   people worked very hard to make this true.  If we insist on
   throwing away the prototype anyhow, we are squandering a precious
   treasure.

3. People need to solve their problems in diffferent ways.  If we
   become too dogmatic about the advice we give people, and waste
   their time insisting (for example) that they eliminate shell calls
   from their programs, we are not going to be a useful support
   community for people who use Perl.  They may drift away to other
   languages whose proponents are more in touch with reality.



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

Date: Mon, 30 Oct 2000 04:37:34 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Comparing two files
Message-Id: <39fcfb0d.7259$7d@news.op.net>
Keywords: brake, bugging, facilitate, negate

In article <8timtm$ccs$1@hermes.nz.eds.com>,
Peter Sundstrom <peter.sundstrom@eds.com> wrote:
>I've come up with the following code.  How does this look?

I sort of wonder why you wrote this really bad code instead of using
something more like the shorter and better code I showed you.

I guess it's out of my hands now though.



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

Date: Mon, 30 Oct 2000 17:12:26 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Comparing two files
Message-Id: <8tisln$ogc$1@hermes.nz.eds.com>


Tom Christiansen <tchrist@perl.com> wrote in message
news:39fcf0bb@cs.colorado.edu...
> In article <8timtm$ccs$1@hermes.nz.eds.com>,
> Peter Sundstrom <peter.sundstrom@eds.com> wrote:
> :Thanks for that Jeff, but it's a bit of overkill for what I need.  I
don't
> :care what the differences are, I just want to know if there are
differences.
> :Looking at that code and looking at some of the sample code from
'perldoc -q
> :array', I've come up with the following code.  How does this look?
>
> Like incredible overkill.

I figured as much.

[snipped overkill code]

> This would be incredibly faster to write, read, and execute:
>
>     sub same_filedata {
> my($f1, $f2) = @_;
> -s $f1 == -s $f2 && `cat $f1` eq `cat $f2`;
>     }

But that's cheating.  I need my code to work on Unix and NT without having
to install something like Cygwin tools.

>
> That version is optimized for speed-of-writing. :-)  It takes about
> 50% the memory that your version does.
>
> You could obviously tweak that.  But it's a *lot* faster to just
> call cmp(1).  You were afraid of system calls.  Well, I'll tell you
> this: I'm sure that cmp(1) will do its job using fewer system calls
> than your code is going to end up making.

I don't disagree with that.

>
> Yes, in fact, when run on two copies of my system's /etc/termcap,
> your code makes 1603 system calls (on my system, of course).  Using
> cmp(1), however, results in merely 46 system calls.  A ratio of 35
> to 1 is not to be scoffed at.  So much for saving system calls!
> Trapping into kernel space is not free.  Neither is doing it 1500
> more times than you need to.
>
> Then there's the small matter blowing up your process's core image
> by quite a hefty number of megabytes as it loads, parses, and slings
> into arrays the contents of two 600k files.  Do you know how wicked
> that is?  cmp(1) expanded in core size to merely 36k for the same
> job.

The maximum size of files that I'll be working with are 5K.

>
> I'll take 36k over 3-5 megabytes any day of the week.  Wouldn't
> anyone?  It really seems like self-defeating madness not to.  All
> this pessimal speed and size wasted in the quixotic pursuit of false
> efficiencies.  Sheesh!  If you truly want your program to run big
> and fat and clumsy and slow, then by all means, do what you're
> doing.  This is the kind of performance pessimization that gives
> Perl a bad name.  Perl is supposed to be fast, not bogged down to
> the size and speed of a moribund beached whale inching its way along
> the sand.

And I'm here to be enlightened and to turn the beached whale into a super
slick dolphin.

>
> But if you're brain-washed into going that route, be aware of the
> standard File::Compare module.  It is of course guilty of some of
> the same performance concerns as voiced above, but at least you're
> not reinventing a wheel that's already here.

Unfortunately, I missed this obvious answer before I posted.




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

Date: Mon, 30 Oct 2000 14:56:22 +1000
From: "David Heley" <D.Heley@bom.gov.au>
Subject: NT Web Server and Perl Interpreter Problems
Message-Id: <ql6L5.21$qs6.2929@vic.nntp.telstra.net>

NT Web Server and Perl Interpreter Problems

We are trying to get the Perl interpreter running on our NT web server,
however with limited success. David McElhinney has a functional system on
his test web server, developed some time ago. We are trying to emulate his
web server / Perl configuration on our own NT server. My knowledge in this
area is extremely limited. The web server we are running is a later
version than his, but even when we previously tested it on the same version
web
server, we had similar problems.

My gut feeling is that it may have something to do with permissions and
Perl interpreter association with Perl scripts by the web server, however I
am
by no means certain. It may be something quite fundamental, however due to
my limited knowledge, I cannot yet determine this. David is only in town for
this week, so we are desperately trying to get this operational within this
time frame.

When we submit the form it just seems to hang. Basically this form is
supposed to interact with the perl script which I believe then sends off
an email using WindMail.exe on the NT server.


Latest release is build 618, based on Perl 5.6.0.   installed on Windows NT
server BMTCBAK1   It seems that some of the samples with this version of
Perl seem to run properly. However, your test script still fails to run.
It's reassuring that the interpreter seems at least in part, to be
interacting with the IIS web server.

PERL SCRIPT TEST RESULTS

Key Factors

WEB Browsers type IE5 and versions 5.0, 5.01, 5.5
WEB Server type and version - IIS 4
Perl Type and version - build 618, based on Perl 5.6.0.     Active Perl

Observations when testing  samples

1.  When running IE5  v 5.01 on Web server all the Perl samples seem to run
fine.

2.  When running IE5  v 5.5 on my NT workstation to the Web server none of
the samples work properly.

3.  When running IE5  v 5.0 on another NT workstation to the Web server none
of the samples work properly.

4.  When running IE5  v 5.5 on the Web server all except the Mouse Move,
Perl samples seem to run fine.


These results suggest to me a number of things.

1. An issue with security or pathing for remote client web browsers may
possibly exist.

2. The web browsers own ability to interperate Perl may vary.

Any assistance appreciated.

David
Melbourne
Australia

Any assistance most deeply appreciated.
30 October 2000




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

Date: Sun, 29 Oct 2000 21:15:21 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Pattern Match
Message-Id: <slrn8vpmdp.2uq.tadmc@magna.metronet.com>

On Sun, 29 Oct 2000 18:58:35 -0500, Tad McClellan <tadmc@metronet.com> wrote:

>$string =~ s/(>.*?)6(.*?<)/"$1" . "15$2"/eg;
>#$string =~ s/(>.*?)6(.*?<)/"${1}15$2"/g;   # evals are slow (and dangerous)
                             ^        ^
                             ^        ^

Errr, I forgot to take those out.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 30 Oct 2000 04:53:58 GMT
From: doc@CONSORTIUM.RedBrick.DCU.IE (DoC)
Subject: Re: Pattern Match
Message-Id: <slrn8vprvm.1ftq.doc@Enigma.RedBrick.DCU.IE>

Tad McClellan said this: 
>On 30 Oct 2000 01:05:32 GMT, DoC <doc@CONSORTIUM.RedBrick.DCU.IE> wrote:
>>Clay Irving said this: 
>>>On Sun, 29 Oct 2000 13:06:17 -0800, HappyHippo <thalion@wonderd.com> wrote:
>>>
>>>>I'm working a script that does some replacements to words
>>>>in a string, but I dont want it to replace words inside of html tags.
>
>>>>how could I do this so that it wouldnt match
>>>>the strings inside of < > chars?
>
>
>>Try turning the problem round. You're trying to find strings NOT inside < and
>>the > symbols. It's easier to match positively here, so try matching string
>>between > and <. In well-formed HTML it'll always be the case, as you always
>                     ^^^^^^^^^^^^^^^^
>>have opening and closing tags.
>
>
>What does that term mean?
>

Perhaps it was the wrong term to use. i meant it in that you're working with a
HTML document, that has opening and closing <HTML> tags, and the like, and
therefore would not have issues with strings not being between > and < (i.e.
you won't have a string after the </HTML> tag.).

>
>>$string =~ s/(>.*?)6(.*?<)/"$1" . "15$2"/eg;
>
>-------------------
>#!/usr/bin/perl -w
>use strict;
>
>my $string =<<ENDHTML;
><p>no six here</p> <a href="6pigs.com">Pigs home page</a>
>
><img src="pigs.jpg" alt=">>6 pigs<<">
><!-- <p>6 pigs</p> -->
>ENDHTML
>
>$string =~ s/(>.*?)6(.*?<)/"$1" . "15$2"/eg;
>#$string =~ s/(>.*?)6(.*?<)/"${1}15$2"/g;   # evals are slow (and dangerous)
>
>print $string;
>-------------------
>
These are exceptions, where the above regex will break. However, it was a
clear improvement on the previous one posted.

>Parsing HTML with a regex is hopeless.
>
>Use a module that parses HTML.
>
Overhead. Parsing a simple component of a HTML document like described above
can be done with a regex or multiple regexes.

	- DoC.


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

Date: Mon, 30 Oct 2000 02:10:08 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Perl message on Linux: Setting locale failed.
Message-Id: <39fcd87f.6ec4$3e6@news.op.net>

In article <39FC8A95.DB54F8F6@that.you>, Anastasia  <quit@that.you> wrote:
>I've had this problem for a while.  Some international settings have
>bien corrupted in my Linux box and I'm trying to repair it with no luck.

If you need to repair the corrupted locale settings on your linux box,
you must ask in a Linux newsgroup.

Sorry I can't be more helpful.


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

Date: Mon, 30 Oct 2000 04:33:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: split match and escaped characters.
Message-Id: <x7em0zj6cv.fsf@home.sysarch.com>

>>>>> "TLS" == Tony L Svanstrom <tony@svanstrom.com> writes:

  TLS> If the string is: "a@b@\@@d", then how the heck to I split on all
  TLS> non-escaped @s? Ie, how do I avoid the "@" in "\@" to be viewed as a
  TLS> separator, too?

many solutions but one is negative lookbehind

split /(?<!\\)@/

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Mon, 30 Oct 2000 02:57:50 -0000
From: "Newbie" <the_wizards_bullitin_board@barclays.net>
Subject: Stop the window closing?
Message-Id: <39fce468@news.jakinternet.co.uk>

Ive installed perl on my local machine and every time I run a perl script
it flashes by in a flash.
How can I keep the page open to view the results?
win 98
using Active Perl.

Thanks for any help




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

Date: Sun, 29 Oct 2000 19:46:21 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Stop the window closing?
Message-Id: <39FCEF0D.A93EC121@vpservices.com>

Newbie wrote:
> 
> Ive installed perl on my local machine and every time I run a perl script
> it flashes by in a flash.
> How can I keep the page open to view the results?
> win 98
> using Active Perl.

1. click on start menu
2. click on run
3. type "command" and press enter

A DOS console box will open, in the box:

4. cd to the directory containing the script
5. type perl srciptname, press enter

Eventually, just make yourself a shortcut to the DOS console box and
open it as your command line for testing scripts.

-- 
Jeff


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

Date: Mon, 30 Oct 2000 02:39:47 GMT
From: fallenang3l@my-deja.com
Subject: Re: truncating lines
Message-Id: <8tin1i$i0a$1@nnrp1.deja.com>

$my_variable =~ tr/ /\n/;

In article <Pine.LNX.4.10.10010271142060.7743-100000@nims.wr.usgs.gov>,
  Chris Coffey <ccoffey@nims.wr.usgs.gov> wrote:
> What I want to do is this.  I need to create output from a file such
that
> if there is a space, a line feed will be performed, so each word will
have
> there own line.  Example:  this is a line
>
> this
> is
> a
> line
>
> This is probably such a stupid question, but I just can't think how
to do
> it.  Thanks.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 30 Oct 2000 04:10:12 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: undef values removed from argument list?
Message-Id: <x7lmv7j7ff.fsf@home.sysarch.com>

>>>>> "DC" == David Coppit <newspost@coppit.org> writes:

  DC> I though this:
  DC>   return;
  DC> and this:
  DC>   return undef;
  DC> were equivalent, but they're not:

well you though(t) wrong. they are not the same at all.

plain return is context sensitive and returns () (the empty list) in a
list context and undef in a scalar context.

return undef actually returns a single undefined value in either context.

  DC> print "undefined\n" unless defined bar();
scalar context so that is undefined
  DC> foo(bar());

that is now a list context (provided by the param list to foo()). so the
plain return returns () which is why there is no count to @_ in foo().

  DC> print "undefined\n" unless defined baz();
  DC> foo(baz());

  DC> sub bar { return; }
  DC> sub baz { return undef; }
  DC> sub foo { print "Arg list size is: " . $#_ . "\n"; }
  DC> ----------------

  DC> This script prints:
  DC> undefined
  DC> Arg list size is: -1

because there were no args to foo().

  DC> undefined
  DC> Arg list size is: 0

because you passed a single undef to foo().

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Mon, 30 Oct 2000 02:35:07 GMT
From: fallenang3l@my-deja.com
Subject: What about CGI.pm?
Message-Id: <8timos$hn8$1@nnrp1.deja.com>

So is there a point in loading the entire CGI.pm module if all one
needs to do is read the query string and bake cookies? I am making a
CGI script where performance is an issue and I would like to load and
spit out html as fast as possible. Will loading CGI.pm affect the load
time significantly? That module is over 200 kb in size so I figure it's
a real hog.


In article <slrn8vph1t.ac5.mgjv@martien.heliotrope.home>,
  mgjv@tradingpost.com.au wrote:
> On Mon, 30 Oct 2000 11:02:51 +1100,
> 	Steve <steve@dvd.net.au> wrote:
> > Hey again,
> > 	With perl, if you've written a fair few packages to store your
> > procedures in, Perl has to load them up each time a script is
called and
> > compile them at runtime. If you have a 20k package for instance and
you
> > only want to access a 4 line function in there, why does it need to
load
> > up the whole package? How can you just enforce it to open up the
> > specific function?
>
> You could use the AutoLoader
>
> # perldoc AutoLoader
>
> and also have a look at
>
> # perldoc SelfLoader
> # perldoc AutoSplit
>
> > Will this make my scripts run quicker?
>
> Marginally, maybe. If your script spends 75% of its time loading code
> that it's never going to use, yes, it will be faster. If your script
> spends 0.1 % of its time loading code it never uses, you won't notice
> the difference.
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | Little girls, like butterflies, need
> Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
> NSW, Australia                  |
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 30 Oct 2000 14:08:35 +1100
From: Steve <steve@dvd.net.au>
Subject: Re: What about CGI.pm?
Message-Id: <39FCE633.4E19FD01@dvd.net.au>

fallenang3l@my-deja.com wrote:
> 
> So is there a point in loading the entire CGI.pm module if all one
> needs to do is read the query string and bake cookies? I am making a
> CGI script where performance is an issue and I would like to load and
> spit out html as fast as possible. Will loading CGI.pm affect the load
> time significantly? That module is over 200 kb in size so I figure it's
> a real hog.

My point exactly. If all you want to do is parse the query string and
you are using a Unix based server then you can simply work with
$ENV{QUERY_STRING} and parse it yourself if need be.

Others may have different suggestions.

Cheers,
Steve


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

Date: Sun, 29 Oct 2000 22:16:06 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: What about CGI.pm?
Message-Id: <brian-ya02408000R2910002216060001@news.panix.com>

In article <8timos$hn8$1@nnrp1.deja.com>, fallenang3l@my-deja.com posted:

> So is there a point in loading the entire CGI.pm module if all one
> needs to do is read the query string and bake cookies?

use a lighter module such as CGI::Request or CGI::Cookie if you
don't want the cruft.  see CPAN for details:

   http://search.cpan.org

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Sun, 29 Oct 2000 19:37:23 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: What about CGI.pm?
Message-Id: <39FCECF3.FC191780@vpservices.com>

fallenang3l@my-deja.com wrote:
> 
> So is there a point in loading the entire CGI.pm module if all one
> needs to do is read the query string and bake cookies? 

AFAIK, the module is fairly smart about which parts of itself it loads
for which purposes.

> I am making a
> CGI script where performance is an issue and I would like to load and
> spit out html as fast as possible. Will loading CGI.pm affect the load
> time significantly? That module is over 200 kb in size so I figure it's
> a real hog.

I am not sure this is the way to test that but to indicate the order of
magnitude of the "problem", this script runs at a rate of 32.57 runs of
the subroutine per second on an 800mhz pentium III:

  #!/usr/local/bin/perl
  use Benchmark;
  Benchmark::timethis( 100,
     sub { do 'CGI.pm'; my $q=new CGI; print $q->header; }
  );


-- 
Jeff


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

Date: Mon, 30 Oct 2000 15:53:46 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: what does /warn "$x" if "$x"/ mean
Message-Id: <slrn8vpvmq.ac5.mgjv@martien.heliotrope.home>

On Sun, 29 Oct 2000 19:01:51 -0500,
	Tad McClellan <tadmc@metronet.com> wrote:
> On Mon, 30 Oct 2000 07:44:11 +1100, Martien Verbruggen 
>    <mgjv@tradingpost.com.au> wrote:
> >On Sun, 29 Oct 2000 08:07:26 -0500,
> >	Tad McClellan <tadmc@metronet.com> wrote:
> >> >When I say I wrote, I meant I
> >>                      ^^^^^^^
> >> >take responsiblilty for it, not credit. 
> >> 
> >> 
> >> Then it is fine to write that when you are writing to yourself.
> >> 
> >> When writing to others however, you should write so that *they*
> >> will understand it correctly.
> >
> >`When I use a word,' Humpty Dumpty said in rather a scornful tone, `it
> >means just what I choose it to mean -- neither more nor less.' 
> 
> Hmmm. Let me rephrase my statement then:
> 
>    When writing to others however, you should write so that *they*
>    will understand it correctly (or, say it three times so as to
>    make it true)

heh, yes, of course, that will work too.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Mon, 30 Oct 2000 04:50:33 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Working with time
Message-Id: <t67L5.7$Bf7.170632704@news.frii.net>

In article <8tij4d$f25$1@nnrp1.deja.com>, Mario  <diab.lito@usa.net> wrote:
>In article <39fc1449$1@nexus.comcen.com.au>,
>  "Kiel Stirling" <taboo@comcen.com.au> wrote:
>>
>> Is there an easy way to subtract time ?
>>
>> well what I meen is if I had an end time of 13:59:00 hours
>> and a period of 02:48:20 hours is there an easy way to get the
>> start time ??
>>
>I don't know of a single command to do this but I am a newbie.I would
>use something like this.
>

Consider what happens when the endtime in Mario's code is set to
0:59:00. Beyond this and and a few other idiomatic issues, you
might also want to have code that understands other odd boundary
case issues like transitions to and from daylight savings time.

There are several modules in CPAN to choose from. I've used
Time::ParseDate, Date::Manip, and the venerable Date::Calc for work
like this.  There are several other choices that might also be
worth considering.

YMMV
chris
-- 
    This space intentionally left blank


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4758
**************************************


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