Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Tassilo von Parseval
On Wed, Jan 28, 2004 at 09:11:51AM -0800 Sam wrote:

 4.  As for the generalized case, I learned about using refs.  Anonymous subs
 also work.  
 
 my $re  = sub { return /^\s*$/; };
 my $nre = sub { return not $re; };
 my $expr = $blank ? $re : $nre;
 do ... while ($expr and not eof);
 
 But I'm not sure which is faster though.

These function-refs look fishy. All they do is carrying out a pattern
match. By using '$expr' you'll also have perl pass on the current
content of @_ to the function which is wasteful since you are not
interested in the arguments.

In this case you better just use pre-compiled regexes:

my $re  = qr/^\s*$/;
my $nre = qr/\S/;   # !qr/^\s*$/ wont work unfortunately
my $pat = $blank ? $re : $nre;
do ... while /$pat/o and not eof;

This has the disadvantage that there is no generalized way of negating a
pattern. You have to do that manually. Or you create a slightly more
complicated condition:

do ... while ($blank  /$re/) || !/$re/ and not eof;

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to import symbols and semantics from one namespace into another

2004-01-28 Thread Tassilo von Parseval
On Wed, Jan 28, 2004 at 01:32:14PM -0500 [EMAIL PROTECTED] wrote:

 Hi, this question has to do with importing names from one package into
 another.  In my case, both packages reside in the same file, and I
 simply want to import all the package-global symbols from the one
 package into the other.  Can anyone say how to do this?  Here's a
 bunch of tries that didn't work.
 
 test_import.pl
 --
 package main;
 
 print Hi world\n;
 $x = dosomething();
 print did something and got $x\n;
 exit;
 
 package SomePackage;
 sub dosomething{
 return time;
 }
 
 Obviously this isn't going to work because symbol dosomething is not
 defined in package main.  (In this trivial example I could just say $x
 = SomePackage::dosomething(), but I have dozens of functions and I
 would prefer to simply import them into the namespace of main.  Also,
 apart from this specific instance, I want to understand what I can do
 in general.)
 
 The documentation for perlmod implies there's an import method that's
 part of exporter, so I tried something like this.
 
 test_import.pl
 --
 package main;
 SomePackage::import(qw(dosomething));

import() is a method and not a function. When you call it as a function
it no longer obeyes inheritance and thus cannot be found since
SomePackage inherits import() from Exporter.

 print Hi world\n;
 $x = dosomething();
 print did something and got $x\n;
 exit;
 
 package SomePackage;
 use Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(dosomething);
 sub dosomething{
 return time;
 }
 
 outcome:
 
 Undefined subroutine SomePackage::import called at test_import.pl line 2.
 
 Another variation:
 
 test_import.pl
 --
 package main;
 import SomePackage (qw(dosomething));
 print Hi world\n;
 $x = dosomething();
 print did something and got $x\n;
 exit;
 
 package SomePackage;
 use Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(dosomething);
 sub dosomething{
 return time;
 }
 
 outcome:
 
 (Not what I expected; why didn't it tell me main::import is undefined?)

Because here you called it as a method. This is indirect method
invocation:

import SomePackage qw(bla);

is the same as

SomePackage-import(qw(bla));

Here perl was indeed able to call import(). However, the reason why it
still doesn't work as you expect is the order of execution. If you do

package SomePackage;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(dosomething);
sub dosomething{
return time;
}

package main;
SomePackage-import( qw/dosomething/ );
print dosomething();

things will work. This has to do with the fact that @EXPORT is still
empty when you do the import() and when you have package main before the
exporting package. That is because assignment happens at runtime.

In case you wonder why you got no error with

package main;
SomePackage-import(...);
package SomePackage;
use Exporter;
@ISA = qw(Exporter);

even though @ISA was still empty by the time you called
SomePackage-import, this is because 'import' and 'unimport' are two
special cases. They can always be called as method even when they do not
exist nor are inherited. So in fact you can also do:

package main;
main-import( qw/bla/ );
__END__

and wont get any error.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: variable FORMAT in printf?

2004-01-19 Thread Tassilo von Parseval
On Sun, Jan 18, 2004 at 09:53:56PM -0700 Bryan Harris wrote:

 I've tried everything I can think of, but I feel like a 6th grader trying to
 solve a 7th grade math problem:
 
 I'm trying to build a pretty-fier for any tab-delimited text file
 (basically space-pad the columns so the decimals line up).  I search through
 the columns finding the longest field with and highest precision level for
 each column, then create a format string for the printf command.  The guts
 of it looks like this:
 
 
 **
 $formatstr = ;
 $index = 0;
 foreach (@lwid) {
   $formatstr .= %$lwid[$index].$lprec[$index]f.'\t';
   $index++;
 }
 substr($formatstr,-2,2) = ;
 $formatstr .= '\n';
 
 open(FILE, $file$ext) || die(Couldn't create $file$ext: $!\n);
 
 foreach (@content) {
 @fields = split;
 if (@fields) { printf FILE $formatstr, @fields; }
 else { print FILE $_; }
 }
 
 close(FILE);
 **
 
 
 ... but that printf spits out actual \t and \ns.  How can I get the
 printf to interpret those into tabs and newlines?

This is a typical data versus program problem. You have to give perl a
hint that these are escapes and not literal strings. So turn your above
foreach-loop into 

foreach (@lwid) {
$formatstr .= %$lwid[$index].$lprec[$index]f\t;
$index++;
}

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Suggestions for Submitting to CPAN

2004-01-18 Thread Tassilo von Parseval
On Sat, Jan 17, 2004 at 02:32:25PM -0500 Dan Anderson wrote:
 I've read the tutorial on creating a Makefile.PL for a module I'm
 submitting to CPAN, and I've applied for a PAUSE ID, but I was curious
 if anyone whos been through the process before knows of any pit falls I
 should be careful of, or any suggestions on how to make my life easier.

A thing you should never do is creating the structure of a module
yourself. Let perl do that for you by doing

h2xs -A -X -n Module::Name

This will create the outline of your module (including Makefile.PL) and
you just have to make the appropriate changes. Also, don't forget to put
the tests in the t/ directory.

Creating the tarball should ultimately be done with

make dist

Thus you can be sure not to violate any CPAN conventions.

It's also a good idea to consider back to which version of perl your
module should run. If you pass '-b 5.5.3' to h2xs the module draft only
uses features that can be understood by versions as old as 5.00503. In
my experience, there is rarely the need to use bleeding-edge features in
a module.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Why isn't perl used more in business and industry

2004-01-18 Thread Tassilo von Parseval
On Sat, Jan 17, 2004 at 06:52:27PM -0600 James Edward Gray II wrote:
 On Jan 17, 2004, at 3:51 PM, James Edward Gray II wrote:
 
 A recent article on Perl.com covered this a little:
 
 http://www.perl.com/pub/a/2004/01/09/survey.html
 
 And look what I read on Slashdot today:
 
 http://developers.slashdot.org/article.pl?sid=04/01/17/ 
 1435206mode=threadtid=100tid=126tid=137tid=145tid=156

See also

http://www.theregister.co.uk/content/64/34943.html

on the same issue.

 Heck, isn't the Slash code Perl too?

Yes.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Creating My Own Escapes

2004-01-16 Thread Tassilo von Parseval
On Fri, Jan 16, 2004 at 03:38:40PM -0600 James Edward Gray II wrote:

 I have a problem I just cant seem to get my head around, so any help is 
 appreciated.
 
 I have a string.  It could contain anything a Perl string can contain.  
 I have to print this string to a file and later bring it back in 
 exactly as it was.  However, because of the file format, the string in 
 the file may not contain \n characters.  That's the only difference 
 between the two representations of this string.
 
 Okay, obviously I need to replace all \n characters.  Let's say I want 
 to follow Perl's example and use a literal \ followed by a literal n.  
 Then I would also need to escape \ characters.  Okay, again we'll use 
 Perl's \ and another \.  Does that cover everything if \n is the only 
 illegal character in my file format?  I believe, so, but please correct 
 me if I'm wrong.

Maybe B::perlstring() will do what you need:

[EMAIL PROTECTED]:~$ perl -lMB=perlstring -e '$var = \n\r\f; print perlstring( $var 
bla\\\ \n )'
\n\r\f bla\\\ \n

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Question about CPAN

2004-01-14 Thread Tassilo von Parseval
On Wed, Jan 14, 2004 at 03:05:20PM -0500 Hemond, Steve wrote:

 I just used CPAN for the first time and everything is FINE. :-)
 
 After the initial configuration setup is done, it suggest me to install
 Bundle::CPAN.
 
 First of all, what is that module?

It is the very module you were using in this moment (bundled with its
prerequisites, hence it's a 'bundle'). I'd always keep it up-to-date so
it's a good idea to do a 'install Bundle::CPAN'.

 Second of, I have noticed that it installed Readline, so my CPAN shell
 looks like the bash shells (they obviously both use readline). That
 leads me to another question (Aix users listen!) : Why in subshells
 running ftp, telnet, cpan (initially), the backspace does ^H ? I run ksh
 as my default shell but I always got this problem when running these
 programs. Just before I have installed readline for CPAN, my CPAN shell
 was writing ^H's when backspacing.

I don't know. It's certainly not related to Perl in any way.

 Could anyone guide me to a document talking about .pm's? I didn't think
 they were compiled (make)?

Can you be more specific? Those files are Perl modules and thus they are
written in Perl (they are usually the meat of any stuff you download
from the CPAN). That means that these never need to be compiled. Around
95% of the CPAN will not require any compilation. Perl modules written
in (or containing) C need a C-compiler.

As for 'make', this is not doing the compilation, if any. 'make'
processes a Makefile that contains certain rules. It is most often used
for building and installing a piece of software. Most of the modules on
the CPAN contain a file 'Makefile.PL' that - when run - produces a file
called 'Makefile'. After you have that, you can continue with

make
make test
make install

The first line will do any necessary preparations (this could also be
compiling C code when the module contains bits of it). The second line
triggers the rule 'test' which will run any tests enclosed in the
package. The last one finally installs the module.

When you use the cpan shell, all the above happens behind the scenes.
More precisely, in this order:

perl Makefile.PL
make
make test
make install

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to parse Microsoft Outlook Inbox

2004-01-08 Thread Tassilo von Parseval
On Thu, Jan 08, 2004 at 10:37:02PM -0500 Wiggins d'Anconia wrote:
 PerlDiscuss - Perl Newsgroups and mailing lists wrote:
 Hi,
 I am trying to write a script that will parse Microsoft outlook Inbox
 to a .txt file.  Please let me know if there a way to do that.  Thanks in
 advance for your help.
 
 
 
 I know very little about this specific subject, but Mail::Box has some 
 support for Outlook (maybe only express) mail, via Mail::Transport::Dbx. 
  It is read only which sounds like it should support your purposes, and 
 works on dbx files whatever those are.  Other than that I haven't seen 
 any outlook mail parsers before...

In the hope that the OP was a little sloppy in his wording and he did in
fact mean Outlook Express then, yes, he can use Mail::Transport::Dbx
either directly or through Mail::Box. Those dbx files are OutlookX'
equivalents to the standard mbox format.

If he really meant Outlook, then he's out of luck (heh). I had a look at
the libpst (which is by the same authors as the libdbx used in
M::T::Dbx) but that rather put me off. Outlook's formats are infinitely
more complicated (there seem to be two versions of those living in
parallel even).

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Happy Birthday Perl

2003-12-18 Thread Tassilo von Parseval
On Thu, Dec 18, 2003 at 03:08:05PM +0530 Swaminathan Gopal wrote:

 There are many interesting data about Perl in perlhist. For example,
 
 perldoc perlhist | perl -ne 'print if /larry.+\d+-\w+-\d+/i' | head -1
Larry   1.000  1987-Dec-18
 
 Happy Birthday Perl!
 
 Btw, how can we do the above without using head -1? Any Perl way?

Sure:

perldoc perlhist | perl -ne 'print and exit if /larry.+\d+-\w+-\d+/i'

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: First module!!! YAAAAY!!! :)

2003-12-11 Thread Tassilo von Parseval
On Wed, Dec 10, 2003 at 02:26:40PM -0800 drieux wrote:

 On Dec 10, 2003, at 4:39 AM, Ben Crane wrote:
 
 Just sat done and put together my FIRST MODULE

 It appears that perl5.8.1 rev of h2xs has some
 minor changes:
 [jeeves: 28:] h2xs -AX Wetware::Pid
 Defaulting to backwards compatibility with perl 5.8.1
 If you intend this module to be compatible with earlier perl versions, 
 please
 specify a minimum perl version with the -b option.
 
 Writing Wetware/Pid/Pid.pm
 Writing Wetware/Pid/Makefile.PL
 Writing Wetware/Pid/README
 Writing Wetware/Pid/t/1.t
 Writing Wetware/Pid/Changes
 Writing Wetware/Pid/MANIFEST
 [jeeves: 29:]

5.8.2's h2xs has yet some more changes. It's advisable to get hold of
this version of h2xs (it will run with older perls as well) because it
creates a directory-structure that is more in accordance with the
preferred style of CPAN modules:

[EMAIL PROTECTED]:/tmp$ h2xs5.8.2 -b 5.6.0 -AX Wetware::Pid
Writing Wetware-Pid/lib/Wetware/Pid.pm
Writing Wetware-Pid/Makefile.PL
Writing Wetware-Pid/README
Writing Wetware-Pid/t/Wetware-Pid.t
Writing Wetware-Pid/Changes
Writing Wetware-Pid/MANIFEST

Furthermore, another thing I tend to keep up-to-date is
ExtUtils::MakeMaker. With a recent EU::MM and the conventional

perl Makefile.PL
make
make dist

a decent META.yml is created and added to the distribution.

 NOW comes the 'big uglies' about the design
 philosophy issues - Unless you are Lincoln Stein,
 do not try to make your module BOTH OO-ish and Procedural,
 it can be done - but pick one or the other.

I suppose that mixing styles can be done in a clever way. However,
obscenities such as the approach of CGI.pm really should be avoided.

 I come from the 'put the POD in a Foo.pod file'
 school, others come from the 'interleave pod and code',
 while some are true believers of the 'pod at the end'.
 But think about how other persons pod has helped you,
 do the same.

I used to belong to the 'interleave pod and code' school but soon
changed that when I realized that there is no way to interleave POD into
XS files.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: First module!!! YAAAAY!!! :)

2003-12-11 Thread Tassilo von Parseval
On Thu, Dec 11, 2003 at 09:32:18AM -0800 drieux wrote:

 On Dec 10, 2003, at 11:35 PM, Tassilo von Parseval wrote:

 a decent META.yml is created and added to the distribution.
 
 I'm still working out if i really 'get it'
 about the 'yml' trend.

I haven't yet grokked it either. AFAIK it's one day going to be CPAN's
reservoir for meta data on modules. This was as much as I was able to
deduce from following the discussions on the porters-list. And since my
attempts to get the specs for these META.yml failed, I am the more happy
that the latest EU::MakeMaker creates it for me.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: First module!!! YAAAAY!!! :)

2003-12-11 Thread Tassilo von Parseval
On Thu, Dec 11, 2003 at 11:29:14AM -0800 drieux wrote:
 
 On Dec 11, 2003, at 10:28 AM, Tassilo von Parseval wrote:
 [..]
  And since my attempts to get the specs for these META.yml failed,
 I am the more happy that the latest EU::MakeMaker creates it for me.
 [..]
 
 Excuse me while I giggle UNCONTROLably ( yes, I know
 that is read as 'screaming, in some ascii art - it was
 so intended. { ok, so I not spelt gooder in ascii either } )
 
 p0: given that 'ya' traditionally denotes 'yet another',
 it worries me that most folks do not see 'yada'
 as 'yet another dumb acronym'. Mean while we have shifted
 from 'yaml' to 'yml' as the TLA suffix...

