[26219] in Perl-Users-Digest
Perl-Users Digest, Issue: 8404 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 11 09:06:21 2005
Date: Sun, 11 Sep 2005 06:05:06 -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 Sun, 11 Sep 2005 Volume: 10 Number: 8404
Today's topics:
Re: Can a Perl Programmer Pick up PHP quickly? <gogala@sbcglobal.net>
Re: Can a Perl Programmer Pick up PHP quickly? <john@castleamber.com>
Re: Echoing fatal errors in Unix vs. Windows <joe@inwap.com>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Space (\s) count problem <"h.v.niekerk at hccnet.nl">
Re: Space (\s) count problem <joe@inwap.com>
Re: Space (\s) count problem <john@castleamber.com>
Re: Space (\s) count problem <no@email.com>
Re: Space (\s) count problem <1usa@llenroc.ude.invalid>
Re: Space (\s) count problem <no@email.com>
Re: Space (\s) count problem <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 11 Sep 2005 05:34:27 GMT
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <pan.2005.09.11.05.34.26.88278@sbcglobal.net>
On Fri, 02 Sep 2005 19:51:13 +0200, Matija Papec wrote:
> It is, but you can soon find struggling with php if you want to do something
> more => http://tnx.nl/php
Ah, another PHP hater, and a countryman at that. No, no struggling is
necessary. PHP is easier to learn then perl. Much easier to learn. On the
other hand, for the CLI environment, perl rulz. I started with perl few
weeks ago, when subroutines were called with "&" and curent version was
perl 4.0.36. As an oracle DBA, I used oraperl variety, a predecessor to
DBI/DBD::Oracle. It was 1995. PHP5 was a breeze to pick: no @ISA, no
$AUTOLOAD, no tie, no hidden first arguments, just classes, methods and
inheritance, the way they're meant to be. Yes, PHP5 uses functions for
everything and you can't write something like
if (/^Gas:(\d+).*Mileage:(\d+).*Toll:(\d+)/) { my $expense=$1+$2+$3; }
or use tricky idioms like
$a ||= 'A';
PHP functions are, on the other hand, well documented, books are complete,
unlike "Learning Perl", which skips things like references, packages and
objects. To learn Perl, you need at least 3 books: "Learning Perl",
"Programming Perl" and Conway's OO Perl. It is much easier to learn PHP
then to learn Perl. On the other hands, Perl has formats, and PHP has
nothing like a built-in report writer. I love both Perl and PHP, PHP for
the web, Perl for CLI. Perl with its arcane secrets and tricks that can be
learned only through the word of mouth and bizarre mechanisms like "tie"
is much, much harder to learn. This comes from someone who uses both perl
and PHP. That page is rubbish. For the real PHP hater page look for the
PHP emulation modules on CPAN.
--
http://www.mgogala.com
------------------------------
Date: 11 Sep 2005 10:35:16 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <Xns96CE386A3BA4Ccastleamber@130.133.1.4>
Mladen Gogala <gogala@sbcglobal.net> wrote:
> On Fri, 02 Sep 2005 19:51:13 +0200, Matija Papec wrote:
>
>> It is, but you can soon find struggling with php if you want to do
>> something more => http://tnx.nl/php
>
> Ah, another PHP hater, and a countryman at that. No, no struggling is
> necessary. PHP is easier to learn then perl.
Nonsense. Another Perl hater.
> Much easier to learn.
Only if you are interested in 20 line PHP thingies.
> On
> the other hand, for the CLI environment, perl rulz. I started with
> perl few weeks ago, when subroutines were called with "&" and curent
> version was perl 4.0.36.
Which is like, eh... 15 years old?
> As an oracle DBA, I used oraperl variety, a
> predecessor to DBI/DBD::Oracle. It was 1995. PHP5 was a breeze to
> pick:
in 1995?
> no @ISA, no $AUTOLOAD, no tie, no hidden first arguments,
which hidden first arguments?
btw: check out:
use base CLASS
Wrt $AUTOLOAD: maybe rtfm, and it becomes clear how useful it is. You
*don't* have to use it, but it makes life easier.
> just
> classes, methods and inheritance, the way they're meant to be.
*sniggers* you are talking about PHP now are you?
> PHP functions are, on the other hand, well documented,
*sniggers*, sure. Maybe you misunderstand the word well.
> secrets and tricks that can be learned only through the word of mouth
> and bizarre mechanisms like "tie" is much, much harder to learn.
What is bizarre about tie? Which part do you not understand? It's
nothing more then being able to override some methods on a type of
variable.
> This
> comes from someone who uses both perl and PHP. That page is rubbish.
You mean, you don't have a clue what it tries to make clear.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sun, 11 Sep 2005 03:11:39 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Echoing fatal errors in Unix vs. Windows
Message-Id: <U5ydnShAZ_BAn7neRVn-3w@comcast.com>
Alexandre Jaquet > wrote:
> Bob a écrit :
>
>> Ok... I'm a windows guy and woefully weak in Unix skills.
>> WHen I run a script on my windows IIS server, and Perl script
>> errors (e.g. coding problems) get echoed back to the browser. When I
>> load the same programs on my ISP's Linux server, I get "Internal
>> Server Error, see log". Unfortunately, I don't
>> seem to have access to that log file in my virtual environment.
>> I assume this has something to do with std err vs. std out and where
>> that output goes - but that's about the limit of my Unix
>> knowledge. How can I redirect the error output to dump back to the
>> browser ?
>> Thanks,
>
>
> print "Content-type: image/html\n\n";
> print "$var";
That is so very wrong.
*) "image/html" is gibberish
*) The print() statement will not be executed if there is an
error that causes perl to abort.
The other people answering Bob's question have it right.
-Joe
------------------------------
Date: 11 Sep 2005 04:25:13 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1126412687@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
and XEmacs port
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
http://math.berkeley.edu/~ilya/software/emacs/
by Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Sun, 11 Sep 2005 11:22:54 +0200
From: Huub <"h.v.niekerk at hccnet.nl">
Subject: Space (\s) count problem
Message-Id: <4323f6c1$0$766$3a628fcd@reader10.nntp.hccnet.nl>
Hi,
I want to read the white space character, but it doesn't work. Sofar I
have this code for the actual reading.
while (<INPUT_FILE>)
{
$spatie++ if m/\s/m
}
The line to be read is: dit is een test voor TIRCIN
The result for $spatie is 1 instead of 5. Where do I go wrong?
Thanks,
Huub
------------------------------
Date: Sun, 11 Sep 2005 02:51:32 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Space (\s) count problem
Message-Id: <HtidnUfRt4S7Y77eRVn-uw@comcast.com>
Huub wrote:
> $spatie++ if m/\s/m
>
> The line to be read is: dit is een test voor TIRCIN
You used the /m option instead of /g.
You did not include any code to repeat matches.
$spatie++ while m/\s/g;
It is recommended to use tr/// for counting characters.
-Joe
------------------------------
Date: 11 Sep 2005 10:38:04 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Space (\s) count problem
Message-Id: <Xns96CE38E38A759castleamber@130.133.1.4>
Huub <"h.v.niekerk at hccnet.nl"> wrote:
> Hi,
>
> I want to read the white space character, but it doesn't work. Sofar I
> have this code for the actual reading.
You want to count, not read:
perldoc -q count
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sun, 11 Sep 2005 12:22:53 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Space (\s) count problem
Message-Id: <3oiicdF621j4U1@individual.net>
John Bokma wrote:
> Huub <"h.v.niekerk at hccnet.nl"> wrote:
>
>> Hi,
>>
>> I want to read the white space character, but it doesn't work. Sofar I
>> have this code for the actual reading.
>
> You want to count, not read:
>
> perldoc -q count
>
A few months ago I had to write something to count the number of times a
certain string was found in another string. The script would have to do it
10s of thousands of times in each execution on strings of ~3KB.
It had to be fast, and after much benchmarking, I found the fastest method
(on my machine anyway) is one not in the faq, but to substitute the string
with itself and count the number of successes.
$matches += ($string =~ s!\Q$kw!$kw!g);
Which was ~ 12% faster than anything in faq if I remember correctly.
Why this is faster than :-
$matches++ while $string =~ m!\Q$kw!g;
I have no idea.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Sun, 11 Sep 2005 11:56:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Space (\s) count problem
Message-Id: <Xns96CE50CAAC12asu1cornelledu@127.0.0.1>
Brian Wakem <no@email.com> wrote in news:3oiicdF621j4U1@individual.net:
> A few months ago I had to write something to count the number of times
> a certain string was found in another string. The script would have
> to do it 10s of thousands of times in each execution on strings of
> ~3KB. It had to be fast, and after much benchmarking, I found the
> fastest method (on my machine anyway) is one not in the faq, but to
> substitute the string with itself and count the number of successes.
>
> $matches += ($string =~ s!\Q$kw!$kw!g);
>
> Which was ~ 12% faster than anything in faq if I remember correctly.
>
> Why this is faster than :-
>
> $matches++ while $string =~ m!\Q$kw!g;
>
> I have no idea.
Did try using index?
<untested>
$matches++ while -1 =! index $string, $kw;
</untested>
What were the results?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sun, 11 Sep 2005 13:01:44 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Space (\s) count problem
Message-Id: <3oikl8F64445U1@individual.net>
A. Sinan Unur wrote:
>
> Did try using index?
>
> <untested>
> $matches++ while -1 =! index $string, $kw;
> </untested>
>
> What were the results?
>
> Sinan
Infinite loop.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Sun, 11 Sep 2005 12:42:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Space (\s) count problem
Message-Id: <Xns96CE5896E8B4Fasu1cornelledu@127.0.0.1>
Brian Wakem <no@email.com> wrote in news:3oikl8F64445U1@individual.net:
> A. Sinan Unur wrote:
>
>>
>> Did try using index?
>>
>> <untested>
>> $matches++ while -1 =! index $string, $kw;
>> </untested>
>>
>> What were the results?
...
> Infinite loop.
Well, I said it was untested, didn't I :)) Sorry about that.
A rudimentary benchmark I ran with the corrected code showed that index
is about 30% slower than the substitution based solution you posted.
So much for early Sunday morning inspiration.
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark 'cmpthese';
my $s = join('', '012345678901234567890123456789012' x 100);
my $k = '0123456789';
cmpthese -1, {
use_regex => \&use_regex,
use_index => \&use_index,
};
sub use_index {
my ($m, $i) = (0, -1);
while(-1 != ($i = index($s, $k, $i + 1))) {
$m += 1;
}
return $m;
}
sub use_regex {
my $m = ($s =~ s!\Q$k!$k!g);
}
__END__
D:\Home\asu1\UseNet\clpmisc> perl -v
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
(with 7 registered patches, see perl -V for more detail)
Copyright 1987-2005, Larry Wall
Binary build 813 [148120] provided by ActiveState
http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun 6 2005 13:36:37
D:\Home\asu1\UseNet\clpmisc> ppp
Rate use_index use_regex
use_index 5957/s -- -31%
use_regex 8653/s 45% --
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
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 8404
***************************************