[24429] in Perl-Users-Digest
Perl-Users Digest, Issue: 6615 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 11:05:49 2004
Date: Thu, 27 May 2004 08:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 27 May 2004 Volume: 10 Number: 6615
Today's topics:
Re: 2-1/2 regexp questions nobull@mail.com
Error in ldap->add neelesh@netyantra.com
Listing files sorted by creation time (Yash)
Re: Listing files sorted by creation time <calle@cyberpomo.com>
Looking for a Formmail script (Greg Chapman)
Re: Looking for a Formmail script <HelgiBriem_1@hotmail.com>
Re: Map or Regex and Sorting <krahnj@acm.org>
Re: Map or Regex and Sorting <uri@stemsystems.com>
Re: Perl work? <peter@semantico.com>
Re: Perl work? <postmaster@castleamber.com>
Re: Perl work? <ThomasKratz@REMOVEwebCAPS.de>
Re: POK Flag Weirdness wth binary files <usenet@morrow.me.uk>
Remove first letter of each string in array <jds@nospantrumpetweb.co.uk>
Re: Remove first letter of each string in array <jurgenex@hotmail.com>
Re: Remove first letter of each string in array <kha@rogers.com>
Re: Remove first letter of each string in array <tore@aursand.no>
Re: Stat() function fails? <tadmc@augustmail.com>
Re: Templating system needs help <tore@aursand.no>
Re: Templating system needs help <tore@aursand.no>
Re: Templating system needs help (Anno Siegel)
Re: Templating system needs help <uri@stemsystems.com>
Re: Templating system needs help <tore@aursand.no>
Re: Templating system needs help <tore@aursand.no>
xml type parser in the standard perl installation ? <matrix_calling@yahoo.dot.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 May 2004 05:34:09 -0700
From: nobull@mail.com
Subject: Re: 2-1/2 regexp questions
Message-Id: <4dafc536.0405270434.52bec557@posting.google.com>
nobull@mail.com wrote in message news:<4dafc536.0405240322.2fe8bb57@posting.google.com>...
> Abigail <abigail@abigail.nl> wrote in message news:<slrncaskp3.ct.abigail@alexandra.abigail.nl>...
>
> > use re 'eval';
> > my $r = '\d+';
> >
> > my $re = qr /($r)(?{print "(", $- [-1], ", ", $+ [-1] - $- [-1], ")",
> > " --> '$^N'\n"})(?!)/;
>
> I perfer to avoid the need for "use re 'eval'" by compling the (?{})
> in a separate qr//.
>
> my $r = '\d+';
> my $re = qr /(?{print "(", $- [-1], ", ", $+ [-1] - $- [-1], ")",
> " --> '$^N'\n"})/;
> $re = qr /($r)$re(?!)/;
Sorry, those subscripts in @- and @+ should be 1 not -1 in case $r
contains any capturing groups.
my $r = '\d+';
my $re = qr /(?{print "(", $-[1], ", ", $+[1] - $-[1], ")\n"})/;
$re = qr /($r)$re(?!)/;
------------------------------
Date: 27 May 2004 08:02:50 -0700
From: neelesh@netyantra.com
Subject: Error in ldap->add
Message-Id: <32a55c9.0405270702.7ce7a7e@posting.google.com>
Hi....
I am using perl with open LDAP over linux and i am getting error of
invalid dn when i use following statement.....
$result = $ldap->add(dn =>'$dn', attr => [$attr]);
where $dn and $attr are variable but when i use following statement
then code succcessfully runs
$result = $ldap->add(dn => 'pidTable=test,dc=nycube',attr =>['pid'
=> 'test','objectClass' => 'pidTable','userid' => ['testing'],]);
here $str is constructed by concatenation of $key=>$value pair i want
to use this method because each time when i am calling this function
then passed no of arguments may be different so i construct string by
concatenation of $key=>$value pair and then i passed it to this
function.
so i want to ask why this error is generating.Is there any possibility
inthe case of earlier ldap->add statment that variableds inside the
parentheses are not interpreted before the execution of ldap->add
statement and can i use this statement
$result = $ldap->add(dn =>'$dn', attr => [$attr]);
reply me as soon as possible.
Thanks,
Neelesh Vijaivargia
------------------------------
Date: 27 May 2004 07:47:07 -0700
From: yashgt@yahoo.com (Yash)
Subject: Listing files sorted by creation time
Message-Id: <5a373b1d.0405270647.239815a0@posting.google.com>
Hi,
I would like to do something with every text file from a directory,
with the latest created file taken first.
What is the best way to do this. I am looking for something like:
for my $file ( <something> glob("/mydir/*.txt") )
{
#my code
}
The glob will create an array of filenames. How do I make sure the
list comes in time order , latest fist?
Thanks
------------------------------
Date: Thu, 27 May 2004 16:58:45 +0200
From: Calle Dybedahl <calle@cyberpomo.com>
Subject: Re: Listing files sorted by creation time
Message-Id: <86hdu1uday.fsf@ulthar.bisexualmenace.org>
>>>>> "Yash" == Yash <yashgt@yahoo.com> writes:
> I would like to do something with every text file from a directory,
> with the latest created file taken first.
#!/usr/bin/perl
use warnings;
use strict;
opendir D, "." or die "Failed to open current directory: $!\n";
foreach (map {$_->[0]}
sort {$b->[1] <=> $a->[1]}
map {[$_,(stat $_)[9]]}
grep {/\.txt$/}
readdir D) {
# whatever
}
--
Calle Dybedahl <calle@cyberpomo.com>
http://www.livejournal.com/users/cdybedahl/
"Ah, optimism. I remember optimism." -- Anya, Buffy the Vampire Slayer
------------------------------
Date: 27 May 2004 05:22:13 -0700
From: gchapman1965@msn.com (Greg Chapman)
Subject: Looking for a Formmail script
Message-Id: <4c7f1a81.0405270422.2e2f37b6@posting.google.com>
I'm trying to find a script that will allow me to submit the
information from a form to an email address. The problem is that I
need to format the output that is received in the email. I have it
working now, but the email lists each field straight down the page. I
need to list a group of four fields across the page and then the next
group of four below that and so on.
Is this possible?
Thanks,
Greg
greg@basssax.com
------------------------------
Date: Thu, 27 May 2004 12:28:45 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: Looking for a Formmail script
Message-Id: <elnbb0htjuubvhtf3h5lsitu1ngtehf3br@4ax.com>
On 27 May 2004 05:22:13 -0700, gchapman1965@msn.com (Greg Chapman)
wrote:
>I'm trying to find a script that will allow me to submit the
>information from a form to an email address.
http://nms-cgi.sourceforge.net/scripts.shtml
>The problem is that I
>need to format the output that is received in the email. I have it
>working now, but the email lists each field straight down the page. I
>need to list a group of four fields across the page and then the next
>group of four below that and so on.
>
>Is this possible?
Yes.
--
Helgi Briem hbriem AT simnet DOT is
Never worry about anything that you see on the news.
To get on the news it must be sufficiently rare
that your chances of being involved are negligible!
------------------------------
Date: Thu, 27 May 2004 08:27:41 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Map or Regex and Sorting
Message-Id: <40B5A67F.A9F53053@acm.org>
Uri Guttman wrote:
>
> >>>>> "JWK" == John W Krahn <krahnj@acm.org> writes:
>
> >> for payment, i expect you to test Sort::Maker before its public release.
>
> JWK> I couldn't find it on CPAN or your web site.
>
> i posted the location in another recent thread on sorting. i would
> expect someone who knows how to write a GRT to follow all sort threads!
I follow, I just don't remember. :-)
> anyhow, it is at stemsystems.com/sort/Sort-Maker-0.01.tar.gz
Got it.
> i am coding up some late changes and improvements now and i will
> announce the next beta as soon as that is done. my goal is to release it
> before yapc::na since i am giving a talk about it there.
If you want it to run on version 5.6 or earlier you will have to remove
the =head3 tags from the POD which were introduced in version 5.8.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 27 May 2004 13:17:25 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Map or Regex and Sorting
Message-Id: <x7pt8qf1qy.fsf@mail.sysarch.com>
>>>>> "JWK" == John W Krahn <krahnj@acm.org> writes:
JWK> Uri Guttman wrote:
>>
>> anyhow, it is at stemsystems.com/sort/Sort-Maker-0.01.tar.gz
JWK> Got it.
>> i am coding up some late changes and improvements now and i will
>> announce the next beta as soon as that is done. my goal is to release it
>> before yapc::na since i am giving a talk about it there.
JWK> If you want it to run on version 5.6 or earlier you will have to remove
JWK> the =head3 tags from the POD which were introduced in version 5.8.
i liked using =head3 as the pod needed it with all the nested attribute
stuff. if you can figure out a good way to eliminate head3 i will do
it. i find pod easy to use but frustrating sometimes when you want
better nesting.
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 27 May 2004 09:37:23 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: Perl work?
Message-Id: <40b5a8c2$0$8089$afc38c87@news.easynet.co.uk>
John Bokma wrote:
> AFAIK camels are used in India :-D. And you can eat rice where camels live :-D
Interesting, are they native or imports (as in australia)?
------------------------------
Date: Thu, 27 May 2004 05:01:51 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Perl work?
Message-Id: <40b5bc92$0$196$58c7af7e@news.kabelfoon.nl>
Peter Hickman wrote:
> John Bokma wrote:
>
>> AFAIK camels are used in India :-D. And you can eat rice where camels
>> live :-D
>
> Interesting, are they native or imports (as in australia)?
<http://csmonitor.com/cgi-bin/durableRedirect.pl?/durable/1998/02/12/feat/travel.2.html>
<http://www.austcamel.com.au/cache/Travel%20Tips%20-%20The%20Camel.htm>
The latter talks about differences, but I have no idea if they are
really native.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Thu, 27 May 2004 15:40:58 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Perl work?
Message-Id: <40b5f16f.0@juno.wiesbaden.netsurf.de>
John Bokma wrote:
> AFAIK camels are used in India :-D. And you can eat rice where camels
> live :-D
You can eat rice where camels live, but you most probably can't grow it
there. Camels (independent from humpcount) live in hot and dry climates.
So the (twohumped) camel that originates from the Gobi desert (and lives
domesticated in other dry parts of Asia) comes from China, where they eat
rice; but the rice is grown in other parts of China where you have enough
rain to do so.
Thomas
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
------------------------------
Date: Thu, 27 May 2004 07:11:58 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: POK Flag Weirdness wth binary files
Message-Id: <c944bu$pd0$1@wisteria.csv.warwick.ac.uk>
Quoth waz@easynet.co.uk (Wayne Myers):
>
> This week I got bitten by something very strange. I was writing
> code that needed to decrypt something encrypted using Rijndael
> encryption, but when I read the key in, for some reason, the
> Crypt::Rijndael module refused to accept the key as a valid
> scalar string.
>
> I have written a short script reproducing the problem (under Perl
> 5.6.1 and Perl 5.8.3) and demonstrating the same workaround, here:
>
> http://www.waz.easynet.co.uk/pok/pok.pl.txt
I get 404 for this... (and for /pok).
> Is it a bug in Perl, a bug in Crypt::Rijndael, or a bug in my
> understanding of how to read in binary files?
I'm not sure... I can't reproduce the problem. I have tried:
#!/usr/bin/perl -l
use Crypt::Rijndael;
use Inline C => <<'EOC';
int is_scalar_POK(SV *sv)
{
return SvPOK(sv) ? 1 : 0;
}
EOC
my $k;
for (0..31) {
$k .= chr;
}
print is_scalar_POK $k;
my $c = Crypt::Rijndael->new($k, Crypt::Rijndael::MODE_CBC);
print $c ? 'success' : 'failure';
print is_scalar_POK $k;
__END__
which works as expected, but I don't really understand the difference
between obtaining a key for encryption and for decryption. Could you
post a modification of the above that fails, together with a hex dump of
the key you read from the file?
Ben
--
We do not stop playing because we grow old;
we grow old because we stop playing.
ben@morrow.me.uk
------------------------------
Date: Thu, 27 May 2004 15:07:20 +0100
From: "Julia deSilva" <jds@nospantrumpetweb.co.uk>
Subject: Remove first letter of each string in array
Message-Id: <7Cmtc.25879$FV7.6195@doctor.cableinet.net>
Hi there all.
my @array = qw(1this 2is 3a 4new 5message);
for (my $x=0;$x<@array;$x++){
$array[$x] = substr($array[$x],1,length($array[$x]))
}
foreach (@array){print"$_\n";};
This does indeed remove the first letter of each string in this array, but
is there a better way ! ?
Thanks for your help in advance
J
------------------------------
Date: Thu, 27 May 2004 14:17:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Remove first letter of each string in array
Message-Id: <mMmtc.7017$nJ6.4994@nwrddc02.gnilink.net>
Julia deSilva wrote:
> Hi there all.
>
> my @array = qw(1this 2is 3a 4new 5message);
>
> for (my $x=0;$x<@array;$x++){
Why not just
foreach(@array) {
> $array[$x] = substr($array[$x],1,length($array[$x]))
and then a simple
s/.//;
> }
>
> foreach (@array){print"$_\n";};
>
> This does indeed remove the first letter of each string in this
> array,
Actually it doesn't. Your code removes the first character in each string,
not the first letter.
If you want to remove the first letter, then you can use
s/[a-zA-Z]//;
> but is there a better way ! ?
"Better" in which respect?
Faster? Consumes less memory? More "perlish"? Shorter code (Perl golf comes
to mind)?
jue
------------------------------
Date: Thu, 27 May 2004 14:29:08 GMT
From: Kien Ha <kha@rogers.com>
Subject: Re: Remove first letter of each string in array
Message-Id: <UWmtc.179213$0qd.57739@twister01.bloor.is.net.cable.rogers.com>
Julia deSilva wrote:
> Hi there all.
>
> my @array = qw(1this 2is 3a 4new 5message);
>
> for (my $x=0;$x<@array;$x++){
> $array[$x] = substr($array[$x],1,length($array[$x]))
> }
>
> foreach (@array){print"$_\n";};
>
> This does indeed remove the first letter of each string in this array, but
> is there a better way ! ?
>
Shorter and more Perlish:
$_ = substr $_, 1 for @array;
or
@array = map { substr $_, 1 } @array;
------------------------------
Date: Thu, 27 May 2004 16:46:43 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Remove first letter of each string in array
Message-Id: <pan.2004.05.27.14.46.11.684087@aursand.no>
On Thu, 27 May 2004 15:07:20 +0100, Julia deSilva wrote:
> my @array = qw(1this 2is 3a 4new 5message);
>
> for (my $x=0;$x<@array;$x++){
> $array[$x] = substr($array[$x],1,length($array[$x]))
> }
>
> foreach (@array){print"$_\n";};
>
> This does indeed remove the first letter of each string in this array, but
> is there a better way ! ?
Use Perl's 'for' or 'foreach';
for ( @array ) {
$_ = substr( $_, 1 );
}
--
Tore Aursand <tore@aursand.no>
"War is too serious a matter to entrust to military men." (Georges
Clemenceau)
------------------------------
Date: Thu, 27 May 2004 07:21:26 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Stat() function fails?
Message-Id: <slrncbbna6.9rj.tadmc@magna.augustmail.com>
Joe Cosby <> wrote:
>
> You know, thank you, sincerely, for all who helped.
>
> The basic problem was, I needed to use a full path name for stat(),
> originally as I mentioned in my original post I thought that if I had
> chdir()'d to the directory that wouldn't be necessary.
^^^^^^^^^^^^^
Yes but chdir()ing to the directory that contains the file is
where you needed to go, not to the parent dir of the dir you needed.
> The perl docs are just not very clear.
The warning for readdir is quite clear, noticing that you didn't
chdir() to THE directory is just a (common) programmer's error.
> I apologize, I know that will
> strike some people as my whining because I screwed up,
Yes, it was you, it was not the docs.
Blaming the docs in such a situation surely qualifies as whining.
> But it did seem
> reasonable that chdir would do so.
It will do so if you chdir to the right place.
> But I really hate the way anybody who asks any kind of question gets
^^^^^^^^
> their head bitten off.
You are not sufficiently observant then.
You did not get your head bitten off for asking your question, you
got your head bitten off for seemingly ignoring earlier helpful
debugging advice.
You have incorrectly identified the characteristic that brings
on head biting.
By pointing out the real reason I hope to help you preserve
your head in future postings. :-)
> Why are you posting to usenet at all?
Because we like to help people.
> Why are
> you responding to somebody asking a question if you don't want to
> help?
Showing how to get more debugging information IS helpful, even for
folks who think less information is better for some odd reason.
> Just to get the chance to make somebody feel stupid?
When you ignored the good advice, you made the answerer feel
stupid for wasting his time.
Are you posting just to get the chance to make somebody feel stupid?
(you should expect to be repaid in kind)
> Anyway, thanks, I just had to say that.
It may feel better to get it off of your chest, but it has cost you...
> I see other people get jumped
> on the same way and I always hate it.
Perhaps you should think a bit more carefully about identifying the root
cause of the "jumping". It is very very seldom because you asked
a question, even an obvious one. It is nearly always because
of some (real or perceived) breach of netiquette.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 27 May 2004 10:58:04 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Templating system needs help
Message-Id: <pan.2004.05.27.08.52.08.170881@aursand.no>
On Thu, 27 May 2004 06:19:32 +0000, Uri Guttman wrote:
>> As you can see, the []-tags have been converted to <>-tags by now,
>> which is ideal to let the templating system create/generate templates.
> gack! :)
Excactly. Imagine that these tags also can be combined;
template.txt
------------
<!-- [WORD_<!-- %%NR%% -->] -->
script.pl
---------
$Template->subst( 'NR', 1 );
print Template->get-template();
output
------
<!-- %%WORD_1%% -->
> well, that is easily done with a second pass looking for [] markers.
Actually, yes. In my module it's the last thing that gets done when
processing the template.
AFAIT, however, this makes it impossible (?) to preprocess the template in
any form, as you never know what your tags _really_ will look like after
the user have been substituting and replacing tags.
> yes, we need more templaters! :)
Indeed. It was very fun to write this module, until I came to the thing
with the lists (in lists...). Gah! :)
> i have written so many little templaters for projects. i never seem to
> get around to using one of the modules as they are overkill in my
> experience. and writing templaters is easy. :)
Not only overkill, but too many of them introduces too much logic in the
template system. I feel that the logic should solely be in the scripts,
and that templates are only for "markup".
The closest thing to logic in my module is replacement tags;
template.txt
------------
<!-- %%TAG REPLACE BEGIN%% -->
This text should be replaced.
<!-- %%TAG REPLACE END%% -->
script.pl
---------
$Template->replace( 'TAG', 'something' );
I've also thought about introducing sorting (for lists), which can be
implemented directly in the template files;
<!-- %%USER_LIST BEGIN%% -->
<!-- %%_SORT:LASTNAME,STR,ASC;FIRSTNAME,STR,ASC%% -->
<!-- %%LASTNAME%% -->, <!-- %%FIRSTNAME%% -->
<!-- %%USER_LIST END%% -->
But I don't know about this one yet. Might as well keep it as clean and
simple as possible and have this done from the script instead.
--
Tore Aursand <tore@aursand.no>
"The most likely way for the world to be destroyed, most experts agree,
is by accident. That's where we come in; we're computer professionals.
We cause accidents." (Nathaniel Borenstein)
------------------------------
Date: Thu, 27 May 2004 10:58:12 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Templating system needs help
Message-Id: <pan.2004.05.27.08.57.47.517209@aursand.no>
On Thu, 27 May 2004 00:30:12 -0600, Bill wrote:
>> Now. I have absolutely _no_ idea on how to create this list (and take
>> height for the fact that there can be unlimited nested lists). Anyone
>> feel like they have the guts to try? :)
> Any chance this can just be translated to the Template.pm format:
> [...]
It is possible, of course, but I don't want to walk that path for a number
of reasons;
* The system that generates these templates can't be messed with,
which in turn forces me to create a "gateway" (which converts
them).
* Template::Toolkit (and many of the other templating systems, as
well) are overkill (or too heavy), IMO.
* I still have a lot to learn when it comes to Perl. Creating a
templating system has forced me to come up with better ideas
for many things that I really didn't think much about before.
One small thing: Speed _will_ be an issue at some point, and my simple
benchmarks shows that my module is quite faster than Template::Toolkit and
HTML::Template (which are the templating systems that I've benchmarked it
against).
For the record: If I ever finishes this module, and it works as expected,
I will - of course - release it to CPAN. Name suggestions, anyone? :)
--
Tore Aursand <tore@aursand.no>
"Have you ever had a dream, Neo, that you were so sure was real? What
if you were unable to wake from that dream? How would you know the
difference between the dream world and the real world?" (Morpheus, The
Matrix)
------------------------------
Date: 27 May 2004 10:32:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Templating system needs help
Message-Id: <c94g40$m9o$1@mamenchi.zrz.TU-Berlin.DE>
Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
[...]
> For the record: If I ever finishes this module, and it works as expected,
> I will - of course - release it to CPAN. Name suggestions, anyone? :)
No. Writing modules is easy. Naming modules is hard.
:)
Anno
------------------------------
Date: Thu, 27 May 2004 13:23:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Templating system needs help
Message-Id: <x7n03uf1gd.fsf@mail.sysarch.com>
>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:
TA> Excactly. Imagine that these tags also can be combined;
TA> template.txt
TA> ------------
TA> <!-- [WORD_<!-- %%NR%% -->] -->
double gack!
TA> Actually, yes. In my module it's the last thing that gets done when
TA> processing the template.
do you process code and text in the template?
TA> AFAIT, however, this makes it impossible (?) to preprocess the
TA> template in any form, as you never know what your tags _really_
TA> will look like after the user have been substituting and replacing
TA> tags.
why not? just do multiple passes seems to be the answer.
>> i have written so many little templaters for projects. i never seem to
>> get around to using one of the modules as they are overkill in my
>> experience. and writing templaters is easy. :)
TA> Not only overkill, but too many of them introduces too much logic in the
TA> template system. I feel that the logic should solely be in the scripts,
TA> and that templates are only for "markup".
yep. that is the essence of my new design. pure perl logic and pure text
(usually in a here doc).
TA> The closest thing to logic in my module is replacement tags;
TA> template.txt
TA> ------------
TA> <!-- %%TAG REPLACE BEGIN%% -->
TA> This text should be replaced.
TA> <!-- %%TAG REPLACE END%% -->
TA> script.pl
TA> ---------
TA> $Template->replace( 'TAG', 'something' );
i supported simple if/else as it was useful to do it there. but the
condition was tested from the hash and can't be a general test. so you
must set the boolean result in the data tree first keeping the real
logic out of the text again. if i remember to get the code and examples
from work, i will show that too.
TA> I've also thought about introducing sorting (for lists), which can be
TA> implemented directly in the template files;
TA> <!-- %%USER_LIST BEGIN%% -->
TA> <!-- %%_SORT:LASTNAME,STR,ASC;FIRSTNAME,STR,ASC%% -->
TA> <!-- %%LASTNAME%% -->, <!-- %%FIRSTNAME%% -->
TA> <!-- %%USER_LIST END%% -->
but that seems to mean you can control the template syntax. i thought it
was fixed in concrete and passed to you. if you can change it some, you
can use some of my design.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 27 May 2004 16:46:42 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Templating system needs help
Message-Id: <pan.2004.05.27.14.41.49.931599@aursand.no>
On Thu, 27 May 2004 13:23:47 +0000, Uri Guttman wrote:
>> Actually, yes. In my module it's the last thing that gets done when
>> processing the template.
> do you process code and text in the template?
You mean Perl code in the template file? No. The template "language" is
pure markup/tags; no logic or "code".
>> AFAIT, however, this makes it impossible (?) to preprocess the
>> template in any form, as you never know what your tags _really_
>> will look like after the user have been substituting and replacing
>> tags.
> why not? just do multiple passes seems to be the answer.
Hmm. Maybe you're right. I need to look into this some more. But do I
really _want to_ do multiple passes if I _really_ don't have to? :)
>> I've also thought about introducing sorting (for lists), which can be
>> implemented directly in the template files;
>>
>> <!-- %%USER_LIST BEGIN%% -->
>> <!-- %%_SORT:LASTNAME,STR,ASC;FIRSTNAME,STR,ASC%% -->
>> <!-- %%LASTNAME%% -->, <!-- %%FIRSTNAME%% -->
>> <!-- %%USER_LIST END%% -->
> but that seems to mean you can control the template syntax.
Does it? Why do you think so? Just because of that '_SORT' thing?
That's a feature I plan to _add_ to the existing syntax.
If you mean that I switch between '<%% ... %%>' and '<!-- %%TAG%% -->',
it's because the latter (which is the _real_ syntax) takes more space (and
I try to keep my line lengths below 80 characters on Usenet).
With my module you can change the start and end tag, however. 'new()'
accepts a list of arguments;
filename
tag_begin (default: '<!-- %%')
tag_end (default: '%% -->')
I have to change 'new()' though, so that it can accept either only a
filename _or_ a hash, as I want to write for example:
my $Template = Template->new(filename => 'template.thtml',
path => \@paths);
This way, I can let the module search for - and find the first occurance
of - a file named 'template.thtml' among @paths.
--
Tore Aursand <tore@aursand.no>
"The road to hell is full of good intentions." (Bruce Dickinson)
------------------------------
Date: Thu, 27 May 2004 16:46:43 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Templating system needs help
Message-Id: <pan.2004.05.27.14.33.02.518107@aursand.no>
On Thu, 27 May 2004 10:32:32 +0000, Anno Siegel wrote:
>> For the record: If I ever finishes this module, and it works as
>> expected, I will - of course - release it to CPAN. Name suggestions,
>> anyone? :)
> No. Writing modules is easy. Naming modules is hard. :)
Haha. Excellent point, Anno. May I add that statement to my signature
collection?
--
Tore Aursand <tore@aursand.no>
"The science of today is the technology of tomorrow." (Edward Teller)
------------------------------
Date: Thu, 27 May 2004 18:13:44 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: xml type parser in the standard perl installation ?
Message-Id: <Nultc.17$wQ3.117@news.oracle.com>
Hi
I have a script where some chuncks of text are marked between xml-type
tags .
I say 'xml-type' instead of xml as the tags are preceded with a comment
character "# " so that the script does not fail.
I need to be able to extract the data between tags (which can be
nested), and store it in a hash with each key being the tag itself and
the value, the data in between (it is multiline).
The problem is that I initiially tried using Text::Balanced, but gave up
since ir was too demanding for this kind of work .. spanning across
multiple lines ..
I am thinking of stripping the # from all tagged lines so that it
becomes an xml file, adding a root element (which was not present
before) , and then using an xml parser.
My questions :
1. Is the approach feasible, or is there som other simpler way to do it
.. (after all, TIMTOWTDI)
2. If the above is the optimal solution, is there any parser/module
shipped along with the standard perl (5.8) distro .. ?
Many thanks ..
Abhinav
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6615
***************************************