Dropping the 'a' is mostly a concession to archaic operating systems
that tend to expect 8.3 filenames.

 p1: given that I have been living with the dialectical
 tension of the voices in my head, where on one side
 i have 'sgt. rock' asking do we have a dog in this fight?
 and the 'college boy' in me willing to get 'wrapped
 around the axil' for some purely pedantic issue
 
 I think I'll just follow your lead Sarge
 
   If and when they decide that we really need to
   know how exactly they want to deal with this
   yaml-ization I am more than sure that the
   word will come on down from on high, and at
   that time College Boy we will tell you your position...
 
 Which of course is what makes me just bend over
 and giggle at the growth and/or bloat in
 
   h2xs, the EU::MM and ...
 
 not to mention the ongoing efforts to either
 adopt the Build v. Maker Model, and the ... and ...

Especially the latter discussion has something to do with the
growth-problem. Traditionally, h2xs started as a tiny script that
created a skeletal directory structure with a few templated files in it.
However, that was obviously not powerful enough so it was tweaked to
automatically generate XS files based on some C headers fed to it. 

Once XS was tackled, the question was raised why it shouldn't also
generate accessors for functions defined in C headers. This unfortately
introduced a new prerequesite, namely C::Scan which is a module that
should have never been allowed into the wild and onto the CPAN. Since
this module is a non-core module, not every h2xs has the same
capabilities. Three flavours exist: those not having any C::Scan at
their disposal, those with an old C::Scan and those with a recent enough
C::Scan so that the -m and -a options can be used (calling those
switches obscure would be too favourable).

Since h2xs should continue running on any platform, edge cases like VMS
etc. had to be handled as well.

The result over the years is a script of around 1700 lines to which
maybe 20 different people have contributed. It's living proof that
security through obscurity is in fact a decent approach when done
'properly' and with enough imagination.

Rewriting it from scratch is impossible since the code wont reveal what
it does (my attempt of doing it is still buried deep down in my
home-directory). Furthermore, those people responsible for a particular
change either died or hide in shame so that there is no person alive who
could definitely say whether a particular clean-up to parts of the code
would be functionally equivalent.

EU::MM has a very similar biography, only that it is still maintained by
one brave guy who nonetheless freely admits that M::Build should be used
instead just because at some not too distant point in the past patching
EU::MM will become impossible.

 p2: Next time I think we should have a nice clean
 useful and appropriate BDUF about how Perl Really
 should have been built, developed, maintained, so
 that all due regards to the efficiencies of the
 algorithms with conform to the matrix of maintainablity...

There is no such thing as a dictum of maintainability in the context of
Perl5. Efficiency has always been one but - when done properly - doesn't
leave any room for maintainability. But it does change the way Perl5
develops now. New features are hard to get in because the people
involved have become cautious: They know that any new piece on top could
make the whole card-house collapse. Maybe not now, but possibly half a
year later.

This is why Perl6 is on its way and promises to solve a lot of those
problems. Sometimes something functional has to be torn down in order to
build something better.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: The True Path to Learning Perl Re: [OT] Education Level

2003-12-09 Thread Tassilo von Parseval
On Mon, Dec 08, 2003 at 11:33:08PM -0800 drieux wrote:

 On Dec 8, 2003, at 2:50 PM, Tassilo von Parseval wrote:
 [..]
 The current set of perl-porters that are able and willing
 to work on the core are with
 not many exceptions people with academic degrees.
 [..]
 
 hypothetical question,
 
 would one need to be a perl-porter
 to write good perl?

Had you questioned that one needs an academic degree to learn Perl, this
would be a viable question. But that was not what you said. Let's
refresh your memory:

 Learn to be nice to undergrads and grad students.
 Think about the unpleasant lack of experience that
 they have in a wide range of issues. Most of them
 grew up in normal homes with median types of families.
 ALL they have to 'validate their personhood' IS that
 college degree, and their 'connections'. Unlike
 the rest of us who have different sets of 'connections'
 and different sets of Rules that drive our 'risk analysis'.

You were referring to a 'wide range of issues' and not to Perl in
particular.

I was targetting the cited paragraph. I don't argue that
you need the academic background to learn a programming language.
However, knowing a language itself isn't very much compared to the
problems that are waiting to be solved using this language.

 { would it be impolite to note in which language/languages
 the perl executable is 'written in'??? }

Not at all, why should it?

 but since you have been ever so polite as to offer
 the opportunity, allow me to note one of my most favorite
 and silly misadventures in AcadamiaLand, 

[ little fairy-tail snipped ]

You'll have a hard time trying to induce the general from the particular
case. You'd need a proper induction for that which you haven't provided.

 So when you put my comments to Jason, and those who like
 jason, may be having issues with the INSANITY of the
 american educational system, back into their context,
 then you might want to actually go back and re-read them
 for what they are.

Unfortunately, you haven't provided this context. Furthermore, I don't
find any notion of the word America or American in your posting I
was referring to. Hence I must assume that you were talking about
academia in general.

 yes, yes, I know you are posting from aachen, so take the
 liberty moment and enjoy that I am not complaining about
 Germany... But if you wish I can do a few Herr Doktor
 stories if that would make you feel fuzzyWarm?

No, it wouldn't. Besides, I take the liberty to claim that I have in
general quite a good insight into the German academic system. It does
have its rotten parts but it clearly does not suffer from any of the
points that you mentioned.

 I can appreciate that I clearly must have ruffled some
 feathers, but could the issue be that there is a boring
 practicality to Perl that still escapes you? 

Me escaping Perl's practicality? No, I don't think so. And I wouldn't
indulge with Perl if I found it boring, would I?

A practicality that any reasonable person can acquire??? If on the
other hand what they WANT is to understand 'algorithm construction' and
sound 'performance analysis' - and the only place that one can do that
is, allegedly, in 'the university' then go to it! DO THAT! But suddenly
one has a Reasonable Excuse to be IN COLLEGE somewheres! But if the
programme is not taking you where you want to go, BAIL! GET OUT! RUN
AWAY!

Anyway, you are switching topic once again. I can only follow-up to
things that have actually been there. None of the above was to be found
in this previous posting of yours though.

The credo of your original message was rather flat and shallow: Avoid
university at all costs because it can't teach you anything worthwhile.
This is an immature statement which I addressed.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: passing code inside function

2003-12-09 Thread Tassilo von Parseval
On Tue, Dec 09, 2003 at 09:14:52AM +0100 [EMAIL PROTECTED] wrote:

 I would like to read something about passing code inside function. Lets say
 that:
 
 This works:
 perl -e 'sub a(){print({$_[0]}, /n};$_=0; a {$_++} foreach 1..100'
 
 This don't work
 perl -e 'sub a{print({$_[0]}, /n};$_=0; a {$_++} foreach 1..100'

It will work once you do

perl -e 'sub a{print({$_[0]}, \n)}; a sub {$_++} foreach 1..100'

The prototype '' will let perl treat a bare block as a codereference.
If there is no such prototype, you have to construct the code-ref
yourself, which can happen in several ways:

\func; # reference to the named function 'func'
sub { ... } # reference to an anonymous function

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: The True Path to Learning Perl Re: [OT] Education Level

2003-12-09 Thread Tassilo von Parseval
On Tue, Dec 09, 2003 at 01:43:06AM -0800 drieux wrote:

 On Dec 9, 2003, at 1:24 AM, Tassilo von Parseval wrote:
 [..]
 hypothetical question,
 
 would one need to be a perl-porter
 to write good perl?
 [..]
 
 let us get simple.
 
 how about answering the simple question.
 
 it was the core of your alleged argument.

No, it wasn't. Since you are so sure about it, maybe you just quote the
relevant parts of what I wrote instead of making wild assumptions.

The core of my statement was that Perl wouldn't be Perl as we know it if
there hadn't been some people with academic backgrounds working on its
core. This was a direct reply to your claim that academic education is
essentially useless.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: The True Path to Learning Perl Re: [OT] Education Level

2003-12-08 Thread Tassilo von Parseval
On Mon, Dec 08, 2003 at 12:43:37PM -0800 drieux wrote:

 Learn to be nice to undergrads and grad students.
 Think about the unpleasant lack of experience that
 they have in a wide range of issues. Most of them
 grew up in normal homes with median types of families.
 ALL they have to 'validate their personhood' IS that
 college degree, and their 'connections'. Unlike
 the rest of us who have different sets of 'connections'
 and different sets of Rules that drive our 'risk analysis'.

Pretty big words by someone who happily admits to not have chosen the
academic part. I wonder whether you really know so much about the
contents of academic studies.

 At best they know what they have been taught,
 and rarely have they had the time to test their
 speculations. So if you want to learn Perl, learn it!
 Test out Ideas! See how things can be done! That
 good old fashion all american approach of basing
 one's opinion upon what one has DONE

And at this point it gets utterly ridiculous. Since this is a list
dealing with Perl, we can try to make this thread a little more on topic
by looking at the people who made and still make Perl. The current set
of perl-porters that are able and willing to work on the core are with
not many exceptions people with academic degrees. There are others as
well, but those are usually not responsible for the tricky bits that do
require more than a little bit of self-teaching: you don't usually
self-teach yourself enough number theory that is necessary for coming up
with a sane hashing-algorithm or random number generator. A self-taught
programmer will most definitely not be able to understand (let alone
create) a regular expression engine. The things to be considered when
crafting a memory allocater are usually beyond the things an autodidact
has picked up. It's stuff that can be found in the old venerable
computer-science text books that are recommended in academic circles.

 IF you learned how to do the process of learning,
 Then WHY get a college degree??? IF your skill
 mix is taking you where you want to be, then
 rock ON! if it is not, figure out where you
 want to be and go there.

I am sorry. This only works for the very simple problems. Those
problems, that are indeed not teached in university, because a graduate
is expected to acquire these things on his own. 

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Seeding a Random Number Generator

2003-12-07 Thread Tassilo von Parseval
On Sat, Dec 06, 2003 at 04:38:02PM -0800 John W. Krahn wrote:

 Pd Schloss wrote:

  I'm reviewing a perl script that someone wrote to do a statistical
  analysis.  I know it's bad form, but I was wondering if anyone knows
  what the default seed is for the random number generator in Perl.  They
  haven't seeded it with srand - what does this do?  It still seems to
  pick random numbers, any ideas?
 
 Download the source code for Perl if you don't already have it and have
 a look at the pp.c file.

The actual seed is calculated in Perl_seed() in util.c. The calculation
of the seed itself is highly dependent on the platform used. It involves
various things, such as gettimeofday(2), the PID, a value read from a
random device such as /dev/urandom, the position of PL_stack_sp in
memory etc. For most cases it should be quite ok.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using perl in a c code

2003-12-04 Thread Tassilo von Parseval
On Wed, Dec 03, 2003 at 05:17:01PM -0600 Dan Muey wrote:

 Doh! I was on 5.5, 5.8 just worked for me to, 5.6.1 also!

In order to make your C code more portable across several versions of
the perlapi, you could use Devel::PPPort.

perl -MDevel::PPPort -eDevel::PPPort::WriteFile

will create ppport.h in the current directory. You could take this file
and #include it in your source code. Many macros and some functions from
recent perls are thus also available in older perls.

With this (it corresponds to the -b switch of h2xs) it's relatively easy
to write XS or XS-alike code that runs under many Perl versions.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using perl in a c code

2003-12-03 Thread Tassilo von Parseval
On Tue, Dec 02, 2003 at 05:40:14PM -0600 Dan Muey wrote:

 What I was wondering about was how to execute some perl code *inside*
 the c program instead of takign it via ARGV.  I  think eval_pv and
 eval_sv have somethgin to do with it but I'm a bit cloudy there.
 Since I don't know hardly anythgin about C I'll illustarte it in Perl.
 
 my $perlcode = CODE;
   # instead of getting this via command line argument
   sub simplepage {
   my $name = shift || 'world';
   use CGI qw(header param);
   print header()
   print I am perl hear me roar $name\n;
   print insult();
   }
   sub insult { return So is ytour mother\n; }
   return simplepage(param('name'));
 CODE
 
 printf eval_pv($perldoc);
 
 Basically execute bunch of code, from a one liner to a bunch of lines,
 that basically ends with one return value(an html webpage) and then
 print that value out. 

This can't work because you cannot have return-statements outside of
subroutines in Perl. However, why not just leave the 'return' off:

my $perldocde = CODE;
...
simplepage(param{name});
CODE

And from C:

STRLEN  n_a;
char*string;
SV  *ret;
...
ret = eval_pv(perlcode, TRUE);
string = SvPV(ret, n_a);

eval_pv() returns the last statement evaluated as a SV.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using perl in a c code

2003-12-03 Thread Tassilo von Parseval
On Wed, Dec 03, 2003 at 09:35:54AM -0600 Dan Muey wrote:

  On Tue, Dec 02, 2003 at 05:40:14PM -0600 Dan Muey wrote:
  
   What I was wondering about was how to execute some perl
  code *inside*
   the c program instead of takign it via ARGV.  I  think eval_pv and
   eval_sv have somethgin to do with it but I'm a bit cloudy 
  there. Since
   I don't know hardly anythgin about C I'll illustarte it in Perl.
   
   my $perlcode = CODE;
 # instead of getting this via command line argument
 sub simplepage {
 my $name = shift || 'world';
 use CGI qw(header param);
 print header()
 print I am perl hear me roar $name\n;
 print insult();
 }
 sub insult { return So is ytour mother\n; }
 return simplepage(param('name'));
   CODE
   
   printf eval_pv($perldoc);
   
   Basically execute bunch of code, from a one liner to a
  bunch of lines,
   that basically ends with one return value(an html webpage) and then
   print that value out.
  
  This can't work because you cannot have return-statements
  outside of subroutines in Perl. However, why not just leave 
  the 'return' off:
  
  my $perldocde = CODE;
  ...
  simplepage(param{name});
  CODE
  
  And from C:
  
  STRLEN  n_a;
  char*string;
  SV  *ret;
  ...
  ret = eval_pv(perlcode, TRUE);
 
   Is that a variable?

Yes. When I wrote 'char *string', I meant 'char *perlcode' actually.

   How would one safely get some code into a C variable?
   Like in Perl I can use qq() or similar or escape certain 
   chacters. So double quotes don't kill me.

I can't really answer that because I don't understand what you want to
achieve. In the above, 'perlcode' is a plain C string containing the C
source. How you populate it is totally up to you.

Can you once more explain why you want a C program that executes Perl
code given as a string? And how should the Perl code be injected into
the C program?

  string = SvPV(ret, n_a);
  
  eval_pv() returns the last statement evaluated as a SV.
  
 
 Thanks for the insight!  So, if I understand it right (and assuming I
 compile it properly of course ;p) I would need something like this:
 [questions commented]
 
#include EXTERN.h
#include perl.h
 
static PerlInterpreter *my_perl;
 
