[24428] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6614 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 03:05:37 2004

Date: Thu, 27 May 2004 00:05:05 -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: 6614

Today's topics:
    Re: CPAN.pm configuration <aletia@2vias.com.ar>
    Re: newbie question <matrix_calling@yahoo.dot.com>
    Re: Stat() function fails? <postmaster@castleamber.com>
    Re: Stat() function fails? <http://joecosby.com/code/mail.pl>
    Re: Stat() function fails? <http://joecosby.com/code/mail.pl>
    Re: Stat() function fails? <Joe.Smith@inwap.com>
    Re: Stat() function fails? <Joe.Smith@inwap.com>
    Re: Stat() function fails? <Joe.Smith@inwap.com>
    Re: Stat() function fails? <http://joecosby.com/code/mail.pl>
    Re: Stat() function fails? <postmaster@castleamber.com>
    Re: Stat() function fails? <ebohlman@omsdev.com>
    Re: Templating system needs help (Randal L. Schwartz)
    Re: Templating system needs help <tassilo.parseval@rwth-aachen.de>
    Re: Templating system needs help <tore@aursand.no>
    Re: Templating system needs help <uri@stemsystems.com>
    Re: Templating system needs help <wherrera@lynxview.com>
    Re: Use contents of variable for search and replace <usenet@morrow.me.uk>
    Re: Using Cookies With Perl (Randal L. Schwartz)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 May 2004 02:23:19 -0300
From: chanio <aletia@2vias.com.ar>
Subject: Re: CPAN.pm configuration
Message-Id: <2hlca9Fdd7bvU1@uni-berlin.de>

kj (comp.lang.perl.misc) dijo...

> 
> 
> 
> On my system I have Perl 5.6.1 under /usr and Perl 5.8.3 under /opt
> [1].  This has broken my ability to use CPAN.pm.  More specifically,
> almost invariably the "make test" step fails.  This is because the
> command that runs the test script uses flags such as
> -I/usr/lib/perl/5.6.1,
> when it should be using -I/opt/lib/perl/5.8.3, etc.  And also, even
> though I bring up the CPAN shell with "/opt/bin/perl -MCPAN -e
> shell", during the "make test" part the tests scripts get run with
> /usr/bin/perl instead of with /opt/bin/perl (although I'm less sure
> that this is the case every time).
> 
> How do I configure things such that CPAN.pm uses the Perl (executable
> and libraries) that live under /opt and not the Perl under /usr?
> 
> Thanks!
> 
> kj
> 
> [1] Long story: basically, my stable-release Debian system uses
> 5.6.1 whenever it needs to use Perl, but I prefer to use 5.8.3;
> the Perl 5.8.x distributed with Debian's testing release is compiled
> with threads, which I do not want, so instead of upgrading my
> system's Perl to testing, I installed 5.8.3 under /opt.

RTFM - I guess that everything that might happen to a perl user is solved by
reading the perldocs.
There is a PERLVAR (or something like this) that when it is set at your
environment, it is telling perl where to find the libraries.
Read about it first because I know by experience that it is very powerful.
I did a mess with my two Win XP perls. I finally , removed it and managed ok
just by declaring use lib ('C:\perl\lib', 'C:\perl\site\lib'); first at
every script.
In your case, I dont' know if it is going to affect your 'cpan' LINUX
command line. But surely every perl command.
At the perldoc, there are some mentions of just using the use lib when
calling the perl -MCPAN command line. You should judge by yourself.

