[28856] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 100 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 2 21:06:15 2007

Date: Fri, 2 Feb 2007 18:05:13 -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, 2 Feb 2007     Volume: 11 Number: 100

Today's topics:
    Re: :) <bik.mido@tiscalinet.it>
        how to get recipient of email jcharth@hotmail.com
    Re: HTML:Parser how to remove "//<![CDATA[ ... //]]>" ? <bik.mido@tiscalinet.it>
    Re: Permutation with a twist ?? <wahab-mail@gmx.de>
    Re: Permutation with a twist ?? <john@castleamber.com>
    Re: Permutation with a twist ?? <john@castleamber.com>
    Re: Permutation with a twist ?? <jgibson@mail.arc.nasa.gov>
    Re: Permutation with a twist ?? xhoster@gmail.com
    Re: problem function length <bik.mido@tiscalinet.it>
    Re: problem function length <bik.mido@tiscalinet.it>
    Re: problem function length <noreply@gunnar.cc>
    Re: Problems dealing with dates in Windows <wahab-mail@gmx.de>
    Re: Problems dealing with dates in Windows <john@castleamber.com>
        regex multiline help <lance@augustmail.com>
    Re: Split a very large log file xhoster@gmail.com
    Re: Storing results in array rather than printing <uri@stemsystems.com>
        Win32 Perl slowdown <thinkulum@gmail.com>
    Re: Writing Math Equations in PERL for HTML cylurian@gmail.com
    Re: Writing Math Equations in PERL for HTML <bik.mido@tiscalinet.it>
    Re: Writing Math Equations in PERL for HTML cylurian@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 03 Feb 2007 00:30:11 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: :)
Message-Id: <lbi7s29p3c2c2fqnctchc7tacp7k8casvn@4ax.com>

On Fri, 02 Feb 2007 17:24:08 +0100, "john.swilting"
<john.swilting@wanadoo.fr> wrote:

>:)

:-(


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 2 Feb 2007 16:13:00 -0800
From: jcharth@hotmail.com
Subject: how to get recipient of email
Message-Id: <1170461580.113922.33830@k78g2000cwa.googlegroups.com>

Hello I noticed that when amavis quarantines a message adds the X-
envelop-to tag to the headers of the email. This header has all the
recipients of the email. Some email files dont have a TO
or have a BCC. Can anyone tell me how to get all recipients in a eml
file? I was looking at the code of amavis-new and it has a few
required modules that might do this but I cant find which one

any ideas?


   IO::Handle IO::Wrap IO::Stringy
        Digest::MD5 Unix::Syslog File::Basename File::Copy
        Mail::Field Mail::Address Mail::Header Mail::Internet
        MIME::Base64 MIME::QuotedPrint MIME::Words
        MIME::Head MIME::Body MIME::Entity MIME::Parser
        Net::Cmd Net::SMTP Net::Server Net::Server::PreForkSimple
        MIME::Decoder::Base64 MIME::Decoder::Binary
MIME::Decoder::Gzip64
        MIME::Decoder::NBit MIME::Decoder::QuotedPrint
MIME::Decoder::UU
      ) );
    # with earlier versions of Perl one may need to add additional
modules
    # to the list, such as: auto::POSIX::setgid
