[30426] in Perl-Users-Digest
Perl-Users Digest, Issue: 1669 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 23 18:14:29 2008
Date: Mon, 23 Jun 2008 15:14:20 -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 Mon, 23 Jun 2008 Volume: 11 Number: 1669
Today's topics:
I hate CGI.pm <benkasminbullock@gmail.com>
Re: I hate CGI.pm <baxter.brad@gmail.com>
Re: I hate CGI.pm <noreply@gunnar.cc>
Re: I hate CGI.pm <wahab@chemie.uni-halle.de>
Re: I hate CGI.pm <brian.d.foy@gmail.com>
Re: I hate CGI.pm <rkb@i.frys.com>
Re: I hate CGI.pm xhoster@gmail.com
Re: I hate CGI.pm <usenet@davidfilmer.com>
Re: I hate CGI.pm <cartercc@gmail.com>
Re: I hate CGI.pm <szrRE@szromanMO.comVE>
Re: I hate CGI.pm <tzz@lifelogs.com>
Re: Perl Script <tzz@lifelogs.com>
Re: Print Spanish characters in Perl? <RedGrittyBrick@SpamWeary.foo>
Re: Printing Problems <MSwanberg@gmail.com>
Problem expanding filenames in loop <hjrrs@yahoo.com>
Re: Problem expanding filenames in loop <someone@example.com>
Re: Problem expanding filenames in loop xhoster@gmail.com
Re: Problem expanding filenames in loop <ben@morrow.me.uk>
Re: Problem expanding filenames in loop <hjrrs@yahoo.com>
Re: Ripping out parts of a DOM using XML::XSLT <MSwanberg@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 23 Jun 2008 13:20:54 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: I hate CGI.pm
Message-Id: <g3o7vm$4m7$1@ml.accsnet.ne.jp>
Today I wanted to write a web interface for something, and I opted to
use CGI.pm. It's a core module, something distributed with Perl, and
yet it's painful to use. I started out using CGI.pm a few years ago
when I knew next to no Perl, and at the time I blamed myself for the
module's unuseability. Since then I've been learning more and more
Perl, and yet coming back to CGI.pm I find that it's just as unuseable
to me now as it was then. Some of its behaviours are just stupid and
extremely annoying.
What do other people think of it? Am I a lone CGI.pm hater, or do
other people use some superior system instead of CGI.pm?
I tried to read the documentation for Catalyst, and it makes no sense
to me - it looks like you have to buy a book and spend hours and hours
to understand it. Since I don't usually even write web things, I don't
want to spend a lot of time studying the systems - I just want a
"better CGI module". Does it exist?
------------------------------
Date: Mon, 23 Jun 2008 07:00:12 -0700 (PDT)
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: I hate CGI.pm
Message-Id: <95d16de1-79bc-4126-81f4-26b08fa3914d@8g2000hse.googlegroups.com>
On Jun 23, 9:20 am, Ben Bullock <benkasminbull...@gmail.com> wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use. I started out using CGI.pm a few years ago
> when I knew next to no Perl, and at the time I blamed myself for the
> module's unuseability. Since then I've been learning more and more
> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
> to me now as it was then. Some of its behaviours are just stupid and
> extremely annoying.
>
> What do other people think of it? Am I a lone CGI.pm hater, or do
> other people use some superior system instead of CGI.pm?
>
> I tried to read the documentation for Catalyst, and it makes no sense
> to me - it looks like you have to buy a book and spend hours and hours
> to understand it. Since I don't usually even write web things, I don't
> want to spend a lot of time studying the systems - I just want a
> "better CGI module". Does it exist?
I've had good success with CGI:Minimal. http://search.cpan.org/dist/CGI-Minimal/
You have to bake your own cookies.
--
Brad
------------------------------
Date: Mon, 23 Jun 2008 16:02:53 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I hate CGI.pm
Message-Id: <6c9oolF3gfp1eU1@mid.individual.net>
Ben Bullock wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use. I started out using CGI.pm a few years ago
> when I knew next to no Perl, and at the time I blamed myself for the
> module's unuseability. Since then I've been learning more and more
> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
> to me now as it was then. Some of its behaviours are just stupid and
> extremely annoying.
>
> What do other people think of it? Am I a lone CGI.pm hater, or do
> other people use some superior system instead of CGI.pm?
>
> I tried to read the documentation for Catalyst, and it makes no sense
> to me - it looks like you have to buy a book and spend hours and hours
> to understand it. Since I don't usually even write web things, I don't
> want to spend a lot of time studying the systems - I just want a
> "better CGI module". Does it exist?
It depends on what you mean by "painful", "unusable", "stupid",
"annoying" and "better".
Personally I tend to avoid CGI.pm because it's slow. As regards parsing
form data, there are several alternative modules available, e.g.
CGI::Lite and CGI::Minimal.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 23 Jun 2008 16:31:00 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: I hate CGI.pm
Message-Id: <g3oc34$t29$1@nserver.hrz.tu-freiberg.de>
Ben Bullock wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use. I started out using CGI.pm a few years ago
> when I knew next to no Perl, and at the time I blamed myself for the
> module's unuseability. Since then I've been learning more and more
> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
> to me now as it was then. Some of its behaviours are just stupid and
> extremely annoying.
>
> What do other people think of it? Am I a lone CGI.pm hater, or do
> other people use some superior system instead of CGI.pm?
>
> I tried to read the documentation for Catalyst, and it makes no sense
> to me - it looks like you have to buy a book and spend hours and hours
> to understand it. Since I don't usually even write web things, I don't
> want to spend a lot of time studying the systems - I just want a
> "better CGI module". Does it exist?
Hi Ben,
I almost always use HTML::Template and use CGI
only sometimes for POST/GET parameter extraction
and url encoding (seems to work). I tend to give
the html-template exactly the same name as the
corresponding Perl script and change the extension
to htm (by convention: .htm is template, .html
is static content).
If HTML::Template doesn't fit, I use HTML::Mason
(but that's only on somehow complicated things).
Regards
M.
------------------------------
Date: Mon, 23 Jun 2008 10:41:43 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: I hate CGI.pm
Message-Id: <230620081041433707%brian.d.foy@gmail.com>
In article <g3o7vm$4m7$1@ml.accsnet.ne.jp>, Ben Bullock
<benkasminbullock@gmail.com> wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use.
I think you'd need to define "painful to use". What was painful? What
did you have trouble doing?
------------------------------
Date: Mon, 23 Jun 2008 09:11:02 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: I hate CGI.pm
Message-Id: <223d8377-6def-41e0-a4a5-76b7ead1c041@s21g2000prm.googlegroups.com>
On Jun 23, 6:20 am, Ben Bullock <benkasminbull...@gmail.com> wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use. I started out using CGI.pm a few years ago
> when I knew next to no Perl, and at the time I blamed myself for the
> module's unuseability. Since then I've been learning more and more
> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
> to me now as it was then. Some of its behaviours are just stupid and
> extremely annoying.
>
> What do other people think of it? Am I a lone CGI.pm hater, or do
> other people use some superior system instead of CGI.pm?
>
I think CGI.pm is an excellent module and fairly easy to use once you
thoroughly read the documentation. However, it's not perfect, but
then nothing is ever perfect.
If you truly believe that it's that bad, why don't you write/publish
your own version, rather than simply complaining without specific
details and examples.
------------------------------
Date: 23 Jun 2008 16:26:27 GMT
From: xhoster@gmail.com
Subject: Re: I hate CGI.pm
Message-Id: <20080623122628.590$tP@newsreader.com>
Ben Bullock <benkasminbullock@gmail.com> wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use. I started out using CGI.pm a few years ago
> when I knew next to no Perl, and at the time I blamed myself for the
> module's unuseability. Since then I've been learning more and more
> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
> to me now as it was then. Some of its behaviours are just stupid and
> extremely annoying.
>
> What do other people think of it? Am I a lone CGI.pm hater, or do
> other people use some superior system instead of CGI.pm?
I like CGI.pm. I have been frustrated with it at times, but that
frustration was usually resolved when I tried to do the same thing myself
and thus discovered the subtleties involved, and then appreciated why CGIs
needlessly complicated approach wasn't so needless after all.
> I tried to read the documentation for Catalyst, and it makes no sense
> to me - it looks like you have to buy a book and spend hours and hours
> to understand it. Since I don't usually even write web things, I don't
> want to spend a lot of time studying the systems - I just want a
> "better CGI module". Does it exist?
Have you looked at CGI::Lite? I didn't consider it better last I looked at
it, but YMMV.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 23 Jun 2008 09:52:23 -0700
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: I hate CGI.pm
Message-Id: <brudneRbPtQ8ScLVRVn_vwA@giganews.com>
Ben Bullock wrote:
> I hate CGI.pm
I hate php. I hate it when I must try to understand or modify someone's
php code. But the main source of my dislike is that I don't know php
very well at all. It's easy to be frustrated by something I don't
understand.
I really like CGI.pm, but there was a definite learning curve for me to
understand it (and I was frustrated when I was on the flat part of the
curve). It was worth the effort. I also bought the book (by Lincoln
Stein) which was helpful.
I use HTML::Template for all my webby stuff, but I write Perl programs
(using CGI.pm) to create the templates. Really.
--
David Filmer (http://DavidFilmer.com)
The best way to get a good answer is to ask a good question.
------------------------------
Date: Mon, 23 Jun 2008 10:01:27 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: I hate CGI.pm
Message-Id: <b8d331bc-15ef-4750-aebb-2011f91e43b7@p25g2000hsf.googlegroups.com>
On Jun 23, 9:20 am, Ben Bullock <benkasminbull...@gmail.com> wrote:
> What do other people think of it? Am I a lone CGI.pm hater, or do
> other people use some superior system instead of CGI.pm?
> want to spend a lot of time studying the systems - I just want a
> "better CGI module". Does it exist?
I've been using Perl for about ten years for web programming. I took
one look at CGI and decided to 'roll my own.' I use CGI to pass
parameters from forms to scripts, but the big module that I find
absolutely essential is DBI.
When I develop a web project, I first start by building a module for
database connectivity and HTML components (like the header, footer,
buttons, menus, and so on.) I then build scripts that encapsulate
functionality depending on the data. A very rough sample of pseudo
code follows.
I initialize my variables and then use heredocs to spit out HTML. To
me, this is more intuitive than using any kind of includes tags, like
JSP, PHP, ColdFusion, Catlyst, etc.) You can use the http header of
the requested URL as a key into your database to dynamically generate
pages depending on the user input. Essentially, you are writing a
program to write a program to generate a website.
This is what I mean:
use strict;
use CGI;
use DBI;
use myHTMLmodule;
#passed in from an HTML form or from this script
my $what = param('what');
my $name = param('name');
my $number = param('number');
my $answer = param('answer');
#generate dynamic page based on content drawn from database
myHTMLmodule::header;
myHTMLmodule::menu;
&step_1 if $what eq 'Click Here';
&step_2 if $what eq 'Got Name';
&step_3 if $what eq 'Got Number';
&step_4 if($what eq 'Ask Question';
&error if $what eq '';
myHTMLmodule::return_home;
myHTMLmodule::footer;
sub step_1
{
print <<step1
<p>You want to $what</p>
<ul>
step1
my @results = myHTMLmodule::return_query_results($what);
foreach my $result (@results) { print "<li>$result</li>"; }
print <<step1
</ul>
<p>This is the remainder of step 1:</p>
<!-- HTML -->
step1
}
step2, step3, step4, and error similar
------------------------------
Date: Mon, 23 Jun 2008 11:06:35 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: I hate CGI.pm
Message-Id: <g3oonc0otg@news4.newsguy.com>
Ben Bullock wrote:
> Today I wanted to write a web interface for something, and I opted to
> use CGI.pm. It's a core module, something distributed with Perl, and
> yet it's painful to use. I started out using CGI.pm a few years ago
> when I knew next to no Perl, and at the time I blamed myself for the
> module's unuseability. Since then I've been learning more and more
> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
> to me now as it was then. Some of its behaviours are just stupid and
> extremely annoying.
Could you be kind enough to provide an example or two where CGI.pm
didn't work well for you? Everyone can have a different experience so it
might help to know where you're coming from via illustration :-)
Also please see my reply to your posting in the related FAQ thread.
--
szr
------------------------------
Date: Mon, 23 Jun 2008 14:38:59 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: I hate CGI.pm
Message-Id: <86ve00osa4.fsf@lifelogs.com>
On Mon, 23 Jun 2008 13:20:54 +0000 (UTC) Ben Bullock <benkasminbullock@gmail.com> wrote:
BB> What do other people think of it? Am I a lone CGI.pm hater, or do
BB> other people use some superior system instead of CGI.pm?
mod_perl does most of the things I need (with Template Toolkit). For
quick tasks, I like CGI::FormBuilder. I don't hate CGI.pm, just haven't
found a compelling reason to use it instead of those two. A few times
I've had to import utility functions, but that's about it.
Ted
------------------------------
Date: Mon, 23 Jun 2008 16:04:58 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl Script
Message-Id: <8663rzooat.fsf@jumptrading.com>
On Fri, 20 Jun 2008 22:26:40 +0200 Martijn Lievaart <m@rtij.nl.invlalid> wrote:
ML> On Fri, 20 Jun 2008 11:34:01 -0500, Ted Zlatanov wrote:
ML> I agree with your reasoning, except it may introduce another risk.
>> If the ML> SSN is just used for an check, so you check it against a
>> known record, ML> OK, no problem. But if you use it as a search key,
>> there may be a hash ML> collision.
>>
>> SHA-1 is 160 bits vs. 128 for MD5, so using SHA-1 would definitely avoid
>> collisions. I'm 99% sure there's no MD5 collisions either for USA-style
>> SSNs, which are currently 9 decimal digits and thus will fit in 30 bits.
>> Even at 10 digits (which may happen some day), it's just 33 bits.
ML> The function of a cryptographic hash is that is is very, very difficult
ML> to come up with another document that hashes to the same document as the
ML> one you want to forge.
Well, yes, but also the Hamming distance should be optimized. Otherwise
the hash space can be searched with preference for the busier regions.
ML> But whether there are collisions in this particular key space? You cannot
ML> tell. You are 99% sure. So am I. But it doesn't matter if it's 99% or 1%,
ML> if it is not 100%, it's not usable as a search key.
OK, I tested it against all possible SSNs (in the NNNNNNNNN format in
ASCII, so really a 10-byte string). There were no MD5 collisions. I
didn't run it as a 4-byte packed binary format or anything else, it was
too boring :)
Ted
------------------------------
Date: Mon, 23 Jun 2008 15:22:27 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Print Spanish characters in Perl?
Message-Id: <485fb1a5$0$26080$db0fefd9@news.zen.co.uk>
Ted Zlatanov wrote:
> On Fri, 20 Jun 2008 15:27:25 GMT Jürgen Exner <jurgenex@hotmail.com> wrote:
>
> JE> Oh, now that you mention it, maybe the OP wasn't asking about how to
> JE> correctly print/display non-ASCII characters from his Perl program but
> JE> about how to enter them on his keyboard in the editor. Two very
> JE> different things.
> JE> The easiest way would be to switch the keyboard into Spanish mode. How
> JE> to do that depends on your OS.
> JE> If you have to type text in multiple different languages frequently you
> JE> might want to check out those keyboards that have little LCDs on the
> JE> keys, which change to actually match the national layout for the current
> JE> keyboard mode.
>
> As a follow up I wanted to mention my favorite tools for this.
>
> Yudit is a good Unicode editor that can do a lot of edge cases for
> input.
>
> Yet another way is to use Emacs with Quail. It lets you set up
> transliterated inputs; for example with quail-cyrillic-translit I can
> type `къща №5' with k ~ /t a /no 5
>
> There are equivalent methods for Western European inputs:
> latin1-alt-postfix for example has this table (from the docs):
>
> | postfix | examples
> ------------+---------+----------
> acute | ' | a' -> á
> grave | ` | a` -> à
> circumflex | ^ | a^ -> â
> diaeresis | \" | a\" -> ä
> tilde | ~ | a~ -> ã
> cedilla | / | c/ -> ç
> nordic | / | d/ -> ð t/ -> þ a/ -> å e/ -> æ o/ -> ø
> others | /<> | s/ -> ß ?/ -> ¿ !/ -> ¡
> | various | << -> « >> -> » o_ -> º a_ -> ª
>
> This is not directly related to Perl, but it's really hard (IMHO) to set
> up easy input of UCS characters in a consistent way across platforms, so
> inside Emacs Quail is a pretty good solution. I hope someone finds it
> useful.
>
In vim `:help digraphs`.
--
RGB
------------------------------
Date: Mon, 23 Jun 2008 12:16:21 -0700 (PDT)
From: MSwanberg <MSwanberg@gmail.com>
Subject: Re: Printing Problems
Message-Id: <c5b00c31-8a8d-472b-84d9-4686193e06d0@56g2000hsm.googlegroups.com>
On Jun 19, 5:14=A0am, dakin999 <akhils...@gmail.com> wrote:
> Hi,
>
> I have following code which works ok. It does following:
>
> 1. reads data from a input file
> 2. puts the data into seperate variables in a array
> 3. reads from this array and prints out to another file
>
> It works except that it prints the same record 4 times. I can see I
> have missed some thing in my array definition as their are 4 elements
> in array, it is printing 4 times each element and then moving to next
> element till it reaches eof().
>
> while (<input>) =A0#reading a line from file
> # Read the line into a set of variables
> =A0 =A0($1,$2,$3,$4)=3Dsplit(/,/,$_);
> ....
> ....
> # Buid an array with these varaibles
> =A0 =A0my @array =3D ([$1, $2, $3, $4]);
> =A0 =A0foreach my $r(@array) {
> =A0 =A0foreach (@$r){
>
> ... =A0 =A0 print <out> "$1\n";
> =A0 =A0 =A0 =A0print <out> "$2\n";
> =A0 =A0 =A0 =A0print <out> "$3\n";
> =A0 =A0 =A0 =A0print <out> "$4\n";
> =A0 =A0 =A0 =A0print <out> "\n";
>
> The out put is coming like this:
>
> yellow
> blue
> orange
> red
>
> yellow
> blue
> orange
> red
>
> yellow
> blue
> orange
> red
>
> yellow
> blue
> orange
> red
>
> black
> white
> red
> pink
>
> black
> white
> red
> pink
>
> black
> white
> red
> pink
>
> black
> white
> red
> pink
>
> Clearly it should just print one time and go to the next record....
>
> Please suggest.
Try simply:
print out "$var\n";
Having the brackets around out, such as
print <out>...
isn't the right way to print to the "out" filehandle.
As well, why do you have 2 loops? And why are you putting the
elements into an anonymous array, and then having that as the sole
element of the @array array? Couldn't you just simplify this entire
program as follows:
while (<input>) {
print join("\n",split(/,/,$_),"\n\n";
}
or even:
while (<input>) {
s/,/\n/g;
print "$_\n\n";
}
-Mike
------------------------------
Date: Mon, 23 Jun 2008 11:43:50 -0700 (PDT)
From: Hemant <hjrrs@yahoo.com>
Subject: Problem expanding filenames in loop
Message-Id: <2b25bd47-dfbd-4c89-8f9d-e8c09d343892@l64g2000hse.googlegroups.com>
Folks,
When I try to expand file name in a loop, perl fails to expand
everyother file.
Example:
#!/usr/bin/perl
#
@FileListArr = (
"Full-2008-06-16-23:29:40",
"Incr-2008-06-17-22:02:18",
"Incr-2008-06-18-22:02:23",
"Incr-2008-06-19-22:02:20",
"Incr-2008-06-20-22:02:38",
"Incr-2008-06-21-22:05:30",
"Incr-2008-06-22-22:05:26",
);
foreach $Volume (@FileListArr)
{
$File=glob("/backups/backupfiles/*/$Volume");
if (!defined $File)
{
print "File not found for $Volume\n";
}
else
{
print "$File\n";
}
}
The output of the script:
/backups/backupfiles/lidp11/Full-2008-06-16-23:29:40
File not found for Incr-2008-06-17-22:02:18
/backups/backupfiles/lidp11/Incr-2008-06-18-22:02:23
File not found for Incr-2008-06-19-22:02:20
/backups/backupfiles/lidp11/Incr-2008-06-20-22:02:38
File not found for Incr-2008-06-21-22:05:30
/backups/backupfiles/lidp11/Incr-2008-06-22-22:05:26
I also tried using "<>" keyword, but got same result. I tried similar
test to expand user's HOME directory (tilde expansion) and for same
result.
I tested it under perl 5.8.4 on AIX and perl 5.10.0 on linux.
------------------------------
Date: Mon, 23 Jun 2008 19:01:29 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Problem expanding filenames in loop
Message-Id: <dqS7k.871$yg7.72@edtnps82>
Hemant wrote:
> Folks,
>=20
> When I try to expand file name in a loop, perl fails to expand
> everyother file.
>=20
> Example:
>=20
> #!/usr/bin/perl
> #
>=20
> @FileListArr =3D (
> "Full-2008-06-16-23:29:40",
> "Incr-2008-06-17-22:02:18",
> "Incr-2008-06-18-22:02:23",
> "Incr-2008-06-19-22:02:20",
> "Incr-2008-06-20-22:02:38",
> "Incr-2008-06-21-22:05:30",
> "Incr-2008-06-22-22:05:26",
> );
>=20
> foreach $Volume (@FileListArr)
> {
> $File=3Dglob("/backups/backupfiles/*/$Volume");
> if (!defined $File)
> {
> print "File not found for $Volume\n";
> }
> else
> {
> print "$File\n";
> }
> }
>=20
>=20
> The output of the script:
>=20
> /backups/backupfiles/lidp11/Full-2008-06-16-23:29:40
> File not found for Incr-2008-06-17-22:02:18
> /backups/backupfiles/lidp11/Incr-2008-06-18-22:02:23
> File not found for Incr-2008-06-19-22:02:20
> /backups/backupfiles/lidp11/Incr-2008-06-20-22:02:38
> File not found for Incr-2008-06-21-22:05:30
> /backups/backupfiles/lidp11/Incr-2008-06-22-22:05:26
>=20
>=20
> I also tried using "<>" keyword, but got same result. I tried similar
> test to expand user's HOME directory (tilde expansion) and for same
> result.
>=20
> I tested it under perl 5.8.4 on AIX and perl 5.10.0 on linux.
From the perlop.pod man page:
perldoc perlop
[snip]
So if you=92re expecting a single value from a glob, it is much bett=
er
to say
($file) =3D <blurch*>;
than
$file =3D <blurch*>;
because the latter will alternate between returning a filename and
returning false.
So it's probably better to use something like this:
foreach my $File ( map glob("/backups/backupfiles/*/$_"), @FileListArr )
{
print "$File\n";
}
John
--=20
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: 23 Jun 2008 19:09:26 GMT
From: xhoster@gmail.com
Subject: Re: Problem expanding filenames in loop
Message-Id: <20080623150928.315$Rd@newsreader.com>
Hemant <hjrrs@yahoo.com> wrote:
> Folks,
>
> When I try to expand file name in a loop, perl fails to expand
> everyother file.
>
> Example:
>
...
>
> foreach $Volume (@FileListArr)
> {
> $File=glob("/backups/backupfiles/*/$Volume");
call it in a list context:
($File)=glob("/backups/backupfiles/*/$Volume");
In a scalar context, glob iterates through the expansions, returning
undef when done. The fact that $Volume has changed in the mean time
doesn't matter. Glob doesn't look for such changes until after it is done
iterating on the expansion is is currently working over. In your case,
if the expansion always expands to exactly one file, then you will
get this every other effect.
1) Notice the argument. Return the file.
2) Fail to notice the argument change. Return undef, to indicate no more
files for the previous argument.
3) Since its starting from empty, Notice the argument again. Return that
file.
etc.
From perldoc perlop:
A (file)glob evaluates its (embedded) argument only when it is starting a
new list. All values must be read before it will start over. In list
context, this isn't important because you automatically get them all
anyway.
In my experience, it is almost always a mistake to use glob in a scalar
context.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 23 Jun 2008 20:12:05 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem expanding filenames in loop
Message-Id: <5595j5-dfs.ln1@osiris.mauzo.dyndns.org>
Quoth Hemant <hjrrs@yahoo.com>:
>
> When I try to expand file name in a loop, perl fails to expand
> everyother file.
>
> Example:
>
> #!/usr/bin/perl
> #
use warnings;
use strict;
> @FileListArr = (
my @FileListArr = (
> "Full-2008-06-16-23:29:40",
> "Incr-2008-06-17-22:02:18",
> "Incr-2008-06-18-22:02:23",
> "Incr-2008-06-19-22:02:20",
> "Incr-2008-06-20-22:02:38",
> "Incr-2008-06-21-22:05:30",
> "Incr-2008-06-22-22:05:26",
> );
It is often more convenient to write a list like this as
my @FileListArr = qw(
Full-2008-06-16-23:29:40
Incr-2008-06-17-22:02:18
);
> foreach $Volume (@FileListArr)
foreach my $Volume (@FileListArr)
> {
> $File=glob("/backups/backupfiles/*/$Volume");
glob in scalar context doesn't do what you think. Once you've invoked it
once, it ignores its argument until it's returned all the possible
results and then undef. If you just want the first result, you need to
call it in list context like this:
my ($File) = glob(...);
where the parens around ($File) make this a list assignment (into a list
with only one value) rather than a scalar assignment.
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
ben@morrow.me.uk Groucho Marx
------------------------------
Date: Mon, 23 Jun 2008 12:48:30 -0700 (PDT)
From: Hemant <hjrrs@yahoo.com>
Subject: Re: Problem expanding filenames in loop
Message-Id: <6d119b1d-ab83-41a3-80b0-ce0f6e2b0b32@r66g2000hsg.googlegroups.com>
On Jun 23, 2:12 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Hemant <hj...@yahoo.com>:
>
>
>
> > When I try to expand file name in a loop, perl fails to expand
> > everyother file.
>
> > Example:
>
> > #!/usr/bin/perl
> > #
>
> use warnings;
> use strict;
>
> > @FileListArr = (
>
> my @FileListArr = (
>
> > "Full-2008-06-16-23:29:40",
> > "Incr-2008-06-17-22:02:18",
> > "Incr-2008-06-18-22:02:23",
> > "Incr-2008-06-19-22:02:20",
> > "Incr-2008-06-20-22:02:38",
> > "Incr-2008-06-21-22:05:30",
> > "Incr-2008-06-22-22:05:26",
> > );
>
> It is often more convenient to write a list like this as
>
> my @FileListArr = qw(
> Full-2008-06-16-23:29:40
> Incr-2008-06-17-22:02:18
> );
>
> > foreach $Volume (@FileListArr)
>
> foreach my $Volume (@FileListArr)
>
> > {
> > $File=glob("/backups/backupfiles/*/$Volume");
>
> glob in scalar context doesn't do what you think. Once you've invoked it
> once, it ignores its argument until it's returned all the possible
> results and then undef. If you just want the first result, you need to
> call it in list context like this:
>
> my ($File) = glob(...);
>
> where the parens around ($File) make this a list assignment (into a list
> with only one value) rather than a scalar assignment.
>
> Ben
>
> --
> Outside of a dog, a book is a man's best friend.
> Inside of a dog, it's too dark to read.
> b...@morrow.me.uk Groucho Marx
Thank you all for the quick replies.
------------------------------
Date: Mon, 23 Jun 2008 12:28:23 -0700 (PDT)
From: MSwanberg <MSwanberg@gmail.com>
Subject: Re: Ripping out parts of a DOM using XML::XSLT
Message-Id: <57a1c366-9cef-4bbe-b0f3-d45a2428da00@59g2000hsb.googlegroups.com>
On Jun 18, 4:04=A0am, NiallBCarter <NiallBCar...@googlemail.com> wrote:
> On Jun 18, 9:53 am, Bjoern Hoehrmann <bjo...@hoehrmann.de> wrote:
>
>
>
> > =A0 {'', 'kml'}
>
> > Which is a different tuple. Also, the root element in your document is
> > this kml element, while your template match attribute looks for a root
> > element called 'Document'. To get the names right you have to either
> > declare a namespace prefix and use it in your XPath expressions ala
>
> > =A0 /kml:kml/kml:Document/...
>
> > or use predicates with the namespace-uri() and local-name() functions:
>
> > =A0 /*[local-name() =3D 'kml' and namespace-uri() =3D 'http://...']/...
>
> So would I be right in saying that it is not as simple as I thought?
>
> > Do note that there are more sophisticated XML/XSLT/XPath modules on
> > CPAN, XML::LibXSLT for example.
>
> I am aware that there are more sophisticated modules but I experience
> troubles with each one I try. It was suggested that I stick to
> XML::XSLT for the moment and try to come up with a work around rather
> than have to hassle the IT staff to install more modules on the
> managed computer I work on.
>
> Essentially all I want to do is strip out the <kml>, <Document> parts
> and be left with a DOM containing <Placemark> and all contents </
> Placemark>
> Is there a simple way of doing this?
>
> rgds,
>
> Niall
Have you tried the DOM method "getElementsByTagName"?
You could also use some XQL to parse out only the elements you want to
see.
You will still have to manipulate the nodes manually (i.e. you won't
be using XSL like you want to), but it's not too tough to create a new
DOM Document and appendChild each node you step through.
-Mike
------------------------------
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 1669
***************************************