Hope it helps!
alberto
-- 
 .------------------. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
 | ___   _ _  _ _   | ALBERTO ADRIAN SCHIANO - ARGENTINA - 2004
 |/ __/ | \ || | |  | <ALETIA@2VIAS.COM.AR> # 34-34S 058-25W(z-3)
 |||_< \|   || ' |  | +------------+------------------------------
 |`____/|_\_|`___'  | LINUX COUNTER: 240 133  ~ machine : 119 401
 | _    _ _ __  _   | +------------+----------+-------------------
 || |  | \ |\ \/    | AMD Athlon 6 |RAM 512Mb.|krnl.: 2.6.3-10mdk
 || |_ |   | \ \    | i586-mandrake-linux-gnu |MDK 9.2 - KDE 3.13
 ||___||_\_|_/\_\   | +-----------------------+-------------------
 | __ __  ___  _ _  | Maxtor #4D040H2 32Gb.   |DISPLAY_VGA SiS 630
 ||  \  \| . \| /   | ------------------------+--+----------------
 ||     || | ||  \  | PCI Audio snd-trident 7018 | ViewSonic E771
 ||_|_|_||___/|_\_  | ---------------------------+----------------
 |                  | http://perlmonks.org/index.pl?node_id=245320
 '------------------' -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.


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

Date: Thu, 27 May 2004 12:24:22 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: newbie question
Message-Id: <gngtc.1$wQ3.12@news.oracle.com>



Jim Cochrane wrote:
> In article <zJZsc.5$Bk6.98@news.oracle.com>, Abhinav wrote:
> 
>>Hi,
>>
[SNIP]

> 
> You'll greatly increase your chances of getting useful help by summarizing
> your question in the subject field - 'newbie question' is way too general.
> Many experts will just ignore such subjects.
> 
Hi Jim,

You are right ! But i just _couldn't_ come up with a short but 
descriptive subjectfor this one .. :( :)
I didnt try hard enough ... in fact, it wont be wrong to say that I 
didnt try at all ..

> You're lucky Anno is so patient :-)
> 
> 

True ..Thanks to you both :)

Regards
AB



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

Date: Wed, 26 May 2004 23:31:21 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Stat() function fails?
Message-Id: <40b56f1b$0$197$58c7af7e@news.kabelfoon.nl>

Joe Cosby wrote:

> (start of script)
> use File::stat;

Put use strict; and use warnings; on top.

> chdir 'C:\\My Documents\\DR\\fm docs\\NetComDocs\\user\\doc' || die
> "Couldn't chdir";
> $pathroot = 'C:\\My Documents\\DR\\fm docs\\NetComDocs\\user\\doc\\';

why don't you chdir to pathroot? This is prone to errors. Also, use 
forward slashes instead of \.


> $some_dir = "software";
> opendir(DIR, $some_dir) or die "Can't open directory";
> while (defined($filename = readdir(DIR)))

I recommend naming it $leafname

> {
> 	$filename = $pathroot . $filename;

Since this is very confusing.

And wrong, since you are now in $some_dir. "$pathroot$filename" probably 
doesn't exists.

> 	$st = stat($filename) or die "Can't stat file $filename: $!";

Which should be clear from this error.


> 	print $filename . " " . $st->mode . "\n";
> }
> closedir(DIR)
> 
> (end of script)
> 
> This doesn't seem to work either, I get:
> 
> "C:\My Documents\projects\java dir walker>perl "C:\My
> Documents\projects\perl dir walker\dirwalker.pl"
> C:\My Documents\DR\fm docs\NetComDocs\user\doc\. 16895
> C:\My Documents\DR\fm docs\NetComDocs\user\doc\.. 16895
> Can't stat file C:\My Documents\DR\fm
> docs\NetComDocs\user\doc\taxcalculator:  at C:\My
> Documents\projects\perl dir walker\dirwalker.pl line 11."

Because it is most likely in "$pathroot$software/$filename";

> It should run on another setup without too much work, changing the
> chdir line, the $pathroot and $some_dir so they mapped to a directory
> on your own system.
> 
> If it works on somebody else's setup and not mine I will probably give
> up on this.

Do so, and have a look at File::Find.