auto::POSIX::setuid ...
    fetch_modules('OPTIONAL BASIC MODULES', 0, qw(



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

Date: Sat, 03 Feb 2007 00:19:04 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: HTML:Parser how to remove "//<![CDATA[ ... //]]>" ?
Message-Id: <q9h7s2116mgcg863hnadvq9mn4uj7qkp8c@4ax.com>

On Thu, 01 Feb 2007 11:29:53 -0800, sl123@netherlands.area wrote:

>>why no /x modifier? long and complex regexes always should use /x.
>
>Not sure its relavent here

The point is, Uri is actually mixing comments here, but there are
actually two issues involved here:

(i) extremely bad style which makes for ugly, hardly readable, hardly
maintainable, error prone code - but one could still live with it;

(ii) actual bugs;

Really, both imply very poor programming skills, but the latter is
certainly worse. Now, I may go through the rest of your post and chunk
by chunk underline which is which. However I noticed that to actual
errors you answered along the lines of "I don't think so". It's not a
matter of "thinking" - they're errors, period. I agree that the person
you're answering to sometimes may seem overly harsh, but he's also
very knowledgeable - and in all earnestness, it doesn't take a Perl
guru to recognize those as errors...

>He's probably psycotic or genious, I don't know of him. The code looks good though.

I'm astonished. I wonder what kind of code you have seen thus far.
Certainly it does look *bad* to me in several different respects.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 02 Feb 2007 23:48:55 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Permutation with a twist ??
Message-Id: <eq0g4j$5nh$1@mlucom4.urz.uni-halle.de>

marora@gmail.com wrote:
> Since I don't have "Math::Combinatorics" installed (nor do I have
> permission to install it), I am wondering if there is an alternative.

In this case, you could use
a simple ugly hack like this

   ...

   sub bts {
    (my $g = unpack 'b*', pack 'j', shift) =~ s/0+$//;
     my @f; push @f, $+[0] ? $+[0]-1 : 0 while $g =~ /(1)/g; @f
   }

    my @array = qw (A B C);

    print sort { length($a) <=> length($b) }
          map "@array[ bts($_) ]\n",
          (0 .. 2 ** @array - 1);

   ...

(surely this can be written more compact,
but that'd take some time ;-)

But better install the Combinatorics
Modules in your private directory
and include them via 'use lib ...'

Regards

M.


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

Date: 2 Feb 2007 23:18:14 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Permutation with a twist ??
Message-Id: <Xns98CBB0063AFDcastleamber@130.133.1.4>

"marora@gmail.com" <marora@gmail.com> wrote:
 
> How should I use the 'k-combination' @array of size k, to produce the
> desired result?

http://search.cpan.org/search?query=combinatorics&mode=all

<http://search.cpan.org/~allenday/Math-Combinatorics-
0.09/lib/Math/Combinatorics.pm#combine()>

my @n = qw(a b c);
my @c = combine(2,@n);
print join "\n", map { join " ", @$_ } @c;

prints:

b c
a c
a b

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 2 Feb 2007 23:19:41 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Permutation with a twist ??
Message-Id: <Xns98CBB04492F93castleamber@130.133.1.4>

"marora@gmail.com" <marora@gmail.com> wrote:

> Since I don't have "Math::Combinatorics" installed (nor do I have
> permission to install it), I am wondering if there is an alternative.

If you can make a Perl program work, and your own module work there isn't 
a reason why you can't install a CPAN module locally.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Fri, 02 Feb 2007 16:31:41 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Permutation with a twist ??
Message-Id: <020220071631418857%jgibson@mail.arc.nasa.gov>

In article <m2ejp8b2re.fsf@Sherm-Pendleys-Computer.local>, Sherm
Pendley <spamtrap@dot-app.org> wrote:

> "marora@gmail.com" <marora@gmail.com> writes:
> 
> > Since I don't have "Math::Combinatorics" installed (nor do I have
> > permission to install it)
> 
> Are you aware that you don't need root permission to install modules? You
> can install them under your home directory, or anywhere you have permission
> to write to.
> 
> See "perldoc perlmodinstall" for details.

If you can't or won't install either Math::Combinatorics or
Algorithm::Combinatorics, you can do something like this (reaching back
into my Fortran programming days):


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

my @array = qw( a b c );
my ( @result, @index, @maxindex);

