[24353] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6542 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 8 09:05:44 2004

Date: Sat, 8 May 2004 06:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 8 May 2004     Volume: 10 Number: 6542

Today's topics:
    Re: $# and 2d arrays <krahnj@acm.org>
    Re: $# and 2d arrays <webmaster@neverseenbefore.com>
    Re: $# and 2d arrays <Joe.Smith@inwap.com>
    Re: $# and 2d arrays <invalid-email@rochester.rr.com>
    Re: is there something more elegant to convert Dos to u <uri@stemsystems.com>
    Re: List questions on form (Roger)
    Re: Raw body parts in MIME:Parser <jwillmore@remove.adelphia.net>
    Re: Regular expression questions <abigail@abigail.nl>
    Re: Spreadsheet::WriteExcel <sean_berry@cox.net>
    Re: Spreadsheet::WriteExcel <invalid-email@rochester.rr.com>
    Re: web application testing <jwillmore@remove.adelphia.net>
    Re: Why does chomp leave newlines? <gnari@simnet.is>
    Re: Why is this simple script not sending email? <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 08 May 2004 05:21:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: $# and 2d arrays
Message-Id: <409C6E58.11D82CC6@acm.org>

Ala Qumsieh wrote:
> 
> Dieter D'Hoker wrote:
> >
> > if i have an aray @array that i'm going to fill :
> >
> >   for (my $y=0; $y<20; $y++) {
> >     for (my $x=0; $x<20; $x++) {
> >       $field[$x][$y] = 0;
> >     }
> >   }
> >
> > should i use $#array = 19;
> > or $#array = 399; ?
> >  to predefine the correct lenght ?
> 
> Neither. Generally, you don't need to, but if you had to initialize
> everything to 0 (if undef is not good enough) then I would suspect that
> the following would be faster:
> 
>         my @field;
>         $field[$_] = [(0) x 20] for 0 .. 19;

Or:

my @field = map [ (0) x 20 ], 0 .. 19;


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 8 May 2004 08:02:24 +0200
From: "Dieter D'Hoker" <webmaster@neverseenbefore.com>
Subject: Re: $# and 2d arrays
Message-Id: <2g3bffF40r57U1@uni-berlin.de>

John W. Krahn wrote:
> Ala Qumsieh wrote:
>>
>> Dieter D'Hoker wrote:
>>>
>>> if i have an aray @array that i'm going to fill :
>>>
>>>   for (my $y=0; $y<20; $y++) {
>>>     for (my $x=0; $x<20; $x++) {
>>>       $field[$x][$y] = 0;
>>>     }
>>>   }
>>>
>>> should i use $#array = 19;
>>> or $#array = 399; ?
>>>  to predefine the correct lenght ?
>>
>> Neither. Generally, you don't need to, but if you had to initialize
>> everything to 0 (if undef is not good enough) then I would suspect
>> that the following would be faster:
>>
>>         my @field;
>>         $field[$_] = [(0) x 20] for 0 .. 19;
>
> Or:
>
> my @field = map [ (0) x 20 ], 0 .. 19;

okay, thx for the suggestions ...


-- 
Dieter D'Hoker
news:free.nl.dieter.dhoker & news:alt.nl.fan.dieter.dhoker
Multiplayer tetris? http://www.tsrv.com/




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

Date: Sat, 08 May 2004 09:55:13 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: $# and 2d arrays
Message-Id: <582nc.49777$0H1.4746492@attbi_s54>

Dieter D'Hoker wrote:

> well i have an AI that tries to find the best move on a 20*20 field,

   $array[$_] = [ (0) x 20 ] for (0 .. 19);

> therefore it tries all possible moves and evaluates the resulting field,
> this results in about 48 fields that are created,
> but to make it smarter it then tries to lookahead every 48 fields result in
> another 48 fields, resulting in 2304 fields, etc.

   $fields[$_] = [ (0) x 48 ] for (0 .. 47);

> And all this has to be done in realtime, the
> AI has to give a response within very little time.
> So i'm trying to optimize the code wherever possible, ..

Sounds like premature optimization.  Profile the code first,
find out where the hot spots really are.
	-Joe


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

Date: Sat, 08 May 2004 12:36:49 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: $# and 2d arrays
Message-Id: <409CD459.3060801@rochester.rr.com>

Dieter D'Hoker wrote:

> Eric Schwartz wrote:
> 
>>"Dieter D'Hoker" <webmaster@neverseenbefore.com> writes:
 ...


> well i have an AI that tries to find the best move on a 20*20 field,
> therefore it tries all possible moves and evaluates the resulting field,


Just a general comment:  something that does an exhaustive search 
doesn't sound much like "AI".  Your speed might be improved dramatically 
by using learning algorithms and the like in place of exhaustive searches.


 ...
> So i'm trying to optimize the code wherever possible, ..