-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Wed, 26 May 2004 21:49:37 -0700
From: Joe Cosby <http://joecosby.com/code/mail.pl>
Subject: Re: Stat() function fails?
Message-Id: <01sab05j8q1kru2hsshm8l84af2bv6dguc@4ax.com>

On 27 May 2004 02:53:52 GMT, "A. Sinan Unur" <1usa@llenroc.ude> wrote:

>Joe Cosby <http://joecosby.com/code/mail.pl> wrote in 
>news:25kab0p08serahc7uplnr6qp364gumipm8@4ax.com:
>
>> On Thu, 27 May 2004 01:26:05 -0000, "gnari" <gnari@simnet.is> wrote:
>> 
>>>"Joe Cosby" <http://joecosby.com/code/mail.pl> wrote in message
>>>news:0jfab05uf6gi8c8ufr0mp3rppgfrt91sq3@4ax.com...
>>>
>>>[snip problem involving readdir()]
>>>
>>>just show us a minimal program that shows this behaviour.
>>>
>>>the usual gotcha with readdir() is that it returns a list of leaf
>>>filenames, and people forget to apply the full path when using
>>>them in IO operations.
>>>
>>>you imply that you have not fallen into this trap, but we will
>>>believe it when we see code.
>> 
>> Thanks for both responses, I tried appending the full path at an
>> earlier point (although it -seemed- that shouldn't be necessary
>> because I had chdir()'d), this is a version with the full path added
>> to $filename:
>> 
>
>OK, I have to admit this is getting irritating. It looks like you have 
>not paid attention to any of the comments I made.
>

I wasn't trying to ignore your comments ... in your response, you
added rewritten versions of the individual lines of code after each
line ... when I looked at it I didn't realize you were saying "I think
you wrote these lines of code wrong, try this way instead".

It just looked like line wrap artifacts when I first read the
response.

Thanks.

>> (start of script)
>> use File::stat;
>> 
>> chdir 'C:\\My Documents\\DR\\fm docs\\NetComDocs\\user\\doc' || die
>> "Couldn't chdir";
>
>
>use strict;
>use warnings;
>
>my $pathroot = 'C:/My Documents/DR/fm docs/NetComDocs/user/doc';
>
>chdir $pathroot or die "Couldn't chdir to $pathroot: $!";
>
>> $some_dir = "software";
>> opendir(DIR, $some_dir) or die "Can't open directory";
>> while (defined($filename = readdir(DIR)))
>
>You are reading the $some_dir directory in $pathroot.
>
>> {
>>      $filename = $pathroot . $filename;
>>      $st = stat($filename) or die "Can't stat file $filename: $!";
>
>Why are you not prepending $some_dir to the $filename?
>
>stat("$pathroot/$some_dir/$filename") 
>    	or die "Can't stat file $pathroot/$some_dir/$filename: $!";
>

Ah you're right, that was the problem.  The complete path name was
needed for the stat() command, despite my having done the chdir.

Thanks.

>> If anybody has time, could they verify this script on their own
>> system, if there isn't anything obviously wrong in the code?
>
>There _is_ something obviously wrong with the code.

-- 
Joe Cosby
http://joecosby.com/ 
Last night you were, unhinged. 
You were like some desperate, howling demon. 
You frightened me. ..........  Do it again. 
 


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

Date: Wed, 26 May 2004 22:03:44 -0700
From: Joe Cosby <http://joecosby.com/code/mail.pl>
Subject: Re: Stat() function fails?
Message-Id: <n7tab0t5533uqdovj7n3bubja66ao9mpm0@4ax.com>


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.

The perl docs are just not very clear.  I apologize, I know that will
strike some people as my whining because I screwed up, but the reality
is, I really do try my best to read documentation such as it exists
before asking for help.  The docs did say explicitly that the
opendir() would -not- be sufficient for establishing a path to a file.
I read that and knew that and mentioned it earlier.  But it did seem
reasonable that chdir would do so.

But I really hate the way anybody who asks any kind of question gets
their head bitten off.  Why are you posting to usenet at all?  Why are
you responding to somebody asking a question if you don't want to
help?  Just to get the chance to make somebody feel stupid?

Anyway, thanks, I just had to say that.  I see other people get jumped
on the same way and I always hate it.

-- 
Joe Cosby
http://joecosby.com/ 
You mystics are a sorry lot, always whimping about so-and-so's "ego"
getting in the way of their "detachment." Take it to alt.zen.ego-death,
for the love of pete! This is alt.MAGICK. 
 


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

Date: Thu, 27 May 2004 05:19:19 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Stat() function fails?
Message-Id: <rTetc.6542$Ly.3080@attbi_s01>

Joe Cosby wrote:

> I chdir to the directory I'm reading and this is succesful, and the
> readdir() is pulling the correct list of file names, but when I try to
> stat($filename) it fails.

It works if you actually chdir to the directory, not its parent.
If you are not actually inside the directory in question, you have
to prepend the directory name to the directory entry to get a filename.

> opendir(DIR, $some_dir) or die "Can't open directory";
> while (defined($filename = readdir(DIR)))
> {
> 	$st = stat($filename) or die "Can't stat file $filename: $!";

Very common mistake.  It's "$some_dir/$filename" not "$filename".

   while (defined $dir_entry = readdir DIR) {
       $filename = "$some_dir/$dir_entry";
       $st = stat($filename) or die "Can't stat file $filename: $!";
       ...
   }

	-Joe


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

Date: Thu, 27 May 2004 05:25:35 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Stat() function fails?
Message-Id: <iZetc.2879$n_6.2251@attbi_s53>

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(),

It doesn't have to be a full path name or an absolute path name.
Just a proper relative pathname.

> originally as I mentioned in my original post I thought that if I had
> chdir()'d to the directory that wouldn't be necessary.

If you had chdir()'d to $some_dir and done an opendir(DIR,'.') it
would have worked.  Whenever you use anything other than '.' as the
argument to opendir, you need to prepend the directory name.
	-Joe


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

Date: Thu, 27 May 2004 05:29:01 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Stat() function fails?
Message-Id: <x0ftc.30878$af3.1725532@attbi_s51>

Joe Cosby wrote:

> But I really hate the way anybody who asks any kind of question gets
> their head bitten off.  Why are you posting to usenet at all?  Why are
> you responding to somebody asking a question if you don't want to help?

Every single posting I've seen in this thread is trying to help.
In this particular thread there were no rude comments.
Just recommendations, which if followed, lead to the solution.
	-Joe


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

Date: Wed, 26 May 2004 23:04:08 -0700
From: Joe Cosby <http://joecosby.com/code/mail.pl>
Subject: Re: Stat() function fails?
Message-Id: <161bb01at2fr0soa8ni2j2av0j4jnvvukm@4ax.com>

On Thu, 27 May 2004 05:29:01 GMT, Joe Smith <Joe.Smith@inwap.com>
wrote:

>Joe Cosby wrote:
>
>> But I really hate the way anybody who asks any kind of question gets
>> their head bitten off.  Why are you posting to usenet at all?  Why are
>> you responding to somebody asking a question if you don't want to help?
>
>Every single posting I've seen in this thread is trying to help.
>In this particular thread there were no rude comments.
>Just recommendations, which if followed, lead to the solution.
>	-Joe

Thanks for your help and I apologize if I misconstrued.

-- 
Joe Cosby
http://joecosby.com/ 
In the room the women come and go
Singing of great Pinocchio
 


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

Date: Thu, 27 May 2004 01:46:39 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Stat() function fails?
Message-Id: <40b58ed1$0$191$58c7af7e@news.kabelfoon.nl>

Joe Cosby wrote:

> But I really hate the way anybody who asks any kind of question gets
> their head bitten off.  Why are you posting to usenet at all?  Why are
> you responding to somebody asking a question if you don't want to
> help?  Just to get the chance to make somebody feel stupid?

Usenet isn't, and never was, a free helpdesk.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: 27 May 2004 06:56:31 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Stat() function fails?
Message-Id: <Xns94F6146F9CF06ebohlmanomsdevcom@130.133.1.4>

Joe Cosby <http://joecosby.com/code/mail.pl> wrote in 
news:n7tab0t5533uqdovj7n3bubja66ao9mpm0@4ax.com:

> But I really hate the way anybody who asks any kind of question gets
> their head bitten off.  Why are you posting to usenet at all?  Why are
> you responding to somebody asking a question if you don't want to
> help?  Just to get the chance to make somebody feel stupid?
> 
> Anyway, thanks, I just had to say that.  I see other people get jumped
> on the same way and I always hate it.

You didn't get your head bitten off.  A number of experienced posters gave 
you some advice on how to change your code to make it easier to find out 
where your problem was.  You didn't show any evidence that you even tried 
to follow that advice until you'd been through several iterations of the 
process.  If someone makes a suggestion to you, and your response to them 
indicates that you've completely ignored that suggestion, then that someone 
is going to at the least get a little frustrated.

If you want people to help you, you have an obligation to conduct yourself 
in such a way that the person(s) helping you don't feel like they're 
banging their head(s) against a brick wall.  In your original code, there 
were any number of filesystem-related operations that could have failed, 
yet you didn't check that they succeeded.  Several posters gave you some 
code to check that they did in fact succeed, but each time you responded, 
you showed code that still didn't include the checks.  That gets *really* 
annoying *really* fast.

Any experienced programmer (regardless of what language is used) knows that 
filesystem operations are full of gotchas that need to be checked for.  You 
can't guarantee that Mr. Murphy will never pay you a visit, but failing to 
check filesystem operations for success amounts to buying him a first-class 
plane ticket and putting him up in the most expensive hotel in your 
neighborhood.  If people ask you to implement checks and you fail do so, 
then you come off as A in the following exchange:

A: My head hurts.
B: What are you doing right now?
A: Hitting myself on the head with a hammer and trying to figure out why 
stat() is failing.
B: Well first put down the hammer.
A: My head still hurts.
B: What are you doing now?
A: Hitting myself on the head with a hammer and trying to put a pathname on 
the file I'm stat()ing.
B: What's making your head hurt doesn't have anything to do with stat(), 
it's the damn hammer.  Put it down.
A: I thought my chdir() should have worked, but I still get a headache on 
each hammer hit.
B: PLONK!

If someone gives you advice and you don't understand it, *say so*!  You 
won't get flamed for doing so (you may get pointed to a reference rather 
than getting a direct answer.  That's an expression of *respect* for you 
(you're presumed to be competent enough to discover the answer yourself), 
not a brush-off.  The reference will probably do a better job of explaining 
the situation to you than the advice-giver could have done personally.  A 
lot of people have spent a lot of time and effort creating Perl's 
comprehensive, *free* (as in both beer and speech) documentation.  You can 
pay thousands of dollars for compilers whose documentation can't hold a 
light to Perl's).  If you simply ignore it in a futile attempt to save 
face, you're going to antagonize everyone you're dealing with.


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

Date: Thu, 27 May 2004 05:09:48 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Templating system needs help
Message-Id: <f9056ba1023181553ff8119e5544cc07@news.teranews.com>

>>>>> "Tore" == Tore Aursand <tore@aursand.no> writes:

Tore> On Wed, 26 May 2004 22:58:42 +0000, Eric Bohlman wrote:
>>> Actually, I'm not sure I understand why you can't. Most modules there
>>> are provided under the artistic license, which I thought does not
>>> prevent you from using the modules with propriety code.

>> I think he was trying to say that the template files already exist, and
>> were written in a novel template language.

Tore> That's correct.  I can't use any of them - AFAIK.  And - still AFAIK -
Tore> none of them handles lists (in lists) the way I'm looking for, so I can't
Tore> "borrow" some of the existing modules' code, either.

Well, I bet you could do a source-to-source translator from your
magical templating language to Template Toolkit's language, or even
plugin in a different parser with relative ease.

There's still no point in starting from scratch.

print "Just another Perl hacker,"; # the first

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 27 May 2004 07:30:38 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Templating system needs help
Message-Id: <2hlco0Fej4ppU1@uni-berlin.de>

Also sprach Tore Aursand:

> I need to develop a templating system.  I _cannot_ use on of the
> templating systems found on CPAN as this utility will be used on
> "proprietary" (and already existing) template files.  So - please don't
> tell me to go to CPAN; I already know of it, and I know the templating
> systems found there.  Thanks.
> 
> The problem is lists.  And lists in lists (in lists...).  I've decided to
> have the data structure for my lists like this:
> 
>   $VAR1 = {
>       '__ROOT__' => {
>           'children' => [
>               {
>                   'name'     => 'WEEK_LIST',
>                   'columns'  => [ 'NR' ],
>                   'values'   => [
>                       [ '1' ],
>                       [ '2' ]
>                   ],
>                   'children' => [
>                       {
>                           'name'    => 'DAY_LIST',
>                           'columns' => [ 'DAY' ],
>                           'values'  => [
>                               [ '1' ],
>                               [ '2' ],
>                               [ '3' ],
>                               [ '4' ],
>                               [ '5' ],
>                               [ '6' ],
>                               [ '7' ],
>                           ]
>                       },
>                       {
>                           'name'    => 'DAY_LIST',
>                           'columns' => [ 'DAY' ],
>                           'values'  => [
>                               [ '8' ],
>                               [ '9' ],
>                               [ '10' ],
>                               [ '11' ],
>                               [ '12' ],
>                               [ '13' ],
>                               [ '14' ],
>                           ]
>                       }
>                   ]
>               }
>           ]
>       }
>   }
> 
> This is from Data::Dumper, though I had to reformat it a bit.  I guess you
> all get the point.  The template for this data looks like this (shortened):
> 
>  <%% WEEK_LIST BEGIN %%>
>  <%% NR %%>:<%% DAY_LIST BEGIN %%> <%% DAY %%><%% DAY_LIST END %%>
>  <%% WEEK_LIST END %%>
> 
> Thus - in the end - the following output should be created:
> 
>   1: 1 2 3 4 5 6 7
>   2: 8 9 10 11 12 13 14
> 
> 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? :)

You are best off using a proper grammar for this kind of mini-language
where things can be nested arbitrarily deeply. Depending on how complex
the templating language is you can write a custom recursive descent
parser for it. That naturally requires that your grammar would be LL(1)
which forbids left-recursiveness and common prefixes such as

    rule -> pref rule1 | pref rule2

Both can be eliminated through some transformations (the latter is
solved with left factorization). You'll also need a tokenizer that
returns the next token your parser is supposed to look-ahead at.

Or you just use Parse::RecDescent to create the parser for you. This
means getting acquainted with a complex-ish module but it would spare
you some boring work such as calculating the predict sets yourself which
a recursive descent parser usually needs.

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~~dddd;eval


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

Date: Thu, 27 May 2004 08:03:09 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Templating system needs help
Message-Id: <pan.2004.05.27.06.02.52.806407@aursand.no>

On Thu, 27 May 2004 01:25:58 +0000, Uri Guttman wrote:
>> [...]

> very recently i did something like this for a proof of concept. it is a
> different way to look at templating but it fits your needs well. but the
> code is at work so i will get it tomorrow. rather small and interesting
> stuff as well.

I'm looking forward to have a look at it!

> the concept is that you preprocess the templates and extract out the
> 'chunks' that are delimited by BEGIN/END (and they have a name).

Hmm.  I really don't think I can do that, if I understand you correctly. 
There are ways to dynamically create lists, and that is done by using a
"template tag" which is - uhm - interpolated (?) into the "real template
tag".

Don't know how I can explain this any better, but take a look at this
example template file:

  This <%% WORD_1 %%> a [%% TPL_1 %%]

In my script I do something like this:

  my $Template = Template->new( ... );
  $Template->subst( 'WORD_1', 'is' );
  $Template->subst( 'TPL_1', 'WORD_2' );
  print $Template->get_template();

The output will be:

  This is a <%% WORD_2 %%>

As you can see, the []-tags have been converted to <>-tags by now, which
is ideal to let the templating system create/generate templates.

I have been trying out some code since my original post, and I will post
that code very soon (when it works a bit better than it does now).  I feel
that I'm getting quite close to dealing with that list thing. :)


-- 
Tore Aursand <tore@aursand.no>
"Computer science education cannot make anybody an expert programmer
 any more than studying brushes and pigment can make somebody an expert
 painter." (Eric Raymond)


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

Date: Thu, 27 May 2004 06:19:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Templating system needs help
Message-Id: <x77juygznv.fsf@mail.sysarch.com>

>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:

  TA> On Thu, 27 May 2004 01:25:58 +0000, Uri Guttman wrote:
  >>> [...]

  >> the concept is that you preprocess the templates and extract out the
  >> 'chunks' that are delimited by BEGIN/END (and they have a name).

  TA> Hmm.  I really don't think I can do that, if I understand you correctly. 
  TA> There are ways to dynamically create lists, and that is done by using a
  TA> "template tag" which is - uhm - interpolated (?) into the "real template
  TA> tag".

it handles single tags as well. the hard part is chunks and lists. my
design assumes the data is already for use by the template so it can
handle any dynamic lists/hashes you want.

  TA> Don't know how I can explain this any better, but take a look at this
  TA> example template file:

  TA>   This <%% WORD_1 %%> a [%% TPL_1 %%]

  TA> In my script I do something like this:

  TA>   my $Template = Template->new( ... );
  TA>   $Template->subst( 'WORD_1', 'is' );
  TA>   $Template->subst( 'TPL_1', 'WORD_2' );
  TA>   print $Template->get_template();

  TA> The output will be:

  TA>   This is a <%% WORD_2 %%>

  TA> As you can see, the []-tags have been converted to <>-tags by now, which
  TA> is ideal to let the templating system create/generate templates.

gack! :)

well, that is easily done with a second pass looking for [] markers.

  TA> I have been trying out some code since my original post, and I will post
  TA> that code very soon (when it works a bit better than it does now).  I feel
  TA> that I'm getting quite close to dealing with that list thing. :)

yes, we need more templaters! :)

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. :)

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 00:30:12 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: Templating system needs help
Message-Id: <8MmdnSSVYqtqFyjdRVn-ig@adelphia.com>