main (int argc, char **argv, char **env)
{
STRLEN n_a;
char*string; /** added to perldoc example **/
SV  *ret;/** added to perldoc example**/
 
my_perl = perl_alloc();
perl_construct( my_perl );
 
perl_parse(my_perl, NULL, 3, embedding, NULL);
perl_run(my_perl);
 
ret = eval_pv(perlcode, TRUE); /** So how do I get my code safely into 
 perlcode ?? **/

You can always do

const char *perlcode = use CGI; ...;

This however is tedious since you can't break literal C strings into
several lines and have to escape double-quotes etc. There are probably a
million ways to fill a string. It really depends on your requirements.

/** could I just printf(SvPV(...)) right here and shorten it a bit?? **/

You could do:

printf(%s, SvPV(eval_pv(perlcode)));

string = SvPV(ret, n_a);
 
perl_destruct(my_perl);
perl_free(my_perl);
 
/** Would this be better right after string = SvPV(...) or after perl_free() 
 ?? **/
printf(string); 

Probably better before you destruct and free the Perl interpreter.
SvPV() does not return a copy of the string in the scalar variable. It
returns the pointer in it. So it could happen that the memory this
pointer points to has been freed because the Perl interpreter has been
destructed.

How much of the allocated memory perl frees when exiting depends on the
PERL_DESTRUCT_LEVEL (perl checks the value of this environment variable
when exiting). Per default perl doesn't clean up very much and leaves
this work to the operating system. Nonetheless, it's safer to access the
perl-related memory before perl_free() happens.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using perl in a c code

2003-12-03 Thread Tassilo von Parseval
On Wed, Dec 03, 2003 at 11:33:53AM -0600 Dan Muey wrote:

 Ok, I can compile this example with:
 cc -o perlemb perlemb.c `perl -MExtUtils::Embed -e ccopts -e ldopts`  
 
 I can run it like this:
 ./perlemb -e 'print Howdy;'
 Howdy
 Or
 ./perlemb
 print Howdy;
 cntrl D
 Howdy
 
 Here's what I have on the inetrnal version (IE the perl to execute is provided 
 inside and not via cmd line)
 
 #include EXTERN.h   /* from the Perl distribution */
 #include perl.h /* from the Perl distribution */
 
 static PerlInterpreter *my_perl;  /***The Perl interpreter***/
 
 int main(int argc, char **argv, char **env)
 {
 my_perl = perl_alloc();
 perl_construct(my_perl);
 perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
 perl_run(my_perl);
 perl_destruct(my_perl);
 perl_free(my_perl);
 }
 
 What I'd like to do with this is:
 
 ./perlemb2
 Howdy
 And eventually through using CGI's param() perhas:
 ./perlemb2 name=JoeMama
 Howdy JoeMama

I would assume that this works with the C program in the very same way
as it works with Perl.

 What I have so far for testing is:
 
 #include EXTERN.h
 #include perl.h
 
 static PerlInterpreter *my_perl;
 
 main (int argc, char **argv, char **env)
 {
STRLEN n_a;
const char *perlcode = use CGI 'header';print header();print 'hello World';;
 
my_perl = perl_alloc();
perl_construct( my_perl );
 
perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
 
perl_run(my_perl);
 
printf(%s, SvPV(eval_pv(perlcode)));
 
perl_destruct(my_perl);
perl_free(my_perl);
 }
 
 But when I compile it the same way as the first I get:
 
 perlemb.c:18: macro `SvPV' used with just one arg

Yep, indeed, I forgot the second argument. 

 So I tried it as 
 printf(%s, SvPV(eval_pv(perlcode),n_a));
 Which is how it was in another example and got:
 
 perlemb.c: In function `main':
 perlemb.c:18: invalid type argument of `-'
 perlemb.c:18: invalid type argument of `-'
 perlemb.c:18: invalid type argument of `-'
 perlemb.c:18: warning: passing arg 1 of `Perl_sv_2pv' makes pointer from integer 
 without a cast

Ah, right. One has to take care with the perlapi since many things are
in fact macros and not functions. SvPV() is one and it wont accept an
expression. You need to use a proper variable:

STRLEN n_a;
SV *res = eval_pv(perlcode);
printf(%s, SvPV(res, n_a));

Maybe I can also point you to [EMAIL PROTECTED] If you want to do the
occasional XS or embedding, this mailing-list is the right place to
consult.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Encrypting PERL source code...

2003-12-01 Thread Tassilo von Parseval
On Mon, Dec 01, 2003 at 01:39:43PM -0500 [EMAIL PROTECTED] wrote:

 Can anyone suggest where I might be able to find (hopefully a freeware
 or shareware script..) a program that runs either on a windows system or
 a PERL script that would encrypt a perl script by doing such things as
 removing whitespace, etc. so that it is much more difficult to read but
 yet will execute as if unencrypted?? I'd like to make the source code
 as difficult to pirate as I can for a program that I'm developing.

Those attempts are usually futile since compiled Perl-code can be
deparsed. Of course, when those pirates you have in mind are a little
retarded, you could use one of those many Acme:: or Acme-alike modules
on the CPAN. I quite like SuperPython. This line transforms any Perl
script into a script that can be run by SuperPython:

perl -ne 's/(.)/  x ord($1).\t/ge; print' script.pl  script.spy

And in order to execute it, either do a

perl -MSuperPython script.spy

or add 'use SuperPython;' on top of the encrypted script.

But note that 

perl -MO=Deparse -MSuperPython script.spy

would for instance yield

BEGIN { $^W = 1; }
use SuperPython;
my $code = sub {
my $arg1 = shift @_;
sub {
$arg1 + shift(@_);
}
;
}
;
print $code(5)-(6);

which could easily be more readable than the original script was.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Where is editor that will Indent my perl code?

2003-11-03 Thread Tassilo von Parseval
On Mon, Nov 03, 2003 at 11:54:38AM -0800 Richard Heintze wrote:

 Tim (or anyone else)
 I have vim 6.1 and tried it out. I know VI (a little)
 so I thought vim would not be so bad. I tried help and
 searching help for indent and found it. It looks more
 like a function call for their macro language than it
 does a command. I tried :indent(6) and it did not
 work.
 
  How do I use VIM to re-indent a perl function?

Indenting usually happens automatically when you put 'set autoindent'
into /etc/vimrc (or whereever your vim looks for its configuration,
possibly also ~/.vimrc).

Re-indenting happens by marking a paragraph in visual mode (shift+v and
then moving around with the arrow keys) and hitting '='.

   Also, I assume by your response that PerlBuilder
 indents code too?

You don't need that. vim has excellent indenting and
syntax-highlighting. The same is said to be true for the cperl mode of
emacs.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: array of arrays

2003-10-20 Thread Tassilo von Parseval
On Mon, Oct 20, 2003 at 12:33:00PM +0200 Christiane Nerz wrote:

 How do I read data out of a table-file in an array-of-arrays?
 
 Problem: I have to compare two tables with pairs of start-stop-Positions.
 I want to find out, which pair of Start-Stop-Position in table_1 is 
 entirely within the range marked by a pair of start-stop-positions of 
 the second table.
 2..5 would be in 2..6 or 1..7, 45..46 in 23..47 or 40..46 and so on.

Do these strings show up in the table like that? In this case, it should
not be so hard:

my $range1 = 2..5;
my $range2 = 2..6;

my ($start1, $stop1) = $range1 =~ /(\d+)\.\.(\d+)/;
my ($start2, $stop2) = $range2 =~ /(\d+)\.\.(\d+)/;

print $range1 within $range2 if
$start1 = $start2 and
$stop1  = $stop2;

Is it something like that you were asking for? I am not yet sure where
array of arrays are involved.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Perl Vs ...

2003-09-22 Thread Tassilo von Parseval
On Sun, Sep 21, 2003 at 09:28:21PM -0400 Paul Kraus wrote:

 Perl was pretty much my first language. Not counting Business Basic and same
 old Pascal from high school. The more I learn the more I see that perl can
 handle just about anything I want to do. How do you go about deciding if you
 should use another tool such as C++ over perl? I am thinking about learning
 another language and trying to decide what language would be best to learn.
 To expand my skill set. Suggestions, Ideas, Book Recommendations?

I was always of the opinion that knowing C is one of the essential
things. Too many vital stuff is nowadays hidden away from the user in
more recent languages (such as portability issues and memory management
for instance).

C also has the advantage that it integrates tightly into perl. You can
write Perl modules as C extensions which is fun and will teach you a lot
about perl and how interpreters in general work.

However, C's learning curve is rather steep (but shorter than Perl's).

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Perl Vs ...

2003-09-22 Thread Tassilo von Parseval
On Sun, Sep 21, 2003 at 09:17:38PM -1000 Marc Adler wrote:

 * Tassilo von Parseval [EMAIL PROTECTED] [2003-09-21 20:27]:

  I was always of the opinion that knowing C is one of the essential
  things. Too many vital stuff is nowadays hidden away from the user in
  more recent languages (such as portability issues and memory management
  for instance).
  
  C also has the advantage that it integrates tightly into perl. You can
  write Perl modules as C extensions which is fun and will teach you a lot
  about perl and how interpreters in general work.
  
  However, C's learning curve is rather steep (but shorter than Perl's).
 
 Would learning C++ do just as well? On many of the C/C++-related
 websites/newsgroups they say that there's no point in learning C because
 you'll have to unlearn a bunch of bad habits when you learn C++ (I
 don't know either language, so I don't know what those habits might be).

Well, the same is probably true the other way round. C and C++ are not
the same languages. If that would really matter, you could always only
learn one of them.

If one plans on learning both of them, C should come before, I think. C
is a minimal language whose concepts you should know when doing C++.
There are subtle differences between seemingly similar things though. A
good C++ introduction should mention them.

 Also, how commonly is perl learned as a first language?

I don't know. For me it was de-facto the first language. I learnt
Modula-3 before that but I'd rather not want to talk about that. Knowing
Perl made it pretty easy (in my perception) to learn other languages. In
my case this was mainly Java (unsuitable as first language because it
disallows too many things) and after that C (though: no matter which
language you learnt first, learning C will sooner or later make you send
curses towards heaven; so many things don't work in the beginning).

  $_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
  pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
  $_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval
 
 What's all that?

It's a JAPH. See 'perldoc -q JAPH'. If you preserve the whitespacing of
the above, you can run it as Perl code.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using foreach on an array

2003-09-20 Thread Tassilo von Parseval
On Sat, Sep 20, 2003 at 03:56:14PM +0530 Ramprasad A Padmanabhan wrote:

I have a script in which I am using foreach in two diff ways
 I am doing a last; in the very first loop So each time the variable $t 
 should be assigned only once.
 
 But you can see the results dont match.
 
 
 #!/usr/bin/perl
 use strict;
 use warnings;
 
 my @alpha = qw(a b c d );
 my $t=;
 foreach ( @alpha ){
   $t=$_;
   last;
 }
 
 print Value of t is '$t'\n;
  # OUTPUT: Value of t is 'a'
 
 $t=;
 foreach $t  ( @alpha ){
   last;
 }
 print Value of t is '$t'\n;
  # OUTPUT: Value of t is ''
 
 exit 0;
 
 
 Not that it is a big problem for me , In my actual script I just have 
 avoided the second format and my problem is solved. But the puzzle is, 
 How does $t get reset in the foreach

The answer is in 'perldoc perlsyn':

   The foreach loop iterates over a normal list value and sets the vari- 
   able VAR to be each element of the list in turn.  If the variable is 
   preceded with the keyword my, then it is lexically scoped, and is 
   therefore visible only within the loop.  Otherwise, the variable is 
   implicitly local to the loop and regains its former value upon exiting 
   the loop.  If the variable was previously declared with my, it uses 
   that variable instead of the global one, but it's still localized to 
   the loop.

The last sentence is important here: Even though $t is a lexical
variable in your program, it's value is nonetheless localized inside the
loop and regains its previous value when leaving it.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: STDIN

2003-09-15 Thread Tassilo von Parseval
On Mon, Sep 15, 2003 at 06:25:29PM +1000 Vema Venkata wrote:

 I had rewritten as per ur suggestions but 
 there is no prompt like this choose Change_Request,call_req or Both?#;
 
 pls advise
 
 
 
 print choose Change_Request,call_req or Both?#;
   my$choose_table= STDIN;   #user has to key in 
 Change_Request,call_req,Both
   chomp $choose_table;

Maybe this is a buffering problem. Try

$| = 1; # turns on autoflush
print choose Change_Request,call_req or Both?#;
chomp(my $choose_table= STDIN);

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: reset a file pointer

2003-09-05 Thread Tassilo von Parseval
On Fri, Sep 05, 2003 at 03:25:46PM +0530 Sachin Mathur wrote:
 Hi , 
  I am a beginner in perl I would like to know how to reset a file
 pointer in perl. Is their a rewind command in perl

Yes, it's called seek():

use Fcntl qw/:seek/;

seek FILE, 0, SEEK_SET;

The first line is only for importing the SEEK_* constants for the sake
of portability. See 'perldoc -f seek'.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DynaLoader with nonstandard lib location

2003-08-28 Thread Tassilo von Parseval
On Wed, Aug 27, 2003 at 06:00:40PM -0700 Reid Beels wrote:

 I'm trying to install a module (Image::Imlib2) which depends on  
 DynaLoader being able to find an external C library.  Normally, this  
 wouldn't cause a problem but I'm being forced to install the module on  
 a system which I do not have root access on and thus must store the  
 both the module and the library it seeks in a nonstandard location.   
 The location for the module is working fine, as expected, but I have  
 yet to find a way to tell DynaLoader to look in the correct place for  
 the library.  I have tried adding
 
 push(@DynaLoader::dl_library_path, '/home/lwire/perllib/clib');
 
 to both the script which I am calling Image::Imlib2 from and to  
 Imlib2.pm itself.  Either way, I receive the following error:
 
 Can't load  
 '/home/lwire/perllib/lib/perl5/5.6.1//i686-linux/auto/Image/Imlib2/ 
 Imlib2.so' for module Image::Imlib2: libImlib2.so.1: cannot open shared  
 object file: No such file or directory a
 t /usr/lib/perl5/5.6.1/i686-linux/DynaLoader.pm line 206.
 
 Do I need to be defining dl_library_path somewhere else or is there  
 some other method that I can use to define the search path??

Rather LD_LIBRARY_PATH. Set this environment variable so that it
contains the directory where the imlib2 object files reside. I think
that DynaLoader uses dlopen(3) and related functions to dynamically
include a library and those functions look in LD_LIBRARY_PATH.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: -w vs. use warnings

2003-08-28 Thread Tassilo von Parseval
On Thu, Aug 28, 2003 at 04:17:21PM -0400 K Old wrote:

 Having been a Perl programmer for several years now I have become
 accustom to using the following as my normal start of any Perl script:
 
 #!/usr/bin/perl
 use warnings;
 use strict;
 
 Randal Schwartz uses this:
 
 #!/usr/bin/perl -w
 use strict;
 $|++;
 
 Is there any difference between the -w and use warnings declaration?
 I know that both turn on warnings and the -w is commonly used at the 
 command line, but was just curious as to if one was better than the other.

They are not the same thing, although somewhat related. The warnings
pragma gives you very fine-graned control. It turns on warnings for
blocks and can likewise be switched off for them. Furthermore, you can
surpress particular warning categories altogether as in

use warnings;
$a = $b = foobar;
print undef;
{
no warnings 'uninitialized';
print undef;
print $a + $b;
}
print undef;
__END__
Use of uninitialized value in print at - line 3.
Argument foobar isn't numeric in addition (+) at - line 7.
Argument foobar isn't numeric in addition (+) at - line 7.
Use of uninitialized value in print at - line 9.

As you see, no warning for line 6, but a warning for the line 7 in the
same scope. The various categories that exist are listed in
perllexwarn.pod.

-w on the other hand is truely global. Turn it on anywhere and suddenly
warnings show up from code that you haven't even written (like warnings
produced in modules you use). They can be turned off lexically scoped by
issuing 

local $^W = 0;

though. But you can't distinguish between a warning caused by comparing
a string with a number and, for instance, one caused by using undefined
values.

 One other item, Randal uses $|++; to turn off the buffering for STDOUT.
 What exactly is buffering of standard output?