for( my $n = 1; $n <= @array; $n++ ) {

  # generate starting and ending combinations
  @index = (0..$n-1);
  @maxindex = ($#array-$n+1..$#array);
  my @combo;
  while( (@combo = next_combination($n)) ) {
    push @result, [@combo];
  }
}
print "@$_\n" for @result;

sub next_combination
{
  my $n = shift;
  my @combo;
  
  # get combination specified by @index array
  return unless @index;
  push( @combo, $array[$_] ) for( @index );
  
  # advance elements of @index to next combination or set it to null
  # find highest index that may be incremented
  my $p = $n-1;
  while( $p >= 0 ) {
    last if( $index[$p] < $maxindex[$p] );
    $p--;
  }
  
  # if possible, increment index and reset all higher indices
  if( $p >= 0 ) {
    $index[$p]++;
    $index[$_] = $index[$_-1] + 1 for (++$p..$#index);
  }else{
    # no more combinations
    @index = ();
  }
  return @combo;
}
__END__

which produces:

a
b
c
a b
a c
b c
a b c

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 03 Feb 2007 00:35:36 GMT
From: xhoster@gmail.com
Subject: Re: Permutation with a twist ??
Message-Id: <20070202193545.263$yA@newsreader.com>

"marora@gmail.com" <marora@gmail.com> wrote:
> On Feb 2, 5:21 pm, "Brian McCauley" <nobul...@gmail.com> wrote:
> >
> > Opps, the OP just wanted:
> >
> > my @comb = map { combine ($_, @array) } 1 .. @array;- Hide quoted text
> > -
> >
> > - Show quoted text -
>
> Since I don't have "Math::Combinatorics" installed (nor do I have
> permission to install it),

You don't need permissions, you can install it in user-space.  Or you coud
just get the source code from CPAN and copy and paste it.

> I am wondering if there is an alternative.

sub foo {
  return [@_] unless @_>1;
  my $x=shift;
  return map {[$x,@$_],[@$_]} foo(@_);
};

use Data::Dumper;
print Dumper [foo(qw/a b c d/)];

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Sat, 03 Feb 2007 00:23:49 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem function length
Message-Id: <suh7s2p4eqlel4kj6o6e4cvk0lccdthuuq@4ax.com>

On Fri, 02 Feb 2007 17:18:29 +0100, "john.swilting"
<john.swilting@wanadoo.fr> wrote:

>> perldoc -f -X
>> 
>> 
>> Michele
>CGI::UploadEasy its very well nice for my problems

Glad for you. But it wasn't me to suggest it. You should have followed
up to another post.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sat, 03 Feb 2007 00:27:25 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem function length
Message-Id: <61i7s2pg9cuvukppak2shi3skc9tc0k7pu@4ax.com>

On Fri, 02 Feb 2007 17:46:03 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:

>> Since you seem to be using CGI.pm, you find everything explained 
>> quite clearly in its docs under the "CREATING A FILE UPLOAD FIELD" 
>> heading.
>
>"Quite clearly"? I believe there is a reason why people often encounter 
>difficulties when uploading files. That's why I wrote CGI::UploadEasy.

Well, it doesn't seem too difficult to me:

: When the form is processed, you can retrieve the entered filename by
: calling param():
: 
:        $filename = param('uploaded_file');
: 
: Different browsers will return slightly different things for the name.
: Some browsers return the filename only. Others return the full path to
: the file, using the path conventions of the user's machine.
: Regardless, the name returned is always the name of the file on the
: *user's* machine, and is unrelated to the name of the temporary file
: that CGI.pm creates during upload spooling (see below).
: 
: The filename returned is also a file handle. You can read the contents
: of the file using standard Perl file reading calls:


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sat, 03 Feb 2007 01:17:43 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: problem function length
Message-Id: <52i2hgF1ooat0U1@mid.individual.net>

Michele Dondi wrote:
> Gunnar Hjalmarsson wrote:
>>I believe there is a reason why people often encounter 
>>difficulties when uploading files. That's why I wrote CGI::UploadEasy.
> 
> Well, it doesn't seem too difficult to me:
> 
> : When the form is processed, you can retrieve the entered filename by
> : calling param():
> : 
> :        $filename = param('uploaded_file');
> : 
> : Different browsers will return slightly different things for the name.
> : Some browsers return the filename only. Others return the full path to
> : the file, using the path conventions of the user's machine.
> : Regardless, the name returned is always the name of the file on the
> : *user's* machine, and is unrelated to the name of the temporary file
> : that CGI.pm creates during upload spooling (see below).
> : 
> : The filename returned is also a file handle. You can read the contents
> : of the file using standard Perl file reading calls:

Right after that, the CGI.pm POD talks about problems with the just 
described method, and recommends that the upload method is used instead. 
It can be read and understood, but it's not very straightforward.

And people encounter difficulties over and over.

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


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

Date: Fri, 02 Feb 2007 23:54:53 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Problems dealing with dates in Windows
Message-Id: <eq0gfp$5s8$1@mlucom4.urz.uni-halle.de>

Purl Gurl wrote:
> Mirco Wahab wrote:
>> You are on the wrong track. I can reproduce his
>> error message "under WinXP" without problems here:
> 
>>     5.008008 on linux
>>     5.008007 on cygwin
> 
> No, you are on the wrong track.
> Linux is not Windows XP. Cygwin is not Windows XP.
> Neither are a DOS 6 / 7 command line.
> 
> Others present precisely the same results as mine,
> using Windows XP. Why have you singled me for
> response but not others reporting precisely
> the same results I report?

Other would have probably laughed at it
and then added "yea, he's *using* Windows XP
somehow at the time, but surely not for Perl ..."

But you wouldn't. So you got singled out
for that this time ;-)