You'll likely gain way *way* more from optimizing algorithms than 
optimizing code.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 08 May 2004 05:02:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: is there something more elegant to convert Dos to unix in subroutine?
Message-Id: <x7ekpvtsth.fsf@mail.sysarch.com>

>>>>> "A" == Andrew  <myfam@surfeu.fi> writes:

  A> Thanks for constructive remarks, here is the fixed one, which, again,
  A> works just fine :)

and looks ugly too!

  A> sub toUnixFile {
  A>   my ($file, $trim) = @_;
  A>   -f $file || die "Can't open \"$file\": $! \n";

lose the \ there. use an alternative delimiter

  A>   my $temp_file = $file . ".tmp.$$.$^T";

use the File::Temp module

  A>   move($file, $temp_file);
  A>   local *in;
  A>   local *out;

gack! use lexical filehandles. and glob handles are upper case by tradition
  A>   open(in, "<$temp_file");
  A>   open(out, ">$file");

you check for the file with -f but not here? always check your open
calls for failures

  A>   while(<in>) {
  A>     chomp;
  A>     s/\r$//;

why the chomp AND s///?  s/[\r\n]+$// would work anywhere.

  A>     if ($trim eq "true") {
  A>       s/^\s*//;
  A>       s/\s*$//;
  A>       unless ( -z $_ ) {

huh??!! what do you think -z does? this is perl, not shell.

and if i get your logic (which is coded incorrectly), you want to not
print lines that had only blanks. that means this is not a true dos2unix
program since that is not part of the typical spec for that.

  A>         print out "$_\n";
  A>       }              
  A>     } else {
  A>         print out "$_\n";      
  A>     }

redundant code always bothers me. if you used next you could have that
one print line for both cases.


and you still top post.

  >> >>>>> "A" == Andrew  <myfam@surfeu.fi> writes:
  >> 
  A> Hm, my subroutine is actually working just fine, prove me wrong, it
  A> conversts DOS files to UNIX just fine.
  >> 
  >> it has several bugs.

it still has several bugs

  A> All examples given involve calling perl from code, I don't like it, I
  A> would like a subroutine or function which can be included in my perl
  A> code. I don't like calling perl from perl.

  >> huh? what calling perl from code are you talking about? the answers were
  >> all one liners and it is trivial to convert any of them to a sub.

you never answered that question.

your skill levels demonstrate that you don't know when to call perl from
perl. so your saying you don't like it doesn't hold any water.

  >> >> > 
  >> >> > sub toUnixFile() {
  >> >> >   my ($file) = @_;
  >> >> >   my ($temp_file) = $file . ".tmp";
  >> 
  >> and what if that file already existed?

nevr fixed that bug.

  >> >> >   move($file, $temp_file);
  >> >> >   open(in, "<$temp_file");
  >> >> >   open(out, ">$file");
  >> 
  >> and what if either of those open calls fails?

never fixed that bug

  >> so your sub it not 'actually working just fine'. proving it wrong was
  >> too easy. you just didn't get the answers.

and most of the bugs i pointed out are still there. you don't listen
well it seems.

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: 7 May 2004 21:09:21 -0700
From: roger10232001@yahoo.com (Roger)
Subject: Re: List questions on form
Message-Id: <a872a169.0405072009.6cf17734@posting.google.com>

Joe Smith <Joe.Smith@inwap.com> wrote in message 
> 
> That's an unfortunately ambiguous example.
> Maybe this will show where you are misunderstanding it.
> 
>    # remove 2 elements; 7 and 8
>    # replace with new values
>    splice (@rainbow, 7, 2, "yellow", "orange");
> 
> 	-Joe

It is an unfortunately ambiguous example. What was confusing was the
LENGTH part. For me, the best example (where it would be obvious)
would be a LENGTH of 0 so you were inserting items into the list.
That's the hard part. Items must be shuffeled when that happens. Thats
the hard part. I was thinking LENGTH was how many of the new items to
add.
splice (@rainbow, 7, 0, "yellow", "orange");
inserts items into the list but doesn't screw the list up. PLus it's a
little funky the subscripts are really zero based, but are not
reflected in the call to splice.
Thanks a bunch for your input, you knew what was messing my mind up!

Roger


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

Date: Sat, 08 May 2004 01:05:32 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Raw body parts in MIME:Parser
Message-Id: <pan.2004.05.08.05.05.30.169308@remove.adelphia.net>

On Fri, 07 May 2004 22:21:15 +0200, Mark wrote:

> Hello,
> 
> It would really be a great idea if MIME:Parser had a way to parse the
> unencoded, raw body of a part. There are several parts in its
> documentation which CLAIM to do that. But this is not the case. Every
> time I encounter such a method, it appears to simply be a re-encoded,
> decoded part. Which is NOT the same as the raw body! And having the raw
> body is vital, if you want to replace a part within a string containing
> the original message. As it stands now, I have all these neatly decoded
> parts, but have no way to replace the old message-bodies with new
> (reformatted) ones.
> 
> Does anyone have any experience with this?

No experience ... but a suggestion :-)

If you have all these parts, why not re-assemble the parts using a module
such as MIME::Lite?  Would this work for you ... or am I missing what
you're asking?

In other words - break down your email, do your replacments, then
re-assemble the parts back into an email and send it on its merry way.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 "My life is a soap opera, but who has the rights?"  -- MadameX 
 
 


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

Date: 08 May 2004 08:54:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regular expression questions
Message-Id: <slrnc9p81v.egl.abigail@alexandra.abigail.nl>

Hung Truong (skyfaye@yahoo.com) wrote on MMMCMIII September MCMXCIII in
<URL:news:805c863b.0405071735.1561e4b2@posting.google.com>:
:)  Hi,
:)  
:)    I'm new at this regular expression.  How can I do a match for strings that
:)  1) contain three (or more) pairs of double letters

    print "Three or more pairs of double letters\n" if 3 <= () = /(.)\1/g;