Buffering means that the data you send to a channel isn't going through
right away but ends up in a buffer. STDOUT is typically line-buffered.
That means, data go to STDOUT but wont be printed before a newline was
sent (or the buffer is full). This is an efficiency thing because it
reduces the number of syscalls. STDERR is typically not buffered which
explains why you often get messages to STDERR before the regular output
to STDOUT.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: beginner trying to parse a piece of mail

2003-08-26 Thread Tassilo von Parseval
On Mon, Aug 25, 2003 at 05:19:14PM -0700 nntp.perl.org wrote:

 I have had success now using Mail::MboxParser for all my basic mail parsing
 needs, like getting subject, from, to.  Now bossman wants me to do more
 extensive regex filtering and grabbing weird data in the email body.
 
 I wrote a little test script, shown below.  I am able to get the
 appointment date data, contained in the message body, that I am looking
 for, but only for the first record.  The while loop keeps looping back to
 that record.  Also, I cannot get to the next line that has the comments
 section for each email.  I know this has got to be something stupid I am
 not seeing, but after looking at this for so long, everything is starting to
 blur together.  Would anyone have any insight as to my mistake?

You want to loop over the lines of the body, right?

 #!/usr/bin/perl
 use Mail::MboxParser;
 my $mb=Mail::MboxParser-new('MyMailbox', decode = 'ALL');
 
 #grab data from the body of the message
   while (my $msg = $mb-next_message) {
   $test = $msg-body($msg-find_body) ;
  while (defined($_=$test)) {

That's an infinite loop. If you want to iterate over the lines of a
body, try

for ($test-as_lines) {
# each line now in $_
if (/App:.*Date:\s+(.{0,8})\s+Time:/) {
...
} 
else if (/Comments/) {
...
}

   if ($test =~ /App:.*Date:\s+(.{0,8})\s+Time:/) {
  #looking for appointment data here
  print I see the appointment date is $1, \n;
   } elsif ($test =~ /Comments/) {
  while (($test=) !~ /(Notification|XEDB)/) {

What should this while-loop achieve?  reads from STDIN. I am sure you
don't want that.

  $comments .= $_;
  chop($comments);
  $comments .=  ;
  print The comments are, $comments;
  }#end while ($test=)
   }#end elsif
   }#end while (defined($_=$test)) {
   }#while (my $msg = $mb-next_message)

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Full path to the perl intrepter

2003-08-26 Thread Tassilo von Parseval
On Tue, Aug 26, 2003 at 04:12:59PM +0200 [EMAIL PROTECTED] wrote:
 I'm in a very old project and my scripts are calling other scripts. I have 3
 or 4 different perl version in the server. I need to call the sub-scripts
 with the some version of perl that I'm using in the caller script.
 
 How to find the full path to the perl interpter that is being used?

See the entry on $^X in perlvar.pod. Probably this will already do for
you:

use Config;
my $real_perl = $Config{perlpath};

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Benchmark times

2003-08-24 Thread Tassilo von Parseval
On Sun, Aug 24, 2003 at 09:35:39AM +0200 Janek Schleicher wrote:
 Pablo Fischer wrote at Sun, 24 Aug 2003 01:45:42 +:

  Exists a website with benckmark running times in Perl?
 
 http://www.google.com/search?q=benchmark+perl+programming+languages

Benchmark between languages are - at the best of times - misleading.
They tend to contrive some seemingly common problems and compare their
implementations in different languages. Not even the p5-porters have so
far managed to come up with a reliable benchmark for comparing perl with
perl (perlbench gives nice tables but real-world programs often seem to
contradict these tables).

But as it can be seen in this thread, the problem wont be solved using
pure-Perl. Database access usually happens via modules written in C.
Therefore, a program making heavy use of an SQL database written in pure C
and one written in Perl will yield very comparable results.

I remember the longest-repeated-substring problem that was discussed
some months ago on MJD's quiz-of-the-week mailinglist. A reasonably fast
Perl solution looked very un-Perlish (doing it all with raw index() and
substr() operations for the sake of speed) and thus was easy to
translate to XS. The C implementation was faster to an degree of 5%, at
most. But sometimes it was even slower.

On the other hand, Octave for instance was written in C and Fortran. If
you take this and compare it with an implementation in Perl (if it
existed), it will surely make Perl look very poor.

So only for very sanitized ('pure') problems you'll be able to predice
which implementation will likely be fastest. The problem of the OP is no
such case. First you have the overhead of the FTP transaction,
afterwards unzipping that can either be done the slow way (Archive::Zip)
or in an intelligent way (when speed matters) through PerlIO::gzip or
even an external unzipper.

The only thing that really might make look one language more appropriate
than the other is the sorting. But again, precise figures can't be given
since Perl's sort is either very performant (when using one of the
optimized default routines) or painfully slow (with a complicated custom
comparison-routine).

Then a little bit I/O is carried out. Again, only little significance to
the language (they all are somewhat C-based). Yet, Perl is known to do
I/O a little better than most competitors. Eventually, database-access.
That's no concern when using one of the C-implementations in the DBD::
namespace.

Conclusion: most common languages should be able to do that in
reasonable time. They are no different than Perl in that they interface
with C code for tasks like working with compressed files, I/O and
databases. Unless of course you do in PROLOG or some other truely exotic
language.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: hex2Bin

2003-08-18 Thread Tassilo von Parseval
On Mon, Aug 18, 2003 at 07:34:41AM -0400 Kipp, James wrote:

  I have a file cointaing 1024  hex  numbers .
  I want to convert them to Bin.
  Please help
 
 try something like this:
 
 $hex = 0xff;
 $bin = unpack(B32, pack(N, hex $hex));

The above assumes big-endian byteorder. For little-endian use V instead
of N. Or just use L when the file has the same byteorder as the
machine you are running this script on.

Btw, the hex() above is probably wrong. hex() converts a string into a
numeric value by intepreting it as hexadecimal. Essentially, you do it
twice resulting in:

$hex = 0xff == 255 = hex(255) == 597

Whereas:

$hex = 0xff = hex($hex) == 255

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Please don't say RTFM

2003-08-16 Thread Tassilo von Parseval
On Fri, Aug 15, 2003 at 11:44:04PM -0600 Robert Mark White wrote:

 Please be gentle with me as this is only my first day trying to learn perl.
 I am using an online tutorial, however it must be written for *nix and I am
 trying to use it on win32.
 man perl does not even work.

We'll come to that later...

 I have already found some other differences.  For example, the tutorial uses
 single quotes and to get anything
 to work I had to use double quotes. There must be other things that are
 different also.
 I tried to use the examples directly in an script that would be useful to
 me. Maybe I should have tried
 something a little simplier.
 
 Any polite suggestions would be greatly appreciated.
 
 Sincerely yours,
 
 
 Robert Mark White
 
 
 The attempted script is below
 Most of the lines below are directly from the tutorial so.what!
 I think at least  the # remark lines below should be correct!
 
 
 
 # By RMW
 # using activeperl v5.8.0 for Win32-x86-multi-tread
 # Program to add file1 to file2
 # examples from http://www.comp.leeds.ac.uk/Perl/filehandling.html
 
 #name the files
 $file1 = c:\Program Files\ArGo Software Design\Mail Server\Keyring_ALL;  #
 Name for file1
 $file2 = c:\PGP\pgp-all.asc;  # Name for file2

You are trying to be too smart here. Even on Windows it is totally ok to
use forward-slashes in pathnames. Perl will do the right thing for you:

$file1 = c:/Program Files/ArGo Software Design/Mail Server/Keyring_ALL;
$file2 = c:/PGP/pgp-all.asc;

What you did couldn't work because you used double-quotes in which '\'
is the escape character. For unknown sequences such as '\p' the result
is simply 'p'. So if you want a literal backslash appear in your
double-quoted strings, you need to escape it: \\. 

Now, talking about RTFM. You don't have man available, so far right. But
if you have a Perl distribution, you most likely have the perldoc
program. So try

perldoc perl

in a DOS-prompt. It lists all the other manual pages that are available.
To learn about how to build strings, read

perldoc perldata

and search for String literals or similar.

Depending on your Perl distribution, the documentation is probably also
available as HTML. In case of ActivePerl, you'll find an entry in the
startmenu's group of ActivePerl pointing to the documentation (Help or
so).

 open(INFO, $file2);   # Open file2 for output
 @lines = INFO;  # Read file2 into an array

INFO is a write-only filehandle so you can't read from it. 

 close(INFO, $file2);   # Close the file2
 
 open(INFO, $file1);   # Open file1 for input
 print INFO = @lines;  # Print the array into file1

Even if the above syntax was valid, it wouldn't work because here the
file has been opened for reading. Also, HANDLE is used to read from a
filehandle and not to write to it.

 close(INFO, $file1);   # Close the file1

The above would have to look like:

open INFO_IN, $file2 or die Error opening for read-access: $!;
@lines = INFO_IN;
close INFO_IN;

open INFO_OUT, $file1 or die Error opening for write-access: $!;
print INFO_OUT @lines;
close INFO_OUT;

There are better ways of doing the above. For instance, you don't need
@lines at all. Do it all in one go:

open INFO_IN, $file2 or die Error opening for read-access: $!;
open INFO_OUT, $file1 or die Error opening for write-access: $!;

print INFO_OUT INFO_IN;

close INFO_IN;
close INFO_OUT;

For very large files this may need too much memory (perl internally has
to read the file into a large list), so do it line-wise:

print INFO_OUT $_ while INFO_IN;

This is a good moment to read 'perldoc perlsyn' and learn about this
syntax (it uses someting called 'statement modifiers').

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Questions of OOP in Perl

2003-08-14 Thread Tassilo von Parseval
On Fri, Aug 08, 2003 at 12:05:47AM + Pablo Fischer wrote:

 I have some questions about OOP in Perl.
 
 1. In my class I have lot of methods, but some of them just parse a file or 
 pass a string to a different format (like in C, Im thinking that they are 
 private), In perl, whats the better way to call a private method:
 
 $state = $this-city2state(Arg1);
 
 and in the citystate have
 
 sub city2state {
   my $this = shift;
   my $city = $_[0];
 
 ...MoreCode..
 }

That's an ordinary method call. Nothing wrong with that. Nonetheless I'd
write

my ($this, $city) = @_;

inside the method.

 Or this way
 
 $state = city2state(Arg1);
 
 and in citystate have
 
 sub citystate {
   my $city = $_[0];
 
 MoreCode..
 }

No. This is a plain function call. city2state() is now no longer a
method and wouldn't obey to inheritance either, for example.

With 'private', do you perhaps really mean 'static'? That is, the object
on which the method was called, isn't actually used? If so, call it as a
class method:

Your::Class-city2state(Arg1);

sub city2state {
my ($class, $city) = @_;
# $class is now Your::Class and can be ignored if you want
}

 Which is the correct way? Im confused if I need to use $this for public and 
 private methods or no..

If you really mean private versus public this is a different story.
Whatever you call the object inside your methods should be of no concern
for the interface. If you call it $this or $self or $mona_lisa is up to
you.

There is however a certain convention in Perl to make private methods
look private by prepending an underscore:

$obj-_private;

Of course, perl just doesn't care and _private() can still be accessed
by anyone who gets hold of it. 

 2. Exists an special nomenclature, like Arrays need to be in capital letters 
 and scalar variables not.

Not in this way. The nomenclature is to use lowercase names for lexical
variables (so it's $this, not $This and certainly not $THIS). Globals
should be all uppercased ($GLOBAL). As for things like $Variable, I am
not sure. I haven't often seen them so it is usually either only
lowercase or uppercase.

One final thing about method names: make them lowercase and use
underscores to separate words. This looks Perl-ish:

$obj-get_attribute;

while this looks Java-ish and is harder to read:

$obj-getAttribute;

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: data recovery ext3 (was RE: Recover zip file via Archive::Zip)

2003-08-14 Thread Tassilo von Parseval
On Thu, Aug 07, 2003 at 03:09:06PM -0400 West, William M wrote:

 While I'm still off topic and speaking of data recovery, has anyone
 every recovered data from a ext3 filesystem after all utilities have
 been tried to repair them?  I've tried all the utilities off of
 freshmeat.net and nothing works.  I've got bad blocks and i-nodes.  Any
 suggestions are welcome and you can email me off list.
 
 
 as i had mentioned yesterday, i had written a script some time ago that
 dealt a little with this.  i have since found it (or a version of it) in
 dead tree form- so i retyped it and am sure there are several things wrong
 with it.
 
 i am not sure what all the components do anymore- i did not document it well
 :P

Let me help. :-)

 now that i've looked at it, it's really for getting to files that are
 unlinked etc. so i am not sure it will do you any good.

Partly it might. The only problem with your script is that it cannot
deal with data that is spanning more than 12 inodes (those were usually
not in one block but fragmented over the harddisk). A line like this
shows such a trickier example:

99526  0 100644 6761321/1027 Sat Feb  2 09:11:58 2002

I don't by hard know what to do with it, but it is laid out in the ext2
undeletion how-to.

 to bring this more on topic, i would like to see what ways something like
 this can be improved- it served useful to me in the past, but i'm sure it
 can be made more useful:::
 
 
 #!/usr/bin/perl
 
 # added proper things when retyping it:
 use warnings;
 use diagnostics;
 use strict;
 #---
 
 my $cfile = /tmp/commands.file;
 my $filesystem =/dev/hda6;
 my @path = (/tmp/recover,,/recover,,.ebu);  #making a path to put
 my $date=Oct;   #just files from October#stuff later
 
 open (OUT,$cfile);
 print OUT open $filesystem\n;# i wonder what this is for?

Debug message?

 foreach (`/sbin/debugfs -R lsdel /dev/hda6`){#why did i hard code /dev/hda6?
 
 #debugfs let's me list a bunch of inodes and i stick the list in a file
 
 m/(\d+)/;
 $path[3]=$1;   #had to split this regex to dead with some edge case 
 $1=~m/(\d)/;  # but i can't recall what
 
 $path[1]=$1;
 my $quatch = join(,@path);
 my $place= path[0]$path[1];
 print OUT(dump $path[3] $quatch\n) if ((m/$date/));

Essentially, from a line like

2210070   1000 100600  228432/   6 Wed Jul 23 09:26:10 2003

you extract the inode (2210070) and from that turn

my @path = (/tmp/recover,,/recover,,.ebu);

into

@path = (/tmp/removed, 2, /recover, 2210070, .ebu);

So the deleted inode gets dumped into 

/tmp/removed/2/recover/2210070.ebu

This could have been done more easily:

@path[3,1] = /((\d)\d+)/;

 `mkdir $place`;
 }
 
 
 -
 
 then i chmod 755 command.file?  or is it a file used by another tool???

command.file is the list of dump directives. It's supposedly a shell
script that you can run later. So the above Perl script just generates
another script. I am just not sure about 

 print OUT open $filesystem\n;

open /dev/hda6

is not a meaningful command in shell scripts AFAIK.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Sick of installing CPAN modules

2003-08-14 Thread Tassilo von Parseval
On Thu, Aug 07, 2003 at 11:05:19AM -0700 jc wrote:

 I have parse a mailbox in order to grab data from each email.  Simple enough
 right?
 
 So I tried to use the CPAN module Mail::MboxParser (0.17 version because the
 new one requires more modules than this one) I installed the prerequisite
 MIME::Tools (5 version, not developer) and this went fine.  MIME::Tools also
 requires IO::Stringy, and Mail::Field, Mail::Header, Mail::Internet.  No
 problem, installed all of those.
 
 However, the Mail::MboxParser, the one that I really need still says it need
 MIME::Tools.  The actual module is called MIME::tools.  I'm wondering if the
 program is so stupid that it doesn't realize this ist he same thing.  Or
 perhaps it's not the same thing and there's a secret to installing these
 modules that I don't know about.

