[30151] in Perl-Users-Digest
Perl-Users Digest, Issue: 1394 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 26 11:10:17 2008
Date: Wed, 26 Mar 2008 08:09:09 -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 Wed, 26 Mar 2008 Volume: 11 Number: 1394
Today's topics:
display in a tree structure <vakayil.thobias@alcatel-lucent.com>
Re: display in a tree structure <sandy_saydakov@yahoo.com>
Re: forward to another URL <joost@zeekat.nl>
Re: forward to another URL <nahanfee@gmail.com>
Re: forward to another URL <joost@zeekat.nl>
Re: forward to another URL <veatchla@yahoo.com>
Re: forward to another URL <ben@morrow.me.uk>
get rid of non xml compliant lines from a file <gniagnia@gmail.com>
Re: get rid of non xml compliant lines from a file <RedGrittyBrick@SpamWeary.foo>
Re: get rid of non xml compliant lines from a file <ben@morrow.me.uk>
Re: Pattern matching <hjp-usenet2@hjp.at>
Re: Readline using foreach and while <ced@blv-sam-01.ca.boeing.com>
Re: Readline using foreach and while <ben@morrow.me.uk>
Re: Readline using foreach and while <simon.chao@fmr.com>
Re: Readline using foreach and while <ben@morrow.me.uk>
Re: Readline using foreach and while <szrRE@szromanMO.comVE>
Re: Readline using foreach and while <szrRE@szromanMO.comVE>
Re: Readline using foreach and while <simon.chao@fmr.com>
unwanted leading whitespace when using print <rroo@mail.com>
Re: unwanted leading whitespace when using print <rroo@mail.com>
Re: What's better than Template Toolkit? <joost@zeekat.nl>
Re: What's better than Template Toolkit? <lesley.binks@googlemail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Mar 2008 16:37:32 +0530
From: "Vakayil Thobias" <vakayil.thobias@alcatel-lucent.com>
Subject: display in a tree structure
Message-Id: <1206529653.563871@slbhw0>
Hello,
I have to display the data from a file in tree structure(perl).
The file format is as follows(first field parent, second field child) :
PM01 PM02
PM01 PM1A
PM02 PM03
PM03 PM04
PM04 PM05
PM04 PM06
PM1A PM1B
PM1A PM1C
The output should be like this :
PM01 -- PM02 -- PM03 -- PM04 -- PM05
PM06
PM01 PM1A -- PM1B
PM1C
Anybody have idea ?
Regards,
Thobias
------------------------------
Date: Wed, 26 Mar 2008 07:46:08 -0700 (PDT)
From: Sandy <sandy_saydakov@yahoo.com>
Subject: Re: display in a tree structure
Message-Id: <f9549727-fa04-46b2-8215-62f28a64bfe1@c19g2000prf.googlegroups.com>
On 26 Mar, 04:07, "Vakayil Thobias" <vakayil.thob...@alcatel-
lucent.com> wrote:
>
> I have to display the data from a file in tree structure(perl).
> The file format is as follows(first field parent, second field child) :
>
> PM01 PM02
> PM01 PM1A
> PM02 PM03
> PM03 PM04
> PM04 PM05
> PM04 PM06
> PM1A PM1B
> PM1A PM1C
>
> The output should be like this :
> PM01 -- PM02 -- PM03 -- PM04 -- PM05
> PM01 PM1A -- PM1B
There is a very nice package: http://search.cpan.org/~jhi/Graph-0.84/lib/Graph.pod
use Graph;
my $g = Graph->new();
$g->add_edge('a', 'b');
$g->add_edge('a', 'c');
$g->add_edge('b', 'd');
$g->add_edge('c', 'e');
There are additional packages for traversal:
http://search.cpan.org/~jhi/Graph-0.84/lib/Graph/Traversal.pm
http://search.cpan.org/~jhi/Graph-0.84/lib/Graph/Traversal/BFS.pm -
Breadth first
http://search.cpan.org/~jhi/Graph-0.84/lib/Graph/Traversal/DFS.pm -
Depth first
Or you can traverse it yourself by starting at the root and calling
$root->successors() and then call the same method for every element in
the returned list and print edges in the format you want.
Good luck
/sandy
http://myperlquiz.com/
------------------------------
Date: Wed, 26 Mar 2008 08:35:52 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: forward to another URL
Message-Id: <87od92ndif.fsf@zeekat.nl>
Naved <nahanfee@gmail.com> writes:
> Hello,
>
> Can anyone tell me how can I forward to another URL from my page in
> CGI PERL.
> I don't want to use Redirect method as it is sending back to client
> side and then redirecting the page.
IIRC there isn't a really standardized way to do that, but apache/cgi
will do an internal redirect if the target URL is a *root-relative* path,
so something like:
print $q->redirect('/some/path.html');
will probably work.
> Application::Forward is there but I don't get any example related to
> that method.
I've never heard of that module/function/whatever.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Wed, 26 Mar 2008 01:03:03 -0700 (PDT)
From: Naved <nahanfee@gmail.com>
Subject: Re: forward to another URL
Message-Id: <48482036-85de-407d-b1fe-2010b56d2db4@s19g2000prg.googlegroups.com>
Thanks for the help.
but unfortunately it is not working.
The page is forwarding to another URL after URL re-writing.
which in turn does not solve my issue.
I don't want user to bookmark my page and go directly to html page
instead of first executing login.pl script.
------------------------------
Date: Wed, 26 Mar 2008 11:22:22 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: forward to another URL
Message-Id: <877ifplr8h.fsf@zeekat.nl>
Naved <nahanfee@gmail.com> writes:
> Thanks for the help.
>
> but unfortunately it is not working.
> The page is forwarding to another URL after URL re-writing.
> which in turn does not solve my issue.
>
> I don't want user to bookmark my page and go directly to html page
> instead of first executing login.pl script.
Then you *do* want to redirect at the client side, or maybe I'm not
getting what your problem actually is...
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Wed, 26 Mar 2008 08:41:51 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: forward to another URL
Message-Id: <13ukkl07vpcv23d@news.supernews.com>
Naved wrote:
> Thanks for the help.
>
> but unfortunately it is not working.
> The page is forwarding to another URL after URL re-writing.
> which in turn does not solve my issue.
>
> I don't want user to bookmark my page and go directly to html page
> instead of first executing login.pl script.
In a few occasions I have the main URL coded as a html frame. The top
frame refers to a blank html file, the bottom (main) frame calls the
Perl script or a redirect URL. The URL in the browser remains what they
typed in, not the Perl script nor the redirected URL. This concept may
work for you.
--
Len
------------------------------
Date: Wed, 26 Mar 2008 14:16:10 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: forward to another URL
Message-Id: <ae2qb5-he2.ln1@osiris.mauzo.dyndns.org>
Quoth Joost Diepenmaat <joost@zeekat.nl>:
> Naved <nahanfee@gmail.com> writes:
>
> > Thanks for the help.
> >
> > but unfortunately it is not working.
> > The page is forwarding to another URL after URL re-writing.
> > which in turn does not solve my issue.
> >
> > I don't want user to bookmark my page and go directly to html page
> > instead of first executing login.pl script.
Why are you issuing a redirect at all? Just read in the HTML file
yourself, and serve it up as the output of your script with a text/html
Content-type.
> Then you *do* want to redirect at the client side, or maybe I'm not
> getting what your problem actually is...
If the user visits http://example.com/cgi.cgi, and that issues a 30x to
http://example.com/html.html, the address in the address bar will
change. If the user then bookmarks the page, the bookmark will be to
/html.html, bypassing the CGI. The only safe way around this is to
remove html.html from the document tree and have cgi.cgi return the HTML
directly: there is nothing to prevent a malicious user from visiting
/html.html directly if it is accessible. Depending on what you are
trying to do, HTTP auth may be a better solution.
Ben
------------------------------
Date: Wed, 26 Mar 2008 03:00:46 -0700 (PDT)
From: Mr_Noob <gniagnia@gmail.com>
Subject: get rid of non xml compliant lines from a file
Message-Id: <07f8419d-c3e4-4742-87f6-28a17e98df15@i12g2000prf.googlegroups.com>
Hi all,
I try to write a perl script that would delete all non xml complient
lines (ie beginning with "<" and ending ">").
Here is what i succeded to put down so far :
sub delete_non_xml_lines
{
my $search = new File::List($xmldir);
my @files = @{ $search->find("textfile") };
foreach (@files)
{
my $file = $_;
open(FILE, "< $file") or die "Can't open $file : $!";
while(<FILE>)
{
print if $_ =~ />$/;
}
close FILE;
}
}
But how can I redirect the output for each processed file into an xml
file ?
thanks in advance for helping
Regards
------------------------------
Date: Wed, 26 Mar 2008 11:00:08 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: get rid of non xml compliant lines from a file
Message-Id: <47ea2cbc$0$26090$db0fefd9@news.zen.co.uk>
Mr_Noob wrote:
>
> I try to write a perl script that would delete all non xml complient
> lines (ie beginning with "<" and ending ">").
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
<article>
<sect1>
<title>Observations on XML structure</title>
<para>This is a valid XML document.
Most of the lines don't start with an < symbol.
Some of the lines don't end with an > symbol.
Yet it is still valid XML.</para>
</sect1>
</article>
--
RGB
------------------------------
Date: Wed, 26 Mar 2008 14:27:30 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: get rid of non xml compliant lines from a file
Message-Id: <i33qb5-he2.ln1@osiris.mauzo.dyndns.org>
Quoth Mr_Noob <gniagnia@gmail.com>:
>
> I try to write a perl script that would delete all non xml complient
> lines (ie beginning with "<" and ending ">").
> Here is what i succeded to put down so far :
>
> sub delete_non_xml_lines
> {
> my $search = new File::List($xmldir);
Indirect object syntax (new Foo) is unreliable and can parse
incorrectly. Use
my $search = File::List->new($xmldir);
instead.
> my @files = @{ $search->find("textfile") };
>
> foreach (@files)
> {
> my $file = $_;
This is silly. Use
foreach my $file (@files) {
instead.
> open(FILE, "< $file") or die "Can't open $file : $!";
It is safer to use lexical filehandles and three-arg open.
open(my $FILE, '<', $file) or die ...;
[...from below the code...]
> But how can I redirect the output for each processed file into an xml
> file ?
To write the output to a new file, you need
open(my $XML, '>', "$file.xml") or die ...;
select $XML;
Note that this will leave $XML selected as your default output
filehandle. If you are expecting to write to STDOUT later, you will need
to select it again. Alternatively, you could use SelectSaver:
my $ss = SelectSaver->new($XML);
which will re-select STDOUT when $ss goes out of scope.
> while(<FILE>)
> {
> print if $_ =~ />$/;
$_ is the default match, so
print if />$/;
> }
> close FILE;
If you use lexical filehandles, there's no need to explicitly close
files opened for reading. Files opened for writing should be explicitly
closed, and the return value of close checked, to catch errors writing
(such as a full disk). close will return an error if any of the writes
failed, so there's no need to check each print (unless you are expecting
errors and want to abort early).
close $XML or die "can't write to $file.xml: $!";
Ben
------------------------------
Date: Wed, 26 Mar 2008 13:31:24 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Pattern matching
Message-Id: <slrnfukggt.lve.hjp-usenet2@hrunkner.hjp.at>
On 2008-03-26 04:00, Deepan Perl XML Parser <deepan.17@gmail.com> wrote:
> On Mar 25, 7:13 pm, Lawrence Statton <yankeeinex...@gmail.com> wrote:
>> Deepan Perl XML Parser <deepan...@gmail.com> writes:
>>
>> > No i am writing my own XML parser.
>>
>> Don't. There are many good XML parsers out there, the world doesn't
>> need another one.
>
> Okay then can you name any parsers that would get the CDATA section?
Which one doesn't?
LibXML certainly does (I just tested it). I think expat does, too.
I have my doubts about the pure perl XML parser, but that has a lot of
other problems too and shouldn't be used.
hp
------------------------------
Date: Wed, 26 Mar 2008 04:28:33 -0700 (PDT)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Readline using foreach and while
Message-Id: <a6b64166-84c2-4f97-94b8-cd4e05389c78@i12g2000prf.googlegroups.com>
On Mar 25, 8:57 pm, "szr" <sz...@szromanMO.comVE> wrote:
> comp.llang.perl.moderated wrote:
> > On Mar 25, 1:57 pm, "szr" <sz...@szromanMO.comVE> wrote:
> >> John W. Krahn wrote:
> >>> Ben Bullock wrote:
> >>>> On Mar 25, 4:25 pm, Saurabh Jain <hundredr...@gmail.com> wrote:
> >>>>> Hi,
> >>>>> Is there any difference in reading a file using a while or a
> >>>>> foreach in perl?
>
> >>>> The foreach version seems to first read the whole of the file into
> >>>> an array, and then go through it line by line:
>
> >>> perldoc -q "What is the difference between a list and an array"
>
> >> Array is the variable type, List is the type of valve an Array
> >> takes/holds.
>
> > Actually, an array just holds scalars... or references which is a
> > special type of scalar.
>
> Isn't it more correct to say that an array holds a *list* of scalars? If
> so, then it seems what I originally said is correct; an *array's*
> *value* is a list, which contains scalars (numbers, strings, and refs.)
>
> That is, a scalar take a number, string, or ref. An array takes a list
> (which isa collection of scalars.) And by that token I suppose one could
> say a hash's value is an even numbered list (key => val pairs) of
> scalars :-)
>
A purely semantic case can be made that an array contains a list.
However, internally Perl's "list" as discussed in this thread is just
a stack where values are stored/retrieved for the very limited
lifetime of a particular statement.
So I think it'd mis-charactrize an array to say it holds a list in the
sense of a ephemeral stack of values since an array's contents live on
the heap.
--
Charles DeRykus
------------------------------
Date: Wed, 26 Mar 2008 12:43:35 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Readline using foreach and while
Message-Id: <n0tpb5-7l1.ln1@osiris.mauzo.dyndns.org>
Quoth "szr" <szrRE@szromanMO.comVE>:
> comp.llang.perl.moderated wrote:
> > On Mar 25, 1:57 pm, "szr" <sz...@szromanMO.comVE> wrote:
> >>
> >> Array is the variable type, List is the type of valve an Array
> >> takes/holds.
> >
> > Actually, an array just holds scalars... or references which is a
> > special type of scalar.
>
> Isn't it more correct to say that an array holds a *list* of scalars? If
> so, then it seems what I originally said is correct; an *array's*
> *value* is a list, which contains scalars (numbers, strings, and refs.)
Mo, it's not. For instance, an array can be spliced, which a list
can't.
Ben
------------------------------
Date: Wed, 26 Mar 2008 06:58:31 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Readline using foreach and while
Message-Id: <3480820e-42c5-406c-a0ed-c79dbb405eba@e60g2000hsh.googlegroups.com>
On Mar 26, 12:33=A0am, "szr" <sz...@szromanMO.comVE> wrote:
> Ben Morrow wrote:
> > Quoth Frank Seitz <devnull4...@web.de>:
> [...]
>
> >> use strict;
> >> use warnings;
>
> >> my @a =3D qw/a b c/;
> >> for my $v (@a) {
> >> =A0 =A0 push @a,'d' if $v eq 'c';
> >> =A0 =A0 print "$v\n";
> >> }
>
> > Good point. for is a little weird in this respect...
>
> Nothing really weird about it. In that case above, it's no different
> than:
>
> for (my $i=3D0; $i<@a; $i++) {
> =A0 =A0my $v =3D $a[$i];
> =A0 =A0push @a,'d' if $v eq 'c';
> =A0 =A0print "$v\n";
>
> }
>
> In either case, it's going over the array, one element at a time, in
> sequence, s oif you "push" something onto the end, it grows the array by
> one and thus the for look keeps going.
>
I think the 'weirdness' stems from the notion that 'for' supposedly
builds up a list prior to iterating over it, as opposed to 'while'
which (with respect to filehandles at least) does not. I'm not well-
versed enough to analyze the internals of how 'for' is implemented to
understand what exactly happens if LIST is simply a list, or an array,
or part of each, or if something gets appended, prepended, spliced to
an array that is part of LIST. Based on prior threads, it appears that
the behavior varies. Since the behavior is not really consistent (and
not really documented), it can validly be labeled as 'weird'.
------------------------------
Date: Wed, 26 Mar 2008 14:08:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Readline using foreach and while
Message-Id: <d02qb5-he2.ln1@osiris.mauzo.dyndns.org>
Quoth "szr" <szrRE@szromanMO.comVE>:
> Ben Morrow wrote:
> > Quoth Frank Seitz <devnull4711@web.de>:
> >>
> >> my @a = qw/a b c/;
> >> for my $v (@a) {
> >> push @a,'d' if $v eq 'c';
> >> print "$v\n";
> >> }
> >
> > Good point. for is a little weird in this respect...
>
> Nothing really weird about it. In that case above, it's no different
> than:
>
> for (my $i=0; $i<@a; $i++) {
> my $v = $a[$i];
> push @a,'d' if $v eq 'c';
> print "$v\n";
> }
It is, though. It only works if the LIST given to for is a single array:
my @ary = qw/a b c/;
for (@ary, ()) {
push @ary, 'd' if /c/;
print;
}
__END__
a
b
c
and map doesn't work like that at all
my @ary = qw/a b c/;
map {
push @ary, 'd' if /c/;
print;
} @ary;
__END__
a
b
c
and nor do sub calls. I suspect it's actually a bug: some sort of
optimization that's leaking out, and is now of course unfixable.
Ben
------------------------------
Date: Wed, 26 Mar 2008 07:19:12 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Readline using foreach and while
Message-Id: <fsdm100s2g@news2.newsguy.com>
nolo contendere wrote:
> On Mar 26, 12:33 am, "szr" <sz...@szromanMO.comVE> wrote:
>> Ben Morrow wrote:
>>> Quoth Frank Seitz <devnull4...@web.de>:
>> [...]
>>
>>>> use strict;
>>>> use warnings;
>>
>>>> my @a = qw/a b c/;
>>>> for my $v (@a) {
>>>> push @a,'d' if $v eq 'c';
>>>> print "$v\n";
>>>> }
>>
>>> Good point. for is a little weird in this respect...
>>
>> Nothing really weird about it. In that case above, it's no different
>> than:
>>
>> for (my $i=0; $i<@a; $i++) {
>> my $v = $a[$i];
>> push @a,'d' if $v eq 'c';
>> print "$v\n";
>>
>> }
>>
>> In either case, it's going over the array, one element at a time, in
>> sequence, s oif you "push" something onto the end, it grows the
>> array by one and thus the for look keeps going.
>>
>
> I think the 'weirdness' stems from the notion that 'for' supposedly
> builds up a list prior to iterating over it,
Exactly. It builds a list, when necessary (like when you
use for (<FH>) { ... } ), unless it's alreayd there ( like
with for my $element (@array) { ... } ) and /THEN/ iterates over it.
It just keeps going until the list is expended. Adding to the array like
in the quoted examples above makes the list longer and hence the extra
iteration (since the length of the list is checked each time through the
loop.)
--
szr
------------------------------
Date: Wed, 26 Mar 2008 07:23:23 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Readline using foreach and while
Message-Id: <fsdm8r0sfe@news2.newsguy.com>
comp.llang.perl.moderated wrote:
> On Mar 25, 8:57 pm, "szr" <sz...@szromanMO.comVE> wrote:
>> comp.llang.perl.moderated wrote:
>>> On Mar 25, 1:57 pm, "szr" <sz...@szromanMO.comVE> wrote:
>>>> John W. Krahn wrote:
>>>>> Ben Bullock wrote:
>>>>>> On Mar 25, 4:25 pm, Saurabh Jain <hundredr...@gmail.com> wrote:
>>>>>>> Hi,
>>>>>>> Is there any difference in reading a file using a while or a
>>>>>>> foreach in perl?
>>
>>>>>> The foreach version seems to first read the whole of the file
>>>>>> into an array, and then go through it line by line:
>>
>>>>> perldoc -q "What is the difference between a list and an array"
>>
>>>> Array is the variable type, List is the type of valve an Array
>>>> takes/holds.
>>
>>> Actually, an array just holds scalars... or references which is a
>>> special type of scalar.
>>
>> Isn't it more correct to say that an array holds a *list* of
>> scalars? If so, then it seems what I originally said is correct; an
>> *array's* *value* is a list, which contains scalars (numbers,
>> strings, and refs.)
>>
>> That is, a scalar take a number, string, or ref. An array takes a
>> list (which isa collection of scalars.) And by that token I suppose
>> one could say a hash's value is an even numbered list (key => val
>> pairs) of scalars :-)
>>
>
> A purely semantic case can be made that an array contains a list.
> However, internally Perl's "list" as discussed in this thread is just
> a stack where values are stored/retrieved for the very limited
> lifetime of a particular statement.
> So I think it'd mis-charactrize an array to say it holds a list in the
> sense of a ephemeral stack of values since an array's contents live on
> the heap.
Well, yes and no. If you want to talk about the internal inner workings,
yes it all lives on the heap somewhere.
However, at the surface, an array's *literal* value is a List, is it
not, just as a scalar's literal values can be 123 & "abc" ?
--
szr
------------------------------
Date: Wed, 26 Mar 2008 07:27:41 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Readline using foreach and while
Message-Id: <0a5e8100-4001-45dd-a628-85eb0024b39d@a70g2000hsh.googlegroups.com>
On Mar 26, 10:19=A0am, "szr" <sz...@szromanMO.comVE> wrote:
> nolo contendere wrote:
> > On Mar 26, 12:33 am, "szr" <sz...@szromanMO.comVE> wrote:
> >> Ben Morrow wrote:
> >>> Quoth Frank Seitz <devnull4...@web.de>:
> >> [...]
>
> >>>> use strict;
> >>>> use warnings;
>
> >>>> my @a =3D qw/a b c/;
> >>>> for my $v (@a) {
> >>>> push @a,'d' if $v eq 'c';
> >>>> print "$v\n";
> >>>> }
>
> >>> Good point. for is a little weird in this respect...
>
> >> Nothing really weird about it. In that case above, it's no different
> >> than:
>
> >> for (my $i=3D0; $i<@a; $i++) {
> >> my $v =3D $a[$i];
> >> push @a,'d' if $v eq 'c';
> >> print "$v\n";
>
> >> }
>
> >> In either case, it's going over the array, one element at a time, in
> >> sequence, s oif you "push" something onto the end, it grows the
> >> array by one and thus the for look keeps going.
>
> > I think the 'weirdness' stems from the notion that 'for' supposedly
> > builds up a list prior to iterating over it,
>
> Exactly. It builds a list, when necessary (like when you
> use =A0 for (<FH>) { ... } =A0 ), unless it's alreayd there ( like
> with =A0 for my $element (@array) { ... } =A0 ) and /THEN/ iterates over i=
t.
>
> It just keeps going until the list is expended. Adding to the array like
> in the quoted examples above makes the list longer and hence the extra
> iteration (since the length of the list is checked each time through the
> loop.)
>
Provably untrue. See Ben's example. I'll restate the concept below.
my @ary =3D qw/a b c/;
# for (@ary, ()) {
# for ( (), @ary ) {
for ( @ary ) {
push @ary, 'd' if /c/;
print;
}
=2E..
only the uncommented 'for' line prints a 'd' at the end. so what you
say MAY be true if LIST is ONLY an array.
------------------------------
Date: Wed, 26 Mar 2008 02:59:06 -0700 (PDT)
From: rroo <rroo@mail.com>
Subject: unwanted leading whitespace when using print
Message-Id: <83bb795d-cd27-4f9d-ad5d-b430da9f6dd3@i29g2000prf.googlegroups.com>
The following bit of code adds unwanted whitespace at the beginning of
some lines. It looks like the /n in the added text is not interpret
correctly. Using komodo debugger I cannot pinpoint the problem. The
generic array is filled correctly, only after the print the output is
incorrect.
See code and output:
<begin code>
my @generic;
my @allGeneric;
# read some lines from file, no specific mark up
# store matching lines in @genreric
FH = open "<", "Some file.txt";
while (<FH>)
{
if ($line =~ /some match/)
{
push (@generic, $line);
}
}
close FH;
#add some trailing text
#remove first element since it si always empty due to push
push (@generic, "\nSee some place: \n");
splice (@generic, 0,1);
push (@allGeneric,"*"x80 . "\n");
push (@allGeneric,@generic);
print "The system folder is ...\n\n";
print "===== Generic actions =====\n";
print "@allGeneric\n";
<end code>
This produces:
<begin output>
The system folder is ...
===== Generic actions =====
********************************************************************************
Ja, we hebben hier een heleboel werk om alles goed te krijgen met
allerlei linefeeds en line dingetjes waar ik niet zo'n goed zicht op
heb in perl gebruik. Daarom is het af en toe ook wel lastig, maar toch
ook wel (heel) erg vaak.
En soms: treedt er een 'panic' of "dubbele quote" op, maar mag dat?
See some place:
<end output>
Note the leading whitespace before 'Ja, ' and before 'En soms'.
Any help?
( I am using
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
(with 7 registered patches, see perl -V for more detail)
Copyright 1987-2005, Larry Wall
Binary build 813 [148120] provided by ActiveState http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun 6 2005 13:36:37
)
------------------------------
Date: Wed, 26 Mar 2008 03:10:45 -0700 (PDT)
From: rroo <rroo@mail.com>
Subject: Re: unwanted leading whitespace when using print
Message-Id: <b19d0021-e3e6-444c-b894-807f703af3b5@s13g2000prd.googlegroups.com>
On Mar 26, 10:59 am, rroo <r...@mail.com> wrote:
> The following bit of code adds unwanted whitespace at the beginning of
> some lines. It looks like the /n in the added text is not interpret
> correctly. Using komodo debugger I cannot pinpoint the problem. The
> generic array is filled correctly, only after the print the output is
> incorrect.
> See code and output:
> <begin code>
> my @generic;
> my @allGeneric;
>
> # read some lines from file, no specific mark up
> # store matching lines in @genreric
> FH = open "<", "Some file.txt";
>
> while (<FH>)
> {
> if ($line =~ /some match/)
> {
> push (@generic, $line);
> }}
>
> close FH;
>
> #add some trailing text
> #remove first element since it si always empty due to push
>
> push (@generic, "\nSee some place: \n");
> splice (@generic, 0,1);
> push (@allGeneric,"*"x80 . "\n");
> push (@allGeneric,@generic);
>
> print "The system folder is ...\n\n";
> print "===== Generic actions =====\n";
> print "@allGeneric\n";
> <end code>
>
> This produces:
> <begin output>
> The system folder is ...
>
> ===== Generic actions =====
> ********************************************************************************
> Ja, we hebben hier een heleboel werk om alles goed te krijgen met
> allerlei linefeeds en line dingetjes waar ik niet zo'n goed zicht op
> heb in perl gebruik. Daarom is het af en toe ook wel lastig, maar toch
> ook wel (heel) erg vaak.
>
> En soms: treedt er een 'panic' of "dubbele quote" op, maar mag dat?
>
> See some place:
>
> <end output>
>
> Note the leading whitespace before 'Ja, ' and before 'En soms'.
>
> Any help?
> ( I am using
> This is perl, v5.8.7 built for MSWin32-x86-multi-thread
> (with 7 registered patches, see perl -V for more detail)
>
> Copyright 1987-2005, Larry Wall
>
> Binary build 813 [148120] provided by ActiveStatehttp://www.ActiveState.com
> ActiveState is a division of Sophos.
> Built Jun 6 2005 13:36:37
> )
Oops, I just read FAQ 5.39 :-)
------------------------------
Date: Wed, 26 Mar 2008 08:32:19 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: What's better than Template Toolkit?
Message-Id: <87skyendoc.fsf@zeekat.nl>
fishfry <BLOCKSPAMfishfry@your-mailbox.com> writes:
> I'm starting a little project. I've used TT for the front end before,
> but it has some limitations and quirks as I'm sure people know. I was
> wondering if anyone can recommend a better templating package.
This is probably controversial, but I really don't see the point of
template-specific languages unless they're a superset of the "real"
language for most purposes.
Hence,
http://search.cpan.org/~jdiepen/Text-PSP-1.013/lib/Text/PSP.pm
But there are others.
YMMV,
Joost.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Wed, 26 Mar 2008 06:09:14 -0700 (PDT)
From: LesleyB <lesley.binks@googlemail.com>
Subject: Re: What's better than Template Toolkit?
Message-Id: <e852eebd-530f-4344-a4e7-3119e7503e88@s13g2000prd.googlegroups.com>
On 26 Mar, 05:38, fishfry <BLOCKSPAMfish...@your-mailbox.com> wrote:
> I'm starting a little project. I've used TT for the front end before,
> but it has some limitations and quirks as I'm sure people know. I was
> wondering if anyone can recommend a better templating package.
I've used HTML::Template, Template::Toolkit and am also looking at
mod_perl and Mason but I doubt the latter are what you seek.
Mason seems to be what I want but it seems to be meant for large
sites. Apart from the 'using a sledgehammer to crack a nut' is there
any harm in using it for small projects?
I found Template::Toolkit okay for small projects if a bit quirky.
Regards
L.
------------------------------
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 V11 Issue 1394
***************************************