This assumes that "aaaa" counts as two pairs, not three.

:)  2) have an even number of 'a's


I wouldn't use a regex for that.

    print "Even number of 'a's\n" unless y/a/a/c;


Abigail
-- 
@_=map{[$!++,$_^$/]}split$²,"\@\x7Fy~*kde~box*Zoxf*Bkiaox";$\="\r";
$|=++$*;do{($#,$=)=(rand@_,rand@_);@_[$#,$=]=@_[$=,$#]}for($*..@_);
for$:($|..@_-$|){for($|..@_-$:){@_[$_-$|,$_]=@_[$_=>$_-$*]if$_[$_][
$¼]<$_[$_-$*][$®];print+map{$_->[$|]}@_;select$·,$°,$½,0.1}}print$/


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

Date: Sat, 8 May 2004 00:51:15 -0700
From: "Sean Berry" <sean_berry@cox.net>
Subject: Re: Spreadsheet::WriteExcel
Message-Id: <Bj0nc.89771$Jy3.19461@fed1read03>

This is for a report that will run once a month so mileage isn't really an
issue.

However, I tried a simple insert of one cell on a preformatted spreadsheet
and it gave me the following error:

Can't locate object method "set_print_scale" via package
"Spreadsheet::WriteExcel::Worksheet" at
/usr/local/lib/perl5/site_perl/5.005/Spreadsheet/ParseExcel/SaveParser.pm
line 125.

I am using perl 5.005.  The module was already installed by the sytsem
admin, so what is the problem.  Do I need a more recent version of the
SaveParser module???

Thanks in advance.


"Bob Walton" <invalid-email@rochester.rr.com> wrote in message
news:409C43AA.1000606@rochester.rr.com...
> Sean Berry wrote:
>
> > Is there a way of opening a preformatted excel file, then write to empty
> > cells in the table.
> >
> > I have a table with various formulas, cell and text colors, borders,
etc.
> > But, the data is in a 28 x 170 sized chunk of the sheet.  This will be a
big
> > pain to code so I was looking for a shortcut.
>
>
> Well, one way would be to use Excel itself via the Win32::OLE module.
> Another way might be to use the Spreadsheet::ParseExcel module to read
> the "preformatted Excel file", and then use Spreadsheet::WriteExcel to
> write a new Excel file.  Another way would be with the
> Spreadsheet::ParseExcel::SaveParser module, which will do a
> read-modify-write.  What will give the greatest mileage in the long run?
>   Probably Win32::OLE.
>
>
> >
> > Is is possible to parse the .xml file and use the values within instead
of
> > just the data?
>
>
> What .xml file?  Do you mean .xls ?  Or are you referring to
> Spreadsheet::WriteExcel::FromXML (if so, how do you get the XML file?)?
>   And what do you mean by "values within" versus "just the data"?  What
> you're trying to say isn't at all clear to me.  If you want to parse an
> XML file, check CPAN for modules with XML and Parse in their names.
>
>
> ...
>
>
> -- 
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl
>




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

Date: Sat, 08 May 2004 12:50:26 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Spreadsheet::WriteExcel
Message-Id: <409CD789.4030109@rochester.rr.com>

Sean Berry wrote:

 ...
> However, I tried a simple insert of one cell on a preformatted spreadsheet
> and it gave me the following error:
> 
> Can't locate object method "set_print_scale" via package
> "Spreadsheet::WriteExcel::Worksheet" at
> /usr/local/lib/perl5/site_perl/5.005/Spreadsheet/ParseExcel/SaveParser.pm
> line 125.
> 
> I am using perl 5.005.  The module was already installed by the sytsem

 > admin, so what is the problem.  Do I need a more recent version of the
 > SaveParser module???

Do yourself and everyone else a huge favor and upgrade to a Perl that 
isn't years old.  With that version of Perl, you probably need an 
*older* version of SaveParser, if there even was such a thing back then.

Question:  Are you using the docs that go with the versions of Perl and 
the various modules you are using?


 ...

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 08 May 2004 01:10:12 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: web application testing
Message-Id: <pan.2004.05.08.05.10.09.980846@remove.adelphia.net>

On Fri, 07 May 2004 17:50:44 -0700, Charlie wrote:

> There is a web application that I am working on now, it was written in
> PERL, the backend DB is postgresql, and it runs on LINUX. One of
> issues that I am looking at is the performance. We want to know the
> behaviour it looks like when it is hit by the maximum users. The
> machine that I can use for testing is a win2K PC, and my extra budget
> for that testing is 0.
> 
> All I need to know is in which direction I may go.  

[ ... ]

HTTP::WebTest
(http://search.cpan.org/~ilyam/HTTP-WebTest-2.04/lib/HTTP/WebTest.pm) may
fit the bill for you.

You might be able to use WWW::Mechanize
(http://search.cpan.org/~petdance/WWW-Mechanize-1.02/lib/WWW/Mechanize.pm)
might also be a module to look over.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Whatever is not nailed down is mine.  What I can pry loose is
 not nailed down.   -- Collis P. Huntingdon 
 


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

Date: Sat, 8 May 2004 09:51:28 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Why does chomp leave newlines?
Message-Id: <c7iafs$spn$1@news.simnet.is>

"Mark Healey" <die@spammer.die> wrote in message
news:VP2SpNyJrzMZ-pn2-g58JOiUgmtw2@adsl-63-207-135-60.dsl.sndg02.pacbell.net
 ...
> On Sat, 8 May 2004 01:49:09 UTC, efflandt@xnet.com (David Efflandt)
> wrote:
>
> > On Sat, 08 May 2004 00:50:57 GMT, Mark Healey <die@spammer.die> wrote:
> > > First some fragments
> > >
> > > I get the array thusly:
> > >
> > > 13 @searchTerms=split(/\n/,$queryHash{"searchText"});
> > >


> I'd still like a function that removes all leading and trailing
> whitespace.  I suppose I could do it with regexps but that would be
> kind of ugly.
>

change your split to:
    my ($tmp=$queryHash{"searchText"}) =~ /^ *(.*) *$/s;
    @searchTerms=split(/ *[\r\n]+ */,$tmp);

and drop the chomp;

this will remove all leading and trailing spaces , including
the ones around the newlines

gnari





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

Date: Sat, 08 May 2004 04:09:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Why is this simple script not sending email?
Message-Id: <409C5D79.A650CB58@acm.org>

Kevin Collins wrote:
> 
> In article <slrnc9nme4.94d.efflandt@typhoon.xnet.com>, David Efflandt wrote:
> >
> > However, you also fail to test your open() and close() to see if there are
> > any other problems.
> 
> Not to sound like a smartass, but why would you test a close()? I have never
> thought about it before I read this post... If it doesn't close with close(),
> it definitely will on program termination.

perldoc perlipc
[snip]

Using open() for IPC
       Perl's basic open() statement can also be used for unidi­
       rectional interprocess communication by either appending
       or prepending a pipe symbol to the second argument to
       open().  Here's how to start something up in a child pro­
       cess you intend to write to:

           open(SPOOLER, "| cat -v | lpr -h 2>/dev/null")
                           || die "can't fork: $!";
           local $SIG{PIPE} = sub { die "spooler pipe broke" };
           print SPOOLER "stuff\n";
           close SPOOLER || die "bad spool: $! $?";

[snip]

       Be careful to check both the open() and the close() return
       values.  If you're writing to a pipe, you should also trap
       SIGPIPE.  Otherwise, think of what happens when you start
       up a pipe to a command that doesn't exist: the open() will
       in all likelihood succeed (it only reflects the fork()'s
       success), but then your output will fail--spectacularly.
       Perl can't know whether the command worked because your
       command is actually running in a separate process whose
       exec() might have failed.  Therefore, while readers of
       bogus commands return just a quick end of file, writers to
       bogus command will trigger a signal they'd better be pre­
       pared to handle.  Consider:

           open(FH, "|bogus")  or die "can't fork: $!";
           print FH "bang\n"   or die "can't write: $!";
           close FH            or die "can't close: $!";

       That won't blow up until the close, and it will blow up
       with a SIGPIPE.  To catch it, you could use this:

           $SIG{PIPE} = 'IGNORE';
           open(FH, "|bogus")  or die "can't fork: $!";
           print FH "bang\n"   or die "can't write: $!";
           close FH            or die "can't close: status=$?";



John
-- 
use Perl;
program
fulfillment


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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


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


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