This is a thing I noticed just recently. The thing is: this error
message makes no sense and you can safely ignore it. Why it happens, I
have no idea because

[EMAIL PROTECTED]:~$ perl -MMIME::Tools=5 -e1
[EMAIL PROTECTED]:~$

so it's all fine. Blame it on MIME::Tools...or ExtUtils::MakeMaker, but
not me. :-)

As for using this old version of MboxParser: the additional obligatory
requirements were MIME::QuotedPrint. Clearly, when you were able to
install MIME::Tools, you can install MIME::QuotedPrint, too.

The current version is 0.39 (released yesterday actually; might not yet
have propagated onto every CPAN mirror). It uses a new optional parser
(Mail::Mbox::MessageParser which has been released by David Coppit
shortly ago) which is _very_ fast. But even if you use 0.38 (which is
definitely less experimental), it should be significantly more
performant than 0.17. Also, 0.38 has shown to be relatively bug-free.
Some small changes to your existing scripts might be necessary though,
since the interface changed in a few spots.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: CGI text process question

2003-08-11 Thread Tassilo von Parseval
On Wed, Aug 06, 2003 at 11:13:15PM -0500 Ben Jacobs-Swearingen wrote:

 Hello all, this is my first post to this group, and I hope it isn¹t
 inappropriate. Anyway I have the following code in a CGI I¹m working on,
 it¹s supposed to translate the ugly %(hexhex) markers for non-alphanumeric
 characters back into normal text and assign the results to elements of an
 array. In the following script $in has a sample line of form input to give
 you a better idea of what¹s going on:
 
 $in = 
 protocol=nserver=www.a.this%2Fis%2F%7Esilly.htmlregex=babo%5Bd%7Ce%5D;
 @in = split(//,$in);

There is a nice module called CGI.pm that does that for you. It's a core
module, so use it instead of doing it the hard (and often wrong) way.


use CGI;
my $cgi = CGI-new;

for ($cgi-param) {
print $_: , $cgi-param($_);
}

The param() method returns a list of all parameters when called in
list-context (as in the above for signature) and the value of a
parameter when it is passed as argument. See 'perldoc CGI' for details.

If you want the above to parse given query strings, you can do it like
this:

my $cgi = CGI-new(protocol=nserver=www.a.this%2Fis%2F%...);
...

Just use 'CGI-new()' if you want your script act as a CGI script. The
module will then do the right thing (that is, distinguish between POST
and GET for example etc.).

 When I try this at home (on MacPerl) and at school (using standard Unix Perl
 in OSX) the script works perfectly; however when I try to run it as a CGI on
 the server (which is running Perl 5.006001) I get a blank page: presumably
 the script is not generating any errors (at least according to the error
 log), but it isn¹t giving me any results either. Does anyone have any idea
 why that might be? Also I¹m a total novice at Perl, so please no rude
 comments about my awkward coding (instructive comments about my awkward
 coding would be more than welcome). Thanks in advance!

I didn't look too closely at the code but it appeared to have a few
red-herrings in it. To translate a URI-escaped string back to its plain
representation, you can use this substitution:

$_ = www.a.this%2Fis%2F%7Esilly.html;
s/%(\w\w)/chr(hex($1))/ge;
print $_;

It grabs two characters following a %, turns these hex-numbers into
decimals and looks the corresponding character up using chr(). You need
the /e modifier here, because the right-hand side of the substitution is
not the translation string but instead Perl code whose return value is
supposed to be the string.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Initializing code in a module...

2003-07-14 Thread Tassilo von Parseval
On Mon, Jul 14, 2003 at 11:41:40AM +0200 Hamish Whittal wrote:

 Anyone know whether or how I can initialise code when calling any of the
 subroutines within a module?
 I don't necessarily want to call the module personally, I would like it
 to be called when I call any of the subroutines.

You can have Perl initialize your code when it require()s or use()s the
module. You don't even have to do much. If you add regular code to a
module (that is, code that is not within a subroutine or method), it
gets executed once the module is loaded. Therefore:

package Module;

# This is executed automatically
# --

my $var = 1;
print I am loaded\n;
# you can also call functions
call_init_function();

# --

# the rest remains as it was
sub function {
...
}
1;

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Being a moron CGI.pm

2003-07-12 Thread Tassilo von Parseval
On Fri, Jul 11, 2003 at 11:53:55PM -0700 Rus Foster wrote:

 I know what I'm about to ask is a really stupid question but I just can't
 get my head around my first outing with CGI.pm. I've RTFM as appropiate
 but getting nowhere. All I want to do is dump a list of variable and their
 values which have been parsed to a script. So far I have

Rob already commented on the mix between functional and object-oriented
interface. Just stick to one of them.

 #!/usr/bin/perl
 
 use CGI qw(:all);
 $query = new CGI;
 
 @names = $query-param;
 
 
 print header(), start_html();
 foreach $entry (@names)
 {
 print em(param('$entry')).br \n;

Why do you use single quotes here? You want to pass the value of $entry
to param() and not the literal string '$entry':

print em( param($entry) ), br, \n;

 }
 
 which I thought would work
 
 If I put print $entry \n; that prints out the variables but not the
 values. I know its going to be something stupid..What is it?

param() works a little like a hash: Calling it in list context is like
keys() on a hash (you did that alright). 'param($key)' is then very much
the same as '$hash{$key}'. 

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: scandir

2003-07-06 Thread Tassilo von Parseval
On Sun, Jul 06, 2003 at 02:43:14PM +0530 Pandey Rajeev-A19514 wrote:

 Do we have a perl function equivalent with the same functionality as
 the function scandir in c language ?

No, we don't. Simply do it yourself:

my $dir = /path;
opendir DIR, $dir or die $!;
my @list = sort { $b cmp $a }
   grep { -f $dir/$_ }
   readdir DIR;

closedir DIR;

This spits out all regular files in /path in reverse order.

If you want a function, then wrap the above into something like this
untested snippet:

sub scandir {
my ($dir, $sel, $sort);
local *DIR;
opendir DIR, $dir or die $!;
return sort { $sort-($a, $b) }
   grep { $sel-($dir/$_) }
   readdir DIR;
}

print scandir(/path, sub { -f $_[0] }, sub { $_[1] cmp $_[0] });

Just as scandir(3), this one takes references to the select and sort
function that are used to filter and order the output accordingly. If
you write

return sort { $sort-() }
   ...

(and even if not), you can also use

sub { $b = $a }

as a reference to the sorting-routine. But using @_ for both of them is
more consistent.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Use Carp in package

2003-06-24 Thread Tassilo von Parseval
On Tue, Jun 24, 2003 at 01:52:20PM -0500 Dan Muey wrote:

 I'm writing a simple module to return a few variables and functions.
 
 The perldoc perlmod* stuff says I should use Carp; and call that
 instead of warn().
 So..
 1)
 If I use Carp shoud I still use warnings; in the package?

Those two are independent of each other. Carp provides ways for you, the
programmer, do emit warnings and error messages. They'll show up no
matter whether warnings are in effect. Warnings on the other hand will
make the Perl interpreter emit messages when it has encountered
something warnings-worthy. It's the same as with warn(): You use that
indepently from warnings, too.

 2)
 If I understand it correctly the preffered way would be to do:
 
 use Carp;
 ...
 carp(Watch your monkey);
 
 Instead of:
 ...
 warn(Watch your monkey);
 
 Is that a correct assumption?

Yes, this is correct.

 3)
 Should I just do 
 
 use Carp(carp);
 Since I'll only be calling carp() ( assuming carp() is warn()'s
 replacement in Carp.pm )

That's up to you. Carp exports carp() and croak(). I usually end up
needing both after a while. 

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Please help... struggling beginner.

2003-06-23 Thread Tassilo von Parseval
On Mon, Jun 23, 2003 at 10:43:07AM +0200 Denham Eva wrote:

 I am very much a novice at perl and probably bitten off more than I can chew
 here. 
 I have a file, which is a dump of a database - so it is a fixed file format.
 The problem is that I am struggling to manipulate it correctly. I have been
 trying for two days now to get a program to work. The idea is to remove the
 duplicate records, ie a record begins with Name and ends with Values End.
 The program that I have thus far, is  pathetic in the sense I have opened
 three files, the file below, a data file for cleaned data, and a file for
 capturing the usernames already processed. But I have got stuck on how to
 compare and work through the file line for line and then only to capture the
 lines that are not duplicated.

Keeping a couple of files around is not necessarily pathetic. I think
you don't need a file for the processed usernames. But the original file
and one for the processed data is a totally common pattern.

 Here is the file format
 
 File Begins
 #DB dumped
 #DB version 8.0
 #SW version 2.6(1.10)
 #---
 --
 Name  :   system
 Some stuff here... 
 many lines
 Of different format... 
 such as line below...
 User Count:   0
 ##--- User End
 Lots of text here...
 Until...
 We get line below...
 ##--- Values End
 #---
 --

So, #-... is essentially the record separator? A fixed separator
is good because it makes processing rather easy. It might be handy to
both set the input record separator to this value:

#! /usr/bin/perl -w

use strict;

local $/ = 
#-\n;

open IN, old_database or die $!;
open OUT, new_database or die $!;

# keep track of what records have already been seen
my %records_seen;

# this is the 'header', that is: what is before the first record
print OUT scalar IN;  

while (IN) {
if (/Name\s+:\s+(\S+)/) {
#^^^
# $1 is record name
next if $records_seen{ $1 }++;
print OUT $_;
}
}

print OUT #End Of Dump\n;

close IN;
close OUT;

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Passing control to another perl program....

2003-06-23 Thread Tassilo von Parseval
On Mon, Jun 23, 2003 at 10:04:22PM +0200 Hamish Whittal wrote:

 I have this scenario:
 I have a 'main' program that needs to call on progA under condtions A,
 progB under conditions B, etc.
 
 Now, I would like the progA, progB, progC to remain independent of the
 'main' program at all times. The only thing I would like to connect them
 is the paramteres
 Yes, I know this sounds like the place to use Modules and Packages,
 however, I don't think a module can have a 'main' program of it's own.
 The reasons for keeping this independence is to keep the whole system
 portable and modular. At runtime, the users may choose to leave out
 progC and hence the program will not even load this 'program' or set of
 programs
 
 Can this be done?
 
 I am not sure I am explaining this correctly, so if not, I will try
 again.

I think you will have to explain a little more. Why is it important that
each of your parts needs to have a 'main' program? From your description
it still sounds as though a module would be a good idea. Take these two
modules:

# modA.pm
package modA;
use strict;
use base qw(Exporter);
@modA::EXPORT = qw(main);

sub main {
my $parms = @_;
...
}
1;

# modB.pm
package modB;
use strict;
use base qw(Exporter);
@modA::EXPORT = qw(main);

sub main {
my $parm = @_;
...
}
1;

And in your main program you use require() to pull in either of the two:

# main.pl
...
if ($conditionA) {
require modA;
modA-import;
main(foo);
}
if ($conditionB) {
require modB;
modB-import;
main(bar);
}

Using require() instead of use() has two implications: The first being
that it happens at run-time. Had you used use(), both modules would have
been loaded. In the above case this would have been a problem because
both modules have and export a main() function.

Secondly, require() wont automatically trigger the exporting of symbols
from a module so you have to do that manually. This is done with
PACKAGE-import. The import() method is inherited by your modules from
the Exporter module. It exports everything that is in @PACKAGE::EXPORT
to the caller (which is main.pl in this case).

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: longmess_heavy subroutine undefined

2003-06-21 Thread Tassilo von Parseval
On Fri, Jun 20, 2003 at 01:16:51PM -0700 Rob Richardson wrote:
 Greetings!

Hi there,

 I think something is corrupted.  I am suddently getting error messages
 saying that the undefined subroutine longmess_heavy is used in file
 carp.pm.  My search path seems to have gotten screwed up.  Any
 suggestions on how to fix it?

longmess_heavy() is from Carp::Heavy. See what happens when you type in
your shell 'perl -MCarp::Heavy -e1'. When there's an error this module
must have gone lost for some reason. Then try to locate Carp/Heavy.pm in
your filesystem and see whether the location matches any of the paths in
@INC. Does your script perhaps change @INC in some way?

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: longmess_heavy subroutine undefined -- solved

2003-06-21 Thread Tassilo von Parseval
[ CCed to [EMAIL PROTECTED] ]

On Sat, Jun 21, 2003 at 03:20:59PM -0700 Rob Richardson wrote:

 I found out where the problem was, but not why it happened.  It occured
 to me that it might be a good idea to compile each of the module files
 my program uses individually.  One of them had a missing parenthesis.
 
 I have no idea why the IndigoPerl compiler didn't find it before.  It
 was letting the program run.  It's a CGI program, and it was throwing
 up an Error 500 screen.  The log file was telling of the undefined
 subroutine longmess_heavy and that I had a premature end of script
 headers.
 
 This is the second time I've seen IndigoPerl fail to catch a blatant
 syntax error.  I found a simple way to get it to ignore a missing
 semicolon.  (Unfortunately, I've forgotten what it is now.)  Is
 ActiveState's Perl compiler any better?

I haven't ever used Indigo so I don't know how it compares to
ActivePerl. However, I know the latter and never encountered such a
behaviour with it. It seems odd that the parsing routines in IndigoPerl
should produce results different from other perls because it would mean
that they applied some patches of their own.

Only recently a not so very credible source on comp.lang.perl.misc
stated that there'd be a couple of problems with IndigoPerl 2003.
Obviously your observations go into the same direction.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Accessing C/C++ Dlls using perl

2003-06-19 Thread Tassilo von Parseval
On Thu, Jun 19, 2003 at 01:37:09AM -0700 Ben Crane wrote:

 Thanx, I hunting the info down now, seems quite
 complex. I'm wondering whether it might not be better
 to have a crack at this in C? 

The difference between doing XS in C and in C++ isn't all that rough.
See Using XS With C++ in perlxs.pod. The Perl API however is C so it
feels more natural doing it in C (but since I in general find C more
natural than C++, I am slightly biased on that).

 Have you found perlXS to be difficult to implement?

Foremost it was fun which helped a lot over all the complexities and
subtleties of XS. The hardest part is probably grokking the
idiosyncratic XS documentation that lacks some vital things (typemaps,
for instance, are explained nowehere).

You get some useful examples in the two XS-cookbooks that you find at

http://search.cpan.org/author/DMR/

They don't contain a lot of descriptive explanations (I think they even
contain none at all) but still they are a great help.

Other than that, perlxstut, perlguts, perlxs and perlapi will be the
manpages you need. Roughly in this order save for perlapi.pod which is
the reference for all the API functions and macros.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Accessing C/C++ Dlls using perl

2003-06-19 Thread Tassilo von Parseval
On Thu, Jun 19, 2003 at 01:42:29PM -0400 zentara wrote:

 On Thu, 19 Jun 2003 01:37:09 -0700 (PDT), [EMAIL PROTECTED] (Ben Crane)
 wrote:

 Thanx, I hunting the info down now, seems quite
 complex. I'm wondering whether it might not be better
 to have a crack at this in C? Have you found perlXS to
 be difficult to implement?
 
 Inline::C and Swig  are easier to do than XS. I hav'nt been able
 to get Swig to work with 5.8 though.  
 
 Here is a simple program to mess with the cdrom tray.
 USING Swig:
 Run these commands in succession:
 
 swig -perl5 cdrom.i gcc -fpic -c cdrom.c cdrom_wrap.c 
   -Dbool=char -I/usr/lib/perl5/5.6.0/i586-linux/CORE
 gcc -shared cdrom_wrap.o cdrom.o -o Cdrom.so

That however is a pretty optimistic case. It's not always that
straight-forward, especially not when you want to craft your own more
Perlish interface.