Regards

Mirco



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

Date: 2 Feb 2007 23:15:24 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Problems dealing with dates in Windows
Message-Id: <Xns98CBAF8ABE085castleamber@130.133.1.4>

Glenn Jackman <glennj@ncf.ca> wrote:

> At 2007-02-02 01:42PM, "John Bokma" wrote:
>>  "Paul Lalli" <mritty@gmail.com> wrote:
>>  
>> > On what OS version?  On my WinXP, I get:
>> > C:\>perl -le"print `date /T`"
>> > 02/02/2007
>>  
>>  No Fri?
> 
> Depends on your regional settings.  I use:
>     C:\>date /t
>     2007-02-02

Yes, I was guessing that :-D.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Sat, 03 Feb 2007 00:02:55 GMT
From: Lance Hoffmeyer <lance@augustmail.com>
Subject: regex multiline help
Message-Id: <PiQwh.351$h75.246@trnddc01>

Hey all,

I need a little help with a regex.

Traditionally, I have found numbers in a particular column using the following regex (see table at bottom of page):

$fileT1 =~ /TABLE\s+1.*?$BRAND2.*?(?:(\d{1,3}\.\d|\-)[A-T\s]+){2}/s;my $val = $1;if($1 eq "- "){$val=0} ###($1 = 0.6)

but, the following is matching BRAND5, col 13 = 3.3, instead of BRAND4, col 13 = "-"
$fileT1 =~ /TABLE\s+1.*?$BRAND4.*?(?:(\d{1,3}\.\d|\-)[A-T\s]+){13}/s;my $val = $1;if($1 eq "- "){$val=0}

Basically, I want to find the line BRAND4, then ignore everything up until the next line, then I want to start the multimatch
The "-" seem to be screwing my regex up:
I tried using modifiers within the regex, but still not having any success.

dot matches ^ and $, then after BRAND4, dot does not match ^ or $, rather I match it manually, allowing me to reach the newline
of percentages.

$fileT1 =~ /(?s)TABLE\s+1.*?BRAND4[$b](?m).*?^.*?(?:(\d{1,3}\.\d|\-)[A-T\s]+){$col}/;my $val = $1;if($1 eq "- "){$val=0}

Any suggestions on how to modify my regex such that
1) Find TABLE 1 then,
2) Go past everything until BRAND 4 is found then
3) match until the end of the line is reached (or there is a newline, or ^)
4) then, start the multi-match

Thanks in advance,

Lance