Tore Aursand wrote:
> Hi!
> 
> I need to develop a templating system.  I _cannot_ use on of the
> templating systems found on CPAN as this utility will be used on
> "proprietary" (and already existing) template files.  So - please don't
> tell me to go to CPAN; I already know of it, and I know the templating
> systems found there.  Thanks.
> 
> The problem is lists.  And lists in lists (in lists...).  I've decided to
> have the data structure for my lists like this:

 ....

> This is from Data::Dumper, though I had to reformat it a bit.  I guess you
> all get the point.  The template for this data looks like this (shortened):
> 
>   <%% WEEK_LIST BEGIN %%>
>   <%% NR %%>:<%% DAY_LIST BEGIN %%> <%% DAY %%><%% DAY_LIST END %%>
>   <%% WEEK_LIST END %%>
> 
> Thus - in the end - the following output should be created:
> 
>   1: 1 2 3 4 5 6 7
>   2: 8 9 10 11 12 13 14
> 
> 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:

 >   <%% WEEK_LIST BEGIN %%>
 >   <%% NR %%>:<%% DAY_LIST BEGIN %%> <%% DAY %%><%% DAY_LIST END %%>
 >   <%% WEEK_LIST END %%>

becomes, for the array ref of array of hash refs to key nr and value 
array ref daylist