Also, one problem with Swig is the fact that it is not exclusively for
Perl. It covers other scripting languages as well. This becomes quickly
apparent when manipulating the files generated by it.

 USING Inline::C:
 
 #!/usr/bin/perl -w
 use warnings;
 use Inline C;
 use strict;
 
 my $cd = '/dev/cdrom';
 
 cdlock($cd,0); #unlocks cdrom
 cdeject($cd);  #ejects cdrom
 cdclose($cd);  #closes cdrom
 cdlock($cd,1); #locks cdrom 
 
 exit;
 __END__
 __C__
 #include stdio.h
 #include sys/ioctl.h
 #include linux/cdrom.h
 #include fcntl.h
 #include unistd.h
 #include stdlib.h
 
 #define CDROM /dev/cdrom 
 /* In all functions 'device' means name of CD-ROM device,
 * for example /dev/cdrom
 */
 
 /* Close CD-ROM tray */
 int cdclose(char *device)
 {
 int fd = open(device, O_RDONLY|O_NONBLOCK);
 if (fd == -1)
 return -1;
 if (ioctl(fd, CDROMCLOSETRAY) == -1)
 return -1;
 close(fd);
 return 0;
 }

[...]

And finally the same in XS. It's not the slightest bit harder than with
Inline::C. The only difference with the XS code below is that I changed
the return values in that the functions now return false when something
goes wrong and true otherwise.

This is CDROM.xs [untested]:

#include EXTERN.h
#include perl.h
#include XSUB.h

#include ppport.h

#include stdio.h
#include sys/ioctl.h
#include linux/cdrom.h
#include fcntl.h
#include unistd.h
#include stdlib.h

MODULE = CDROM  PACKAGE = CDROM

INCLUDE: const-xs.inc

void
cdclose(device) 
char* device;
PROTOTYPE: $
PREINIT:
int fd;
PPCODE:
if ((fd = open(device, O_RDONLY|O_NONBLOCK)) == -1);
XSRETURN_NO;
if (ioctl(fd, CDROMCLOSETRAY) == -1)
XSRETURN_NO;
close(fd);
XSRETURN_YES;

void
cdeject(device)
char *device;
PROTOTYPE: $
PREINIT:
int fd;
PPCODE:
if ((fd = open(device, O_RDONLY|O_NONBLOCK)) == -1)
XSRETURN_NO;
if (ioctl(fd, CDROMEJECT) == -1)
XSRETURN_NO;
close(fd);
XSRETURN_YES;
   
void
cdlock(device, lock)
char *device;
int lock;
PROTOTYPE: $$
PREINIT:
int fd;
PPCODE:
if ((fd = open(device, O_RDONLY|O_NONBLOCK)) == -1)
XSRETURN_NO;
if (ioctl(fd, CDROM_LOCKDOOR, lock) == -1)
XSRETURN_NO;
close(fd);
XSRETURN_YES;

The corresponding CDROM.pm is autogenerated by h2xs and can be used
literally. In the above the -b switch would have been used (as can be
seen because ppport.h and const-xs.inc were included). That would make
the XS portion of the code backwards compatible up to the specified
version of Perl.

I never quite understood people's fondness for Inline::C. The Inline
modules don't make the hard things easier in any way (you still have to
write your own typemaps if you need them for example). I would even say
that XS allow better control when working with several namespaces and
inheritance. And it's quite convenient in that a very well working and
easily to be extended skeleton is automatically created. Finally, the
usual 'perl Makefile.PL PARAMS=...; make; make test; etc' cycle is more
transparent and in fact pretty fool-proof. What I hated about Inline::C
was the fact that it created a small directory hierarchy (without me
asking it to do so) where it created files that for instance contained
the error messages that happened during compilation. With XS I all have
them sent to stderr which resembles very much the familiar way of
working with C and C compilers.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Info req

2003-06-18 Thread Tassilo von Parseval
On Wed, Jun 18, 2003 at 12:38:35AM -0400 Shishir K. Singh wrote:

 I am trying to locate the perl code for the opcode -B  or stat but I
 am getting lost in the maze of all the files. Would appreciate it if
 someone could pls direct me to the actual file where  the algo for -B
 file test switch lies. 

It is in the file pp_sys.c. Perl built-ins are usually declared like

PP(pp_split)
{
...
}

In pp_sys.c you will find most of the system related built-ins. The
filetest operators are to be found in the PP(pp_ft*) functions. For
instance PP(pp_ftsize) is the '-s' operator. '-B' is PP(pp_ftbinary)
which just calls PP(pp_fttext). What to return is presumable based on
the current OP (which is OP_FTTEXT for -T and OP_FTBINARY for -B).
stat() is PP(pp_stat).

If you want to find yourself around the Perl source, a good primary
source of information is 'perldoc perlhack.pod'. It's giving an overview
of how the interpreter works. To understand the source-code however, you
need to have read perlguts.pod, perlcall.pod and keep perlapi.pod around
as reference. And even that is only a fraction of what you actually
need.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tassilo's email signature

2003-06-18 Thread Tassilo von Parseval
On Wed, Jun 18, 2003 at 09:44:58AM +0100 Sparrow, Dave wrote:
 A regular contributor to the Perl Quiz Of The Week discussion newsgroup
 ([EMAIL PROTECTED]) is Tassilo von Parseval. 

Actually even more regularly to this list here so I can respond...

 His email signature is reproduced below. I have no idea what it does
 and can't get it to run.

You can't get it to run? For me:

[EMAIL PROTECTED]:~$ perl
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval
__END__
Just another Perl hacker,[EMAIL PROTECTED]:~$

There shouldn't be anything platform dependent in it. However, for this
JAPH whitespace does matter. So you need to copy it as one string and
not concatenate it together. Must be three lines separated by newline.

The basic idea is simple. It has some Perl code that is backwards and that
is evaled after some processing. A common JAPH-pattern. The string is:

 ,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
 pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;

It is wrapped in '$_=q##;' to obfuscate it a little and to assign to
$_.

Next is

$_=reverse,

which turns the above into