PAGE 1
BANNER 13 COL
TABLE 1
XXXXXXXXX
Q.1b



                     COL 1 COL 2  COL 3  COL 4  COL 5  COL 6  COL 7  COL 8  COL 9  COL 10 COL 11 COL 12 COL 13
                     ----- ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------
                       (A)    (B)    (C)    (D)    (E)    (F)    (G)    (H)    (I)    (J)    (K)    (L)    (M)

TOC
BASE - TOTAL          1025     90*   111    103    138     64*    83*    53*    86*    88*    51*    77*    76*
 RESPONDENTS

BRAND1                 660     48     74     59     85     46     61     40     55     58     36     51     48
                      64.4   53.5   66.8B  57.4   61.5   71.8BD 73.0BD 75.5BD 63.4   65.5   70.2B  65.5   63.0

BRAND2 / TYPE          113     17     10      5     22      2      4      7     11     12      5      9      8
 (TEST)               11.0   19.1CDF 9.5    5.2   16.3DFG 2.5    4.5   13.7F  13.3DF 13.5DFG 9.1   11.4F  11.0
                             G                                                G

BRAND3                  43      2      8     12      4      1      3      1      1      2      6      3      2
                       4.2    1.8    7.0   11.6BEF 2.7    0.8    3.1    2.0    1.2    1.8   11.4BEF 4.0    2.8
                                           GHIJM                                            IJ

BRAND4                  13      1      -      5      1      1      1      1      1      -      -      3      -
                       1.2    0.6      -    5.1CEJ 0.8    1.7    0.6    1.0    0.6      -      -    4.0      -

BRAND5                   7      2      1      1      -      1      1      -      1      -      -      -      3
                       0.7    2.3    0.5    0.5      -    0.8    0.6      -    0.6      -      -      -    3.3




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

Date: 03 Feb 2007 00:41:40 GMT
From: xhoster@gmail.com
Subject: Re: Split a very large log file
Message-Id: <20070202194149.336$tg@newsreader.com>

Terry.Riegel@gmail.com wrote:
> I have a 9gig log file, I am trying to do something with it. I tried
> to run it through awstats and after about 8 hours I got a segmentation
> fault.
>
> I think if I could break it up into 2 files I could process one , then
> process the other.