(whitespace may need tweaking etc)

Template.pm template 'template.tp':
=============
[% FOREACH week=weeklist %]
[% week.nr %]: [% FOREACH day=week.daylist %] [% day %] [% END %]
[% END %]
==============
called with


use Template;
use strict;
use warnings;


my $template = new Template;

my $vars = {
	weeklist => [
	{ nr => 1, daylist => [ qw(1 2 3 4 5 6 7) ] },
	{ nr => 2, daylist => [ qw(18 9 10 11 12 13 14)] },
         ],
};

$template->process('template.tp', $vars);

=========

Now, it seems to me that there should be a way to translate from your 
templates to Template.pm's, though YMMV.



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

Date: Thu, 27 May 2004 06:13:05 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Use contents of variable for search and replace
Message-Id: <c940th$oi3$1@wisteria.csv.warwick.ac.uk>


Quoth Paul Lalli <ittyspam@yahoo.com>:
> On Wed, 26 May 2004, wappel wrote:
> 
> > I have the following problem:
> >
> > I have an XML text which consists of several chapters that have a
> > number-Attribute
> > <xmltext>
> > <chapter number="345">
> >    ...searchtext...
> > </chapter>
> > <chapter number="446">
> >   ...searchtext...
> > </chapter>
> > </xmltext>
> >
> > Now I want to replace the ...searchtext... by <search
> > number="xxx">...searchtext...</search>, where xxx is the value of
> > number-Attribute of the chapter in which the ...searchtext... stands:
> > <chapter number="345>
> >    <search number="345">...searchtext</search>
> > <chapter>
> > <chapter number="446">
> >    <search number="345">...searchtext</search>
> > </chapter>
> > ..searchtext... could be a regular expression.
> >
> > Maybe it is possible to do it with
> >     s/(...searchtext...)/<search number="$variable">$1</search>/gs;
> > ???
> > But how do I get the right value into the variable?
> 
> Ideally, you would be far far better off using one of the XML Parsing
> modules on CPAN.  Failing that, however, this would be my initial
> (untested) attempt:
> 
> s[(<chapter number="(\d+)">)(.*?)(</chapter>)]
>  [$1\n<search number="$2">$3</search>\n$4]gs;

Presumably the OP (although it isn't clear) didn't mean the searchtext
to be the whole contents of the <chapter>. So (also untested):

my @chapters;
my $searchtext = qr/.../;

while (length $xml) {
    $xml =~ s/(.+)(?!<chapter\s)//s and push @chapters, [undef, $1];
    push @chapters, [$1, $2] 
        while $xml =~ s!^<chapter\s+number="(\d+)">(.*?)</chapter>!!s;
}

for (@chapters) {
    defined $_->[0] or $xml .= $_->[1], next;
    $_->[1] =~ s{($searchtext)}
                {<search number="$_->[0]">$1</search>}g;
    $xml .= "<chapter number="$_->[0]">$_->[1]</chapter>";
}

Again, it would *really* be better to use an XML parsing module.

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Thu, 27 May 2004 05:09:48 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Using Cookies With Perl
Message-Id: <6f04cfb363d9fa14a3f928e795072204@news.teranews.com>

>>>>> "James" == James Hunt <jameskorea2003@hotmail.com> writes:

James> Does anyone have a good web reference for setting up and accessing cookies
James> with Perl?

Many people refer to my
<http://www.stonehenge.com/merlyn/WebTechniques/col61.html> for "basic
Cookie Management".


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

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 6614
***************************************


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