subJust{another(qq!HPAJ!)}subanother{Perl()}subPerl{hacker()}subhacker{map
{($_=(caller(3-$_))[3])=~s/main:://;$_}0..3}print@{[Just(qq!HPAJ!)]},

That now already looks more like Perl. After that a substitution against
that happens:

s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;

Of course, the many x and s modifiers are spurious (just used to pad my
signature nicely). So actually it is:

s/(?=sub)./q#q!'qq.\t$.'!#/sieg;

This turns the above string into:

sub Just{another(qq!HPAJ!)}sub  another{Perl()}sub
Perl{hacker()}sub   hacker{map
{($_=(caller(3-$_))[3])=~s/main:://;$_}0..3}print@{[Just(qq!HPAJ!)]},

It is really just used to add a whitespace between the keyword 'sub' and
the function name. Writing it properly formatted yields:

sub Just {
another(HPAJ);
}
sub another {
Perl();
}
sub Perl {
hacker();
}
sub hacker {
map { ($_ = (caller(3 - $_))[3]) =~ s/main:://; $_ } 0 .. 3 
}

print @{[ Just(HPAJ) ]},;

The 'y~\n~~;' is the same as

tr/\n//d;   # deletes all newlines

It's not important and could be left off. Eventually we have some Perl
code in $_ and simply run it with eval().

The above code consists of one print() statement that calls Just().
Just() calls another(), another() calls Perl() which in turn calls
hacker(). Finally hacker() looks back in the caller-stack and extracts
who called whom:

(caller(3))[3] == main::Just;
(caller(2))[3] == main::another;
(caller(1))[3] == main::Perl;
(caller(0))[3] == main::hacker;

It strips off the main:: part and returns the list qw(Just another Perl
hacker) which - because it is interpolated in double quotish strings -
stringifies to Just another Perl hacker. 
 
If you like JAPHs you should have a look at those of Abigail in
particular ('perldoc -q JAPH' links to a couple of those by him, too).
It's consensus that he has written the most obscure and funniest JAPHs
around.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tassilo's email signature

2003-06-18 Thread Tassilo von Parseval
[ CCed to [EMAIL PROTECTED] ]

On Wed, Jun 18, 2003 at 06:43:24AM -0700 Rob Richardson wrote:

 Interesting!  Not that I can understand much of it...
 
 But I'm particularly interested in the caller stack.  Is that standard
 Perl or do I have to have a special module?

caller() is a Perl-builtin. See 'perldoc -f caller'. In a nutshell: It
can be used to figure out by whom a function (or a module included with
require()) was called. For instance, a function can find out its own
name programatically:

sub test1 { test2(); }
sub test2 { print My name is , (caller(0))[3], 
   and I was called by , (caller(1))[3], \n; }
test1();
__END__
My name is main::test2 and I was called by main::test1

These are usually pretty exotic information but if you want to write
your own debugger, you'll have use for it.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tassilo's email signature

2003-06-18 Thread Tassilo von Parseval
On Wed, Jun 18, 2003 at 04:08:22PM +0100 AustinTanney wrote:

 Hi I'm totally new to the list and havent a clue about coding. gotta start
 somewhere tho :-)
 
 Interesting signature. One thing I dont get though is, why when i change any
 of the backwards text does it stop the output from working?

In the case of this signature, the text that you changed deliberately is
the actual Perl code that gets executed. Perl is a dynamic language
which means that many information (including the code itself which is to
be executed) can be provided and manipulated at runtime:

$string = 'print hello world\n';
eval($string);

is a valid Perl program where the actual action happens in the eval().
With this it's the same as with the signature: Make some changes to
$string and the program might no longer work.

But don't focus on that yet. First make yourself comfortable and
familiar with Perl and programming in general before you tackle things
like dynamic code generation. You've found the right spot with this list
to get the necessary assistance on this way.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Style ( was:Capture a printing function into an array )

2003-06-17 Thread Tassilo von Parseval
On Mon, Jun 16, 2003 at 11:39:30PM -0700 Harry Putnam wrote:

 Charles K. Clarkson [EMAIL PROTECTED] writes:
 
 
  $$line =~ s/[Ss]ource/Src/g;
  $$line =~ s/[Dd]estination/Dst/g;
  $$line =~ /^[^ ]+, (\d[^ ]+ \d[^ ]+).*(Src[^ ]+ \d+).*(Dst[^ ]+
 
 Where do I look for the details on the meaning of the double `$'?

In perlref.pod. $$line is a short-cut for ${ $line }. The function from
which the above snippet was extracted took a reference to a scalar as
first argument (in order to change the argument in place). $$line
dereferences that to get the actual value it referred to.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: %x = ( xyx = 'abc' ) is strange!

2003-06-17 Thread Tassilo von Parseval
On Mon, Jun 16, 2003 at 10:03:50PM -0700 Richard Heintze wrote:

 Why does this program print yes def but not yes
 xyz? It does print xyz:def, so I don't understand
 why it does not print yes xyz.
 
 {
   my %x = ( xyx = 'abc', d = 'y', f = 'g' );
  ^^^
   $x{def} = fhi;
   print  qq($_ : ).$x{$_}.qq(\n)   foreach (keys %x);
   foreach (keys %x) { print yes xyz\n if ($_ =~
 xyz);  }
   ^^^
   foreach (keys %x) { print yes def\n if ($_ =~
 def);  }
   print $x{'xyz'}.\n;
  ^^^
 }

Spot the difference? ;-) 'xyx' is not at all the same as 'xyz'.

Other than that, two cosmetical things. You shouldn't pretend a pattern
is a string. It's not. Correct would be

... if $_ =~ /xyz/;

Secondly, this is sort of ugly and hard on the eyes:

print  qq($_ : ).$x{$_}.qq(\n)   foreach (keys %x);

Put it all into one string and let perl do the interpolation for you:

print $_: $x{ $_ }\n foreach keys %x;

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Strings and operators?

2003-06-14 Thread Tassilo von Parseval
On Sat, Jun 14, 2003 at 08:56:21AM -0500 deborah wrote:

 How does Perl interpret a string when used in a numeric comparison 
 equation?

It depends.

  I accidently used a numeric comparison operator when I was comparing 
 strings and I found that no matter what strings I compared, Perl always 
 said they were equal.

In that case, both certainly evaluated to the same numerical value. For
instance, this comparison is true:

14b == 14c  # in numerical context both are evaluated as 14

this one as well:

b14 == c14  # in numberical both are evaluated as 0

And subsequently:

14b != b14  # because 14 != 0

 Any other operation (such as , , != ) always proved false, but it was 
 always true that 'stringA'=='Bstrg'.  Is it just saying that it is 
 true that stringA and Bstrg are both strings? I thought it would count 
 spaces or convert to numbers or something like that.  Well, actually, I 
 first was surprised that it didn't give me an error since I used the 
 wrong type of operator. What is it doing in this case?

It's not an error in Perl. But you get a warning if you 'use warnings'
or employ the -w switch:

perl -we 'print 14b == 14c'
Argument 14c isn't numeric in numeric eq (==) at -e line 1.
Argument 14b isn't numeric in numeric eq (==) at -e line 1.
1

As a rule of thumb: perl takes the longest numerical prefix of a string
and treats it as number (either integer or float). In the following,
numeric context is enforced by adding 0 to a string:

print $_+0, \n for 2, 2a, 2.2, 2.2a, a2, a2.2;
__END__
2
2
2.2
2.2

But:

print 4e10+0;
__END__
400

because 4e10 is a number in scientific notation and therefore a valid
number literal.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Find regex in Start/Stop segments

2003-06-13 Thread Tassilo von Parseval
On Fri, Jun 13, 2003 at 03:09:20PM -0700 R. Joseph Newton wrote:

 Tassilo von Parseval wrote:
 
 chomp;
 
  I don't think that the entries in @ARGV contain newlines at the end.
  Actually I know they don't. :-)
 
 
 That's good.  and that is why chomp is an excellent choice for this context.
 Because the OP may not know, or be sure of, that fact.  The chomp function is
 custom-designed for cases of uncertainty,.and is perfectly safe in cases where
 there is no tail-junk to remove.  Please don't discourage its use.

I was not discouraging its use. I was rather pointing out that @ARGV
does (usually) not contain trailing newlines. chomp() should be used
when - conceptually - there could be something to remove. In case of
filenames however you either don't have anything to remove or you don't
want to remove it. That way this chomp() could even be wrong (as John
remarked in his follow-up).

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How can I find the module version?

2003-06-11 Thread Tassilo von Parseval
On Tue, Jun 10, 2003 at 09:32:53AM -0400 Rick Ressegger wrote:

 If I want to know what version of a module is already installed on a system,
 how can I disclose this?

Either use Janek's suggestion or ask for the value of $VERSION for the
module in question:

perl -MSome::Module -e 'warn Some::Module-VERSION'

 Can multiple versions of a module exist in a library or does one get
 superceded by another that is installed later?

Usually older versions are replaced by newer versions. But see

http://search.cpan.org/author/INGY/only/

which allows you to install as many versions of a module as you want.
For that see INSTALLING MULTIPLE MODULE VERSIONS in the docs of
'only'.

Once you have several versions you can explicitely specify to use a
particular version of that module. That's also laid out in the docs.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Find regex in Start/Stop segments

2003-06-11 Thread Tassilo von Parseval
On Tue, Jun 10, 2003 at 11:49:25PM -0700 Harry Putnam wrote:

 I use a homeboy data base technique to keep info about the scripts I
 write and other typse of stuff too.  Here I'm just dealing with
 scripts.
 
 Its a simple format to enter key information about what a script
 does.  Looks like:
 
 # Keywords: SOME WORDS
 # body
 # body
 # DATE
 # 
 
 I've written various scripts to search this format in awk and shell.
 Now trying it in perl.  I have several working scripts but wanted to
 get some ideas from the sharp shooters here how to do this better.
 
 My technique seems like it could be streamlined and improved quite a
 lot.

Yes, it's a little wordy considering it's Perl.

 The sample below just handles the basic technique and isn't completed
 with all tests and etc.  Just some basic ones. But really I'm more
 interested in hearing better ways to accomplish this.
 
 The basic task is to locate a formated segment, search its keywords
 line for regex then print the segment.  Also a basic check for
 misformatted segments.
 
 Not too concerned with how the files are aquired but what comes after.
 ^^
 #!/usr/local/bin/perl -w
 
 ($myscript = $0) =~ s:^.*/::; 

You are allowed to manipulate $0, too. The new value of $0 is the one
that is eventually showing up in your process-table (unless you are
using Perl5.8.0 where this does not work due to a bug).

 $regex = shift;
 ## Set Keywords start end regex for non script searching (The default)
 $keyreg = '^# Keywords:';
 $keyend = '^# $';
 
 if (!$ARGV[0]) {
   usage();
   exit;
 }
 ## Aquire there files in whatever way
 @files = @ARGV;
 
 ## Set a marker to know when we are in a new file
 $fname_for_line_cnt = '';
 for (@files) { 
   chomp;

I don't think that the entries in @ARGV contain newlines at the end.
Actually I know they don't. :-)

   $file = $_;
   if ($fname_for_line_cnt eq $file) {

There is no reason to put those variables into quotes.

## This shouldn't happen
 print We're reading the same file again .. exiting\n;
 exit;

That is better solved using a hash. Fill all the files into a hash (as
keys) and iterate over the keys. That way, it's guaranteed you only
inspect each file once.

   } else {
 ## Set lineno to 0 for start of each file
 $lineno = 0;
 $fname_for_line_cnt = $file;
   }
 
   if (-f $file) {
 open(FH,$file) or die Cannot open $file: $!;
 while (FH) {
   chomp;
   $lineno++;

You don't have to keep track of the line numbers yourself. Perl offers
the special variable $. for that.

   $line = $_;
   if (/$keyreg $regex/) {
 print $file\n;
   $hit = TRUE;
   }
   if ($hit) {
   print $lineno $line\n;
   }
   if ($hit  /$keyend/) {
   ## We've hit the end of a good segment, print delimiter and null
   ## out our vars
   print -- \n;
   $hit= '';
   $line   = '';
   }
   if ($hit  /^[^#]/ || $hit  eof) {
 ## If we see this situation it means the format is screwed up
 ## Notify user of the line number, but null out vars and proceed. 
   print  $file:\n   INCOMPLETE SEGMENT ENTRY: Line $lineno\n --\n;
   $hit= '';
   $line   = '';
   }
 }
 close(FH);
   } else {
 next;
   }
 }
 sub usage {
   printEOM;
 
 Purpose: Search scripts keyword segments (or any file)
 Usage: \`$myscript REGEX file ... fileN (or glob)'
   (Where REGEX is a regex to be found in Keyword segment) 
 
 EOM
 }

I'd probably write it like that:

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

$0 =~ s:.*/::;

my $regex = shift;
$regex = qr/^# Keywords: $regex/;   # could improve performance a little

my %files;
@files{ @ARGV } = ();   # a hash-slice: see 'perldoc perldata'

usage(), exit if ! @ARGV;

for my $file (keys %files) {
next if ! -f $file;
open FILE, , $file or die Error opening $file: $!;

my $hit;
while (FILE) {
chomp;
$hit++ if /$regex/o;# start of record
print $. $_\n if $hit;# $. is the line number
$hit-- if /^# $/; # end of record
print $file:\n\tINCOMPLETE SEGMENT ENTRY: Line $l.\n--\n
and $hit--
if $hit  !/^#/ or $hit  eof;
}
}

sub usage {
...
}
   
I didn't test it but it should produce the same result as your script
and doing it considerably more quickly. Please substract any possible
syntax errors or logical flaws from the script before running it. ;-)

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: how to count?

2003-06-09 Thread Tassilo von Parseval
On Sun, Jun 08, 2003 at 11:41:26PM -0500 Jerry Preston wrote:

 I am not sure if this can be done or not, but I want to create a counter on
 the fly so to speak.
 
 foreach $id ( @IDS ) {
 $cnt = $id._cnt;
 $cnt++;
 }
 
 All I get is item_cnt.  Is there a way to do this?

I can only assume what you want. It looks suspiciously as though you
wanted to create new variables with the name $id._cnt. You can do
that with symbolic references (I know that some would now want me to
shred into pieces):

foreach $id (@IDS) {
$cnt = $id._cnt;
$$cnt++;
}

This is _not_ advisable, wont work with properly declared lexcical
variables (variables declared with my() can't be accessed through a
symbolic reference) and will fail if you 'use strict;'. To do it
properly better create a hash:

my %cnt;# all your counters in here
foreach my $id (@IDS) {
$cnt{ $id . _cnt }++;
}

Doing it with symbolic references is apt to fail at some later point and
you will then have a very bad time at debugging your scripts. Better
leave your fingers off that and use a hash (or even array in this case).

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: replacing text in a file

2003-06-09 Thread Tassilo von Parseval
On Mon, Jun 09, 2003 at 02:46:48AM -0500 christopher j bottaro wrote:

 what is the easiest way to replace text in a file?  say i have file blah.txt 
 and i want to replace some regular expression found in that file with 
 something.  also, i want to do this from within the perl program, not by 
 invoking perl with the -e option.

You can use the same underlying technique from within a Perl script. You
have to set two special variables accordingly and Perl can even do an
inplace-edit:

local $^I = 1;  # enable inplace editing
local @ARGV = blah.txt;   # make it accessible with 
while () {
s/blabla/BLABLA/;
print;
}

This however might not work on Windows due to some limitations concerning
open files. 

So if the above is no option for you, you have to do it manually:

open IN,  blah.txt or die $!;
open OUT, blah.txt.tmp or die $!;

while (IN) {
s/blabla/BLABLA/;
print OUT;
}

close IN;
close OUT;

rename blah.txt.tmp, blah.txt or die Renaming: $!;

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: replacing parts of a string

2003-06-09 Thread Tassilo von Parseval
On Mon, Jun 09, 2003 at 04:53:53AM -0500 christopher j bottaro wrote:

 i want to do something like:
 $line =~ s/M (\d+) (\d+)/M $1+100 $2+200/;
 obviously adding 100 to $1 and 200 to $2, not adding the text '+100' and 
 '+200'.

Use the /e modifier and turn the substitution side into a valid Perl
expression that returns the desired output:

$line =~ s/M (\d+) (\d+)/M  . ($1+100) .   . ($2+200)/e;

/e will make perl execute the right side and put in the result of this
execution.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: replacing text in a file

2003-06-09 Thread Tassilo von Parseval
On Mon, Jun 09, 2003 at 03:22:52PM +0100 Rob Dixon wrote:

 Tassilo Von Parseval wrote:

  You can use the same underlying technique from within a Perl script. You
  have to set two special variables accordingly and Perl can even do an
  inplace-edit:
 
  local $^I = 1;  # enable inplace editing
  local @ARGV = blah.txt;   # make it accessible with 
  while () {
  s/blabla/BLABLA/;
  print;
  }
 
 The value of $^I is the string to be appended to the backup copy of
 the original file. The above will edit 'blah.txt' and rename the original
 file to 'blah.txt1'.

Indeed, yes. I wonder how people can memorize that because I've been
getting it wrong for three years. The letter 'i' never fails to trick
me into believing that it's a boolean switch turning on or off
inplace-editing altogether.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: perl extensions

2003-06-07 Thread Tassilo von Parseval
On Fri, Jun 06, 2003 at 10:33:21PM -0700 R. Joseph Newton wrote:

 Francis Henry wrote:

  The following is a note from a colleague of which I am skeptical:
 
  fyi
  .pl used to be used for both executables and libraries.
  A library is simply perl code located in a different file which is
  imported into another perl program with the 'require' keyword.
 
  Now that we have the .plx convention (and of course the extension
  doesn't
  affect perl's behavior at all) we can have .pl stand only for
  libraries
  and .plx stand for executables.
 
  Are any of the rest of you conforming to this?  I'm not sure if he's
  referring to modules (ext. .pm) when he says libraries, either.

 Bad idea, IMHO.  We can altready use the .pm extension for modules, an
 argot that is already native to Perl.  I look at established Perl folders
 and I see .pl scripts backed by .pm modules.
 
 Lacking some truly compelling reason, it strikes me as a bad idea to veer
 off on an unfamiliar and non-standard model.  I therefore share your
 skepticism.

And yet there is still Perl4 code floating around that didn't yet use
.pm but instead .pl for perl library. On operating systems that
determine the type of a file by looking at the extension (unlike unices
and others) a distinction into .plx, .pl and .pm can be critical. I bet
that this is the ratio behind ActiveState's scheme. And I think they are
right.

Also, there is no standard at all that says that an exectubale Perl
script needs to have the .pl extension. Only the .pm thing is mandatory
with Perl5 because it has been compiled into the interpreter.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Flush Everything

2003-06-06 Thread Tassilo von Parseval
On Fri, Jun 06, 2003 at 04:12:11PM +1200 Voodoo Raja wrote:

 I have got a script running..
 
 Its ment to  repeat  a particular sub routine using the after syntax

What is the after syntax? Do you mean statement-modifiers as in

function() for 1 .. 10;

?

 All i want to do is clear everything in buffer ... since it eats up the 
 memory

Which buffer?

 I do not need any varaibles which I have defined in the sub.

If you don't need them, why did you define them in the first place?

 there are more then enough to init manually.
 
 Is there any command I can use to kill any constants assigned.

Why do you assign constants if you want to kill them?

 any piiece of code will be helpful

I think it's up to you to provide the code you have so far and want
assistance with. Right now I don't have even a vague idea of what your
problem is.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Warnings/strict still needed?

2003-06-05 Thread Tassilo von Parseval
On Wed, Jun 04, 2003 at 03:58:44PM -0500 James Edward Gray II wrote:
 On Wednesday, June 4, 2003, at 03:45  PM, John W. Krahn wrote:
 
 Does it hurt performance having them?
 
 No.
 
 Are we sure about this?  I find it really hard to believe that 
 'warnings' isn't affecting performance on some level.  I doubt it's a 
 big hit, but I would be very surprised if it doesn't cost something.

Perl internally uses a bit-mask to determine when to warn (stored in
${^WARNINGS_BITS}). When interpreting a script perl has to check against
this bitmask regardless of whether warnings are turned on or not,
therefore there's no change in run-time performance.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: More Jump Shots ;-) [Was Re: arrays and hashes]

2003-06-04 Thread Tassilo von Parseval
On Tue, Jun 03, 2003 at 08:36:05PM +0200 Kevin Pfeiffer wrote:

 Since it seemed like a nice exercise to work on I played with this some 
 myself. Goals being to try to avoid global variables, use subroutines and 
 keep MAIN 'uncluttered' and pass arguments to subs as needed.
 
 I think I did okay (holding breath), but I'm wondering about things like:
 
 my @sorted_keys = sort_results(\%score, \%opt);
 
 ## [...]
 
 sub sort_results {
 
 my %scores = %{ (shift) };
 my %opt= %{ (shift) };
 
 ## [...]
 
 }
 
 In the subroutine I'm dereferencing the hash and array and placing the 
 values into new variables, correct? Should I instead be working directly on 
 the original values (via a reference)? Would that be something like:
 
 sub sort_results {
 
my ($score_ref, $opt_ref) = @_;

## etc...
 }

If you from then on referred to elements of the hash with something like

$score_ref-{ key };

then this would be it. It depends on what you want. By dereferencing the
whole data-structure you're essentially creating a copy. The downside of
that is that it needs more memory and is slightly less efficient.
However, that way your subroutine wont have side-effects. If you
directly work on the references, you'd change the hashes in your main
program (only on read-access, of course). That itself can be a valid
design decision. So it's up to you what you want.

 (Thanks for your always helpful advice and comments!)
 
 -K
 
 
 #!/usr/bin/perl
  use warnings;
  use strict;
 
  # from perl.beg (Stuart White)
 
  # desired result:
  # (attempted shots)
  #
  # Marbury 1
  # Jackson 3
  # Hardaway 1
  # Stoudemire 2
  # Bowen 3
  # Duncan 2
  # Williams 1
  # Marion 2
  # Ginobili 1
 
  {
 
  use Getopt::Std;
  my (%opt, $total_attempts);
 
  getopts('hl', \%opt);   # commandline options
  my %score = get_data();
  my @sorted_keys = sort_results(\%score, \%opt);
 
  print (format_output([EMAIL PROTECTED], \%score));
 
  }
 
 ## END   MAIN ##
 
 ## BEGIN SUBS ##
 
 
  sub get_data {
 
 my %scores;
 
 while (DATA) {
 
if (/.*\] (\w+).*/) { # get player's name
   $scores{$1}++;
}
 
 }
 
 return %scores;
 
  }
 
 
  sub sort_results {
 
 my %scores = %{ (shift) };
 my %opt= %{ (shift) };
 
 unless (%opt) {  # default is sort by name
 
my @sorted_keys = sort keys %scores ; # sorted by key

Was this branch ever executed so far? You create a lexical variable
inside...of course, @sorted_key wont be visible outside this
unless-block.

 } else {
 
my $sort_hi if ($opt{h});

What is this statement for?

my @keys_sorted_by_value  = sort {
 
   compare ($scores{$a}, $scores{$b}, $opt{h})
 
} keys %scores;   # sorted by value
 }
 
  }

Ah, I should have read on. Either the unless or the else branch is the
last thing in your subroutine and so the last statement they evaluate is
returned. Hmmh, no. I wouldn't do it like that. It requires too much of
brain-power. ;-) What I often do in such a case is return early from a
sub and thus doing away with an else block. Like this:

sub sort_results {

my %scores = %{ (shift) };
my %opt= %{ (shift) };

if (%opt) {
return sort {
compare($scores{ $a }, $scores{ $b }, $opt{ h })
} keys %scores;
}

return sort keys %scores;

}
 
First of all, I turned the logic around. What previously was the else
part is now the if part. I use an explicit return there. So the second
return statement is only reached when %opt was false.

  sub compare {   # sorts high  low scores
 
 my ($aa, $bb, $sort_hi) = @_;
 ($aa, $bb) = ($bb, $aa) if $sort_hi; # reverse if sort high 
 (option h)
 
 return $aa = $bb;
 
  }
 
  sub format_output {
 
 my @sorted_keys = @{ (shift) };
 my %score   = %{ (shift) };
 my $total_attempts;
 my $output  = \n;
 
 foreach (@sorted_keys) {
 
$output .= sprintf %12s  %2s\n, $_, $score{$_};
$total_attempts += $score{$_};
 
 }
 
 $output .= \n;
 $output .= TOTALS:   $total_attempts\n\n;
 
  }

The rest looks fine to me. However - and so turning back to your
original question - for this program you are probably best off by
directly working with the references. sort_results() would then look
like:

sub sort_results {
my ($scores, $opt) = @_;
if (%$opt) {
return sort {
compare($scores-{$a}, $scores-{$b}, $opt-{h})
} keys %$scores;
return sort keys %$scores;
}

By not creating a copy of your hashes, you save a little on memory and
CPU-cycles.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({

Re: open(IN,) flock?

2003-06-02 Thread Tassilo von Parseval
On Sun, Jun 01, 2003 at 09:35:56AM -0700 Bob's Demise wrote:

 I've written a Perl/CGI that allows a user to search
 for a string in a specified file.  I've yet to make
 this little program widely available - and currently
 with one or two users - it's quite speedy.  I
 anticipate no more than 20 users attempting to access 
 the same file at the same time - and this probably
 won't occur very often.  I intend to eventually move
 this data to database and use DBI.  Until then - I'm a
 bit concerned.  Any undesirable results I might
 expect?
  Is it necessary to lock a file for reading?  My gut
 suggests the file won't be available until the file
 handle closes or the program ends. 

You need locking when you have several process indeterministically
reading and writing to this file. In your case, there is only reading
involved so you don't need need any locking at all.

However, it wont hurt to place a shared lock on the file (LOCK_SH from
the Fcntl module). That way you can later easily extend the script if
the need for writing to the file should arise.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using a CONSTANT as a pathname

2003-06-02 Thread Tassilo von Parseval
On Sun, Jun 01, 2003 at 08:36:34PM -0400 Todd Wade wrote:

 Tassilo Von Parseval [EMAIL PROTECTED] wrote in
 message news:[EMAIL PROTECTED]
  On Sun, Jun 01, 2003 at 11:22:32AM +0200 Kevin Pfeiffer wrote:
 
 snip /
 
  open DATA, @{[ CFG ]} or die ...;
 
  The part between @{[ ]} is arbitry Perl-code that is executed in list
  context and the last expression evaluated in this Perl code is what gets
  eventually printed.
 
 
 If you want to interpolate a scalar value in a string you should probably
 avoid creating an array reference, if only to avoid confusion:
 
 [EMAIL PROTECTED] trwww]$ perl
 use constant A_CONSTANT = '/some/path';
 print(the constant's value is: ${ \A_CONSTANT }\n);
 Ctrl-D
 the constant's value is: /some/path

That's a bit better here because ${ \... } will execute the code in
scalar-context instead of list-context. However, it wont always work as
expected which is why I seldom use it. For instance:

# this should work _theoretically_
print ${ \localtime };
# but doesn't:
__END__
1

Instead one needs to explizitely enforce scalar context. I think this is
a little non-intuitive:

print ${ \scalar localtime };
__END__
Mon Jun  2 07:50:54 2003

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Passing arrays/associative arrays into subroutines ... how?

2003-06-02 Thread Tassilo von Parseval
On Sun, Jun 01, 2003 at 04:20:28PM -0500 James Edward Gray II wrote:

 On Sunday, June 1, 2003, at 04:12  PM, Ken Tozier wrote:
 
 No luck. Dropping the \ in 'my $description = 
 DescribeCritter(\%wombatStats);' didn't fix the problem.
 
 You're right.  I was dumb.  Let me try again...
 
 my $description = DescribeCritter(\% wombatStats);
 
 Drop the backslash and space here, as I said before.

You are right in that a space should probably not be there. However, it
is legal and exhibits Perl's very odd lexer-rules. You can write:

$



foo


=

bar;

print $foo;
__END__
bar

It's probably only useful for obfuscated Perl contests. And this is
totally mad:

$


# a comment between the sigil and the variable name!!

foo = bar;
print $foo;
__END__
bar

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: converting arrayname to string or vice-versa

2003-06-02 Thread Tassilo von Parseval
On Mon, Jun 02, 2003 at 07:53:06AM -0400 zentara wrote:

 This one is puzzling me. 
 I know it's in the faq, to not use variables for variable naming,
 but I find it odd that I can't get a stringified form of a variable
 name, maybe from the symbol table? Or from the B line of modules?
 
 Say I have an array like:
 
 @somename = (1,2,3,4,5);
 
 and I want to write that array to a file, but I
 want the file named automatically by just
 dropping the @ off of the @somename.
 How would you go about doing it? Plus,
 I would like to be using strict.

This can be done, even with strictures enabled. @somename has an entry
in the symbol-table if it is a package variable. The entry looks like

'somename' = *::somename,

So under the key 'somename' you have a glob as corresponding value. A
glob has several slots, one of them the ARRAY slot which you will
automatically get when you use @{ } for dereferencing:

use strict;
@main::somename = qw(a b c);
...
# and now get the content of @somename
my @values = @{ $::{somename} };

I think from that it should be obvious how you store it in a file
[untested]:

for my $var ( qw/array1 array2/ ) {
my @values = @{ $::{ $var } };
my $valstring = join , @values;
print FILE [EMAIL PROTECTED]::$var = ($valstring)\n;
}

You will have to take additional care if your variables don't contain
plain numbers. If they contain strings, you can't just join with
commatas. You then also have to enclose them in quotes. Also, I am
storing a string like

@main::array1 = (1,2,3);

because it can later just be evaled (or do()ne) under strictures.

 Also the reverse: take a filename like somename
 and load it to an array @somename just by some
 concantation like @{'somename'}.

If you store it similarily to the above, a plain

do 'somename';

should do.

 The @{'somename'} seems to work, but not with strict.

No, because it's a symbolic reference. The @{ *glob } trick is slightly
different in that you don't dereference a string.

 It seems like it should be easy, but it's not.

It's not so hard with a little bit of understanding for the
symbol-table. However, and that's the limitation, you can't thusly store
lexical (my()-) variables because they don't have an entry in the
symbol-table. In this case you need to walk the pads of the Perl
interpreter which one of the B:: modules could indeed help you with.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Perl Text to Wav

2003-06-01 Thread Tassilo von Parseval
On Sat, May 31, 2003 at 11:51:59AM -0400 Jan van den Berg wrote:

 I was wondering if some of you might have come across a free module/
 program with which it is possible to do to text to wav conversion.
 
 I've been looking at this for some time, but I don't seem to get
 anywhere.
 
 What I am asking is mostly regarded Text-to-Speech (TTS), I don't really
 care about the speech part. I just want to be able to create wav files
 and store them somewhere, for later use.
 
 I have seen www.festvox.org http://www.festvox.org/  and
 http://www.reednet.org/ViaVoiceTTS/  but some tips, ideas pointers might
 come be nice.

Have a look at http://www.ni-s.u-net.com/. Nick Ing-Simmons (the Perl/Tk
creator) has something called 'rsynth' on his webside.

It escapes me how this relates to Perl, though.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using a CONSTANT as a pathname

2003-06-01 Thread Tassilo von Parseval
On Sun, Jun 01, 2003 at 11:22:32AM +0200 Kevin Pfeiffer wrote:

 More problems trying to use constants...
 
 I have:
 
 use constant CFG = qq|$ENV{'HOME'}/.get_quiz|;
 
 
 But I can't see how to make this work:
 
 open DATA,  CFG or die Couldn't open , CFG,  for writing: $!\n;
 
 With quote marks it creates a new file in the pwd called CFG. (Maybe it's 
 time to get the Programming Perl book?)

A constant neither has the $ nor @ sigil in front so it wont
interpolate in strings. Oddly enough you did the right thing in the 'or
die' string. The second argument to open() is not different: It's just a
string.

To get around that, you can use the three-argument form of open():

open DATA, , CFG or die ...;

if your Perl is recent enough (= 5.6.0). Or you use the
interpolate-anything trick:

open DATA, @{[ CFG ]} or die ...;

The part between @{[ ]} is arbitry Perl-code that is executed in list
context and the last expression evaluated in this Perl code is what gets
eventually printed.

Btw: You probably shouldn't use the DATA handle. It's special in that it
refers to anything that follows the __DATA__ or __END__ token in your
scripts. It even is seekable so you can write a script that prints
itself with the help of this filehandle.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: using a CONSTANT as a pathname

2003-06-01 Thread Tassilo von Parseval
On Sun, Jun 01, 2003 at 01:13:31PM +0200 Kevin Pfeiffer wrote:

 Hi Tassilo,

Hi there,

 In article [EMAIL PROTECTED], Tassilo Von Parseval wrote:

  if your Perl is recent enough (= 5.6.0). Or you use the
  interpolate-anything trick:
  
  open DATA, @{[ CFG ]} or die ...;
  
  The part between @{[ ]} is arbitry Perl-code that is executed in list
  context and the last expression evaluated in this Perl code is what gets
  eventually printed.
 
 This seems too confusing here for me (but I will add it to my save file for 
 future reference.)

It is quite orthogonal actually. You probably know that you can create a
reference to an anonymous array on the fly like this:

my $ref = [ split /,/, $var ];
# which can be dereferenced to
my @fields = @{ $ref };

And now in one go you could do (a little silly of course):

my @fields = @{ [ split /,/, $var ] };

The right-hand side interpolates...it is just an ordinary array (without
a name).

  Btw: You probably shouldn't use the DATA handle. It's special in that it
  refers to anything that follows the __DATA__ or __END__ token in your
  scripts. It even is seekable so you can write a script that prints
  itself with the help of this filehandle.
 
 I almost asked about this earlier - if a script can also write to itself. I 
 wrote something to test it, but haven't had time to look up the seek 
 functions, etc. I suppose this only makes sense in very limited situations 
 (if at all)?

I don't think you can use it for writing. DATA is meant for reading. But
it's useful for embedded data:

while (DATA) {
...
}
__DATA__
some data
to be used
by script

Some CPAN modules use this technique to embedded some data.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: variable not being interpreted

2003-05-31 Thread Tassilo von Parseval
On Sat, May 31, 2003 at 01:50:51AM +0200 Kevin Pfeiffer wrote:

 I use a function to return a value:
 $ENV{HOME}/perl/qotw/qotw13/mb; which is then assigned to $mb
 
 But the $ENV{HOME} part is not being interpreted, so this sample:
 
 my $mb  = get_config('mb', '.get_quiz');
 print $mb\n;
 exit;
 
 produces literally: $ENV{HOME}/perl/qotw/qotw13/mb instead of:
 /home/pfeiffer/perl/qotw/...

Can you post the (potentially) relevant bits of get_config()? Sounds as
though this function reads in a configuration file and returns the
requested values. Is $ENV{HOME}/perl/qotw/qotw13/mb one such line of
this config file? If so, it would be data and not code and you'd have to
eval() it or so.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: variable not being interpreted

2003-05-31 Thread Tassilo von Parseval
On Sat, May 31, 2003 at 10:30:02AM +0200 Kevin Pfeiffer wrote:

 In article [EMAIL PROTECTED], Tassilo Von Parseval wrote:
 
  On Sat, May 31, 2003 at 01:50:51AM +0200 Kevin Pfeiffer wrote:
  
  I use a function to return a value:
  $ENV{HOME}/perl/qotw/qotw13/mb; which is then assigned to $mb
  
  But the $ENV{HOME} part is not being interpreted, so this sample:
  
  my $mb  = get_config('mb', '.get_quiz');
  print $mb\n;
  exit;
  
  produces literally: $ENV{HOME}/perl/qotw/qotw13/mb instead of:
  /home/pfeiffer/perl/qotw/...
  
  Can you post the (potentially) relevant bits of get_config()? Sounds as
  though this function reads in a configuration file and returns the
  requested values. Is $ENV{HOME}/perl/qotw/qotw13/mb one such line of
  this config file? If so, it would be data and not code and you'd have to
  eval() it or so.
 
 Sorry about leaving out the routine:
 
 sub get_config {
 my ($setting, $cfg_file)  = @_; # setting is 'mb'
 
 open DATA,  $ENV{'HOME'}/$cfg_file 
or die Error, could not open $cfg_file : $!;
 
 while (DATA) {
next if (/^[#\s]*$/);
$result = $1 if (/^$setting\s*=\s*?([^]*)?\s*$/);
 }
 
 close DATA;
 return $result;
  }
 
 Data file looks like:
 mb  = $ENV{'HOME'}/perl/qotw/qotw13/mb

Ah, there's the delinquent. Indeed, it's data and not (yet) code.

 It already occurred to me that I might need an eval and I've tried using it 
 in every position and way possible it seems, but the env variable still 
 doesn't get interpreted.

In your case, you have to build an expression that, when evaluated,
returns the expanded string. That's not so hard...all you have to watch
is the use of quotations:

my $val = q!$ENV{'HOME'}/perl/qotw/qotw13/mb!;
my $mb = eval qq! $val !;
print $mb;

Bear in mind that simply evaling $ENV{HOME}/etc./.../ wont work because
it is not a proper Perl expression. You need to add double-quotes to
turn it into one.

But I guess you already know that evaling strings from a config-file
could be a problem, depending on the context in which you use it. It's
totally ok, though, if you have control over the content of the file.

Still, you could also put 

mb = ~/perl/quotw/qotw13/mb

and expand the tilde. 'perldoc -q tilde' comes up with a regex-solution.
Using glob (which is also mentioned) is more straightforward, however:

my $mv = glob('~/perl/qotw/qotw13/mb');

will do the right thing.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: MySQL and perl using quotes

2003-05-29 Thread Tassilo von Parseval
On Thu, May 29, 2003 at 11:17:40AM +0200 anthony wrote:

 i have to update a MySQL tables some names and text
 the problem is that the names and words have quotes
 maybe in names it has O'connor, and text would be
 He said  :I'don't know where to go!!.
 
 where there is a mixture of single and double quotes in text, i'm really get
 problem with updating the table.
 any help with the query statment would be appreciated!!
 also I forgot to mention I tried
 $name = $dbh-($name);
 $text   = $dbh-($text);
 I get an error it says it is not a CODE.**and i use $dbh to connect to
 database, so it is valid**

I am hardly surprised. Where did you pick the above up? $dbh is not a
code-reference (in which case it would indeed be called as you did). I
suppose it's a database-handler. 

As for quoting, the DBI module can do that for you. You first prepare a
statement and get back a statement-handler on which you then call
execute with the data to be inserted, queried etc. For instance:

my $sth = $dbh-prepare(UPDATE table SET name=? where ID=?);
$sth-execute($name, $id);

The two parameters to execute() ($name and $id) directly correspond to
the two question-marks in the prepare-statement. If you expand it, this
would read:

UPDATE table SET name=$name where ID=$id

but $name and $id get properly quoted so that you don't have to care
about that.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: global variable

2003-05-28 Thread Tassilo von Parseval
On Wed, May 28, 2003 at 12:05:41PM +0200 anthony wrote:

 i have a script with my modules.
 i.e
 #!/usr/bin/perl
 use strict;
 use warnings;
 use Config::IniFiles;
 my $cfg = new Config::IniFiles( -file = /path/configfile.ini );
 use lib '/path/tomy/Module';
 use MyModule;
 use TestModule;
 
 now i would like $cfg to be global , so that all module can use the same
 variable, and i don't have to declare each time $cfg in the module.
 If  I do our $cfg, i can't get the variable in the module,I tried but i
 don't know how to get.
 Any help is appreciated.

If you only have a few global variables, you don't need our() at all.
Simply package-qualify the variable and it will also make 'use strict'
happy:

use strict;
use warnings;
use Config::IniFiles;
$main::CFG = new Config::IniFiles( -file = /path/configfile.ini );
...

Uppercasing a global variable is a good idea to indicate that it is global.

Now, if you want to access this variable from a module (that is, another
namespace/package), all you have to know is in which package this global
variable lives. In the above, this is package main, so in your module
you'd have to write:

$main::CFG-method;

A shortcut exists in that global variables from package main can also be
written as

$::CFG-method;

Looks odd and yet $::VAR is the same as $main::VAR.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: catch errors

2003-05-27 Thread Tassilo von Parseval
On Tue, May 27, 2003 at 02:27:29PM -0400 Moshe wrote:

 How do I catch/handle runtime errors in Perl?
 
 Something like:
 
 try {
 
 } catch (e) {}
 
 or

Use a block eval:

eval {
# potentially failing code
};
if ($@) {
print An error occured: $@;
}

$@ is special in that it could also be an object. That depends on the
code that throws this error. If it does a

die $object;

$object is eventually to be found in [EMAIL PROTECTED] But I don't know of any module
that would make use of this feature.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]