I would guess that doing this will lead to the wrong answers.  If awstats
is at all well written, then it wouldn't be loading all the data into
memory (which I'm guessing is what precipitated the seg fault) unless that
is what it needed to do to get the right answer.


> I am not very good at PERL, but have to believe
> this would be a 5-10 line program.

I'd use GNU "split" rather than using Perl at all, but anyway you just
need to look in $. to decide if you should reopen to a new output
file.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Fri, 02 Feb 2007 20:36:55 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Storing results in array rather than printing
Message-Id: <x74pq4ggy0.fsf@mail.sysarch.com>

>>>>> "j" == joseph85750  <joseph85750@yahoo.com> writes:

  j> Thanks for the replies, everyone.  I couldn't get IPC::Open2 to work,
  j> but I understand the need now.  The system call solution:

  j> @array = `echo '$someData' | zathras`

first off, that is not a system() call but backticks. they are related
but not the same thing.

  j> worked, and I'll stick with that.  I was hoping to avoid a system
  j> call, but I'm tired.

open2 does the same fork/exec as do system and backticks. why do you
think you are avoiding a system call? you have to fork/exec zathras
somehow and perl has about 5 different (all useful) ways to do that. the
only think you avoid with open2 vs backticks is the shell call to parse the
command there.

uri

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


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

Date: 2 Feb 2007 15:27:00 -0800
From: "Andy Culbertson" <thinkulum@gmail.com>
Subject: Win32 Perl slowdown
Message-Id: <1170458818.787594.51330@v33g2000cwv.googlegroups.com>

I'm running ActivePerl on Windows XP SP2.  My job involves processing
text files that are 8-12 M, which I do using regular expressions.  Up
until last September I was able to do this fairly quickly, but at that
point my script suddenly took a lot longer to run, which really
hinders my work.

I thought maybe the problem was some change in the way ActivePerl
handled regular expressions, but someone has suggested that it might
have to do with memory allocation.

I wrote some test scripts that I profiled under various conditions,
and in a nutshell I found that the following had little to no effect:

  - uninstalling the Windows updates I had installed between the time
the script ran slowly and the last time I remembered it running
normally (a period of about a month)

  - testing the script under ActivePerl builds 817, 813, and 811.

  - testing the script on three different machines running WinXP SP2

Running the same script on Linux, however, had a dramatic effect.  The
regular expression portion of the script ran 200 times faster than it
did on Windows (though this is not the case with the script below).
On Linux, the speed of the script I normally work with runs at a
comparable speed to what I remember previously on Windows.

Given my test results, I can't imagine what could have caused such a
drastic change in speed or how to fix it.  Does anyone have any
ideas?  It's inconvenient to switch from Windows to Linux to do this
part of my work, but I can continue doing that if necessary.

Here is some of my data to give you an idea of what I found.
Unfortunately, my test script evolved during my investigation, so I
don't really have a consistent set of data to present, but here are
some basic tests with the latest version of the script.  I can rerun
some of the earlier tests with this script if anyone needs me to.

First, the script (profile.pl):

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

#!usr/bin/perl -w

use strict;

my $megabytes = 10;
print "Building string - $megabytes M\n";
my $string = buildString();
print "Tokenizing\n";
my @list = tokenize($string);
print "Stripping tags\n";
$string = stripTags($string);
# This splicing sub is *really* inefficient, so feel free to omit it.
# I was just testing different functions to see if they all slowed
down
# equally.
print "Splicing list\n";
@list = spliceList(@list);
print "Building another list\n";
&buildList;

sub buildString {
	my $string;
	for my $m (1..$megabytes) {
		for my $i (0..65536) {
			$string .= "abcdefgh";
			$string .= "<abcdef>";
		}
	}
	$string;
}

sub tokenize {
	my $string = shift;
	my @list = $string =~ /<[^<>]*>|[^<>]+/sg;
	@list;
}

sub stripTags {
	my $string = shift;
	$string =~ s/<[^<>]*>//sg;
	$string;
}

sub spliceList {
	my @list = @_;
	my $i = 0;
	while ($i <= $#list) {
		if ($list[$i] =~ /^</) {
			splice @list, $i, 1;
			$i--;
		}
		$i++;
	}
	@list;
}

sub buildList {
	my @list;
	for my $i (1..1000) {
		push @list, "a";
	}
}

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

Seconds per call for each sub and system:

               WinXP   Linux     Mac  NetBSD
&spliceList   272.57  236.94  1689.1  329.69
&buildString  21.968  0.5600  1.1600  22.750
&tokenize     15.954  1.6300  10.750  6.7000
&stripTags    0.3440  0.3500  1.0900  0.4600
&buildList         -  0.0600  0.0100       -


System details:

WinXP SP2
Intel(R) Pentium(R) 4 CPU 3.40GHz
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
ActivePerl build 813

Linux version 2.6.15-27-386 (buildd@terranova) (gcc version 4.0.3
(Ubuntu 4.0.3-1ubuntu5))
Intel(R) Pentium(R) 4 CPU 3.40GHz
This is perl, v5.8.7 built for i486-linux-gnu-thread-multi

Mac OS X 10.4.8
1.33 GHz PowerPC G4
This is perl, v5.8.6 built for darwin-thread-multi-2level

NetBSD 3.0.1_STABLE (GENERIC.MPACPI)
Intel (686-class), 2992.59 MHz, id 0xf34
This is perl, v5.8.8 built for i386-netbsd-thread-multi



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

Date: 2 Feb 2007 15:25:59 -0800
From: cylurian@gmail.com
Subject: Re: Writing Math Equations in PERL for HTML
Message-Id: <1170458759.406624.269790@a75g2000cwd.googlegroups.com>

Wow, thanks.  What can I do if $a = -1 and I want nothing to show, is
there a faster way then doing a separte condition for $a like

if ($a == -1) {
 printf "x<sup>2</sup>%+dx%+d=0",$a,$b,$c;
}else {
 printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;
}


On Feb 2, 2:27 pm, "Brian McCauley" <nobul...@gmail.com> wrote:
> On Feb 2, 10:15 pm, cylur...@gmail.com wrote:
>
>
>
> > Hello everyone.  I create a lot of math questions with PERL and
> > display them in html.  One item that kills me is using negative signs,
> > especially for displaying on html.  Question is what is the best
> > efficient way to account for positive and negative (addition and
> > subtraction) signs when displaying in html?  I write many conditional
> > statements so I can account for the sign (operations).  For example,
> > lets say I have a quadratic:  ax^2 + bc + c = 0
>
> > And I want a, b and c to be random from -9 to -1 and 1 to 9.  When I
> > print the problem, I have to all the cases for displaying in html.
>
> > If (($a >= 1)&&($b >= 1)&&($c >= 1) {
>
> > print "$a x<sup>2</sup> + $b x + $c = 0";
>
> > }elsif (($a >= 1)&&($b <= 1)&&($c >= 1)) {
>
> > print "$a x<sup>2</sup>  $b x + $c = 0";
>
> > }..... keeps going until I cover all possible combinations with negative
>
> > and positive signs.  Any suggestions on being more efficient?
>
> printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;




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

Date: Sat, 03 Feb 2007 00:33:09 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Writing Math Equations in PERL for HTML
Message-Id: <ufi7s2tqjrhvhjov2lp3fs7vf1mnrotmk7@4ax.com>

On 2 Feb 2007 14:15:31 -0800, cylurian@gmail.com wrote:

>Hello everyone.  I create a lot of math questions with PERL and

Perl

>display them in html.  One item that kills me is using negative signs,

You may want to see what LaTeX 2 HTML converters, e.g. TeX4ht do.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 2 Feb 2007 15:36:38 -0800
From: cylurian@gmail.com
Subject: Re: Writing Math Equations in PERL for HTML
Message-Id: <1170459398.767151.71820@v33g2000cwv.googlegroups.com>

Wow, thanks. Is there a way for me to show only a negative for 1
instead of -1.  I know of two ways, but is there a better way.

if ($a  == -1 {

$a = "-";
}

or

if ($a == -1) {

printf "-x<sup>2</sup>%+dx%+d=0", $b,$c;

}else {

printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;

}



On Feb 2, 2:27 pm, "Brian McCauley" <nobul...@gmail.com> wrote:
> On Feb 2, 10:15 pm, cylur...@gmail.com wrote:
>
>
>
> > Hello everyone.  I create a lot of math questions with PERL and
> > display them in html.  One item that kills me is using negative signs,
> > especially for displaying on html.  Question is what is the best
> > efficient way to account for positive and negative (addition and
> > subtraction) signs when displaying in html?  I write many conditional
> > statements so I can account for the sign (operations).  For example,
> > lets say I have a quadratic:  ax^2 + bc + c = 0
>
> > And I want a, b and c to be random from -9 to -1 and 1 to 9.  When I
> > print the problem, I have to all the cases for displaying in html.
>
> > If (($a >= 1)&&($b >= 1)&&($c >= 1) {
>
> > print "$a x<sup>2</sup> + $b x + $c = 0";
>
> > }elsif (($a >= 1)&&($b <= 1)&&($c >= 1)) {
>
> > print "$a x<sup>2</sup>  $b x + $c = 0";
>
> > }..... keeps going until I cover all possible combinations with negative
>
> > and positive signs.  Any suggestions on being more efficient?
>
> printf "%dx<sup>2</sup>%+dx%+d=0",$a,$b,$c;




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

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 V11 Issue 100
**************************************


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