[32292] in Perl-Users-Digest
Perl-Users Digest, Issue: 3559 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 5 21:09:27 2011
Date: Mon, 5 Dec 2011 18:09:10 -0800 (PST)
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, 5 Dec 2011 Volume: 11 Number: 3559
Today's topics:
Re: Command invoked by backticks hangs, silently - bypa <nospam-abuse@ilyaz.org>
Re: Command invoked by backticks hangs, silently - bypa <jurgenex@hotmail.com>
Re: Command invoked by backticks hangs, silently - bypa <news@lawshouse.org>
Re: Command invoked by backticks hangs, silently - bypa <news@lawshouse.org>
Command invoked by backticks hangs, silently: how to di <news@lawshouse.org>
Re: Command invoked by backticks hangs, silently: how t <bjoern@hoehrmann.de>
Re: Command invoked by backticks hangs, silently: how t <jurgenex@hotmail.com>
Re: Command invoked by backticks hangs, silently: how t <ben@morrow.me.uk>
DBD::SQLite install with PPM, MD5 bootstrap parameter <cartercc@gmail.com>
Re: IO::Socket::INET hostname restrictions? <ben@morrow.me.uk>
Re: IO::Socket::INET hostname restrictions? <ben@morrow.me.uk>
Re: IO::Socket::INET hostname restrictions? <ben@morrow.me.uk>
Re: Problem configuring OS/2 for installing CPAN packag <lgrosenthal@invalid-invalid.com>
Re: Problem configuring OS/2 for installing CPAN packag <ben@morrow.me.uk>
simple xml - change tag name <fajfusio@wp.pl>
Re: simple xml - change tag name <news@lawshouse.org>
Re: simple xml - change tag name <willem@toad.stack.nl>
Re: simple xml - change tag name <ben@morrow.me.uk>
Re: simple xml - change tag name <news@lawshouse.org>
Re: simple xml - change tag name <willem@toad.stack.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 5 Dec 2011 11:23:55 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Command invoked by backticks hangs, silently - bypassed and also solved, sort of
Message-Id: <slrnjdpaea.g12.nospam-abuse@panda.math.berkeley.edu>
On 2011-12-05, Henry Law <news@lawshouse.org> wrote:
> Now the odd bit. Something one of you said made me wonder whether gzip
> had prompted for information and was waiting,
Me too...
> so I ran the original
> version with the backticks when it hung I entered a "Y" ... and off it
> went! I can't imagine what gzip was waiting for _half-way through_ a
> compress operation.
What made you think it is "half-way through"? I suspect it found the
*.gz file already present, and is asking you for a permission to overwrite...
Ilya
------------------------------
Date: Mon, 05 Dec 2011 17:26:57 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Command invoked by backticks hangs, silently - bypassed and also solved, sort of
Message-Id: <iorqd7t6s7l731mc4hrrhc2hqrkp5oan9t@4ax.com>
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid> wrote:
>In <G96dncJlBPUMPEHTnZ2dnUVZ8k2dnZ2d@giganews.com>, on 12/05/2011
> at 10:48 AM, Henry Law <news@lawshouse.org> said:
>
>>So anyone who finds themselves reading this in future remember: if
>>whatever you invoked via backticks talks to you, you won't see what
>>it says, and it will just wait for you to answer.
>
> `foo 2>bar`
>
>Will that capture the prompt?
I hope it doesn't. After all backticks are explicitely used to capture
any output of the called process.
If you don't want that behaviour but want to see the output on the
screen, then don't use backticks but system().
jue
------------------------------
Date: Mon, 05 Dec 2011 10:48:49 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Command invoked by backticks hangs, silently - bypassed and also solved, sort of
Message-Id: <G96dncJlBPUMPEHTnZ2dnUVZ8k2dnZ2d@giganews.com>
Useful replies from Björn, Jürgen and Ben; thank you all.
On 04/12/11 19:14, Bjoern Hoehrmann wrote:
> Anyway, your problem seems to be "gzip hangs" and those
> words seem to produce a fair number of results in my favourite search
> engine.
Mine too, I should have said that I'd done that. Actually the results
produced were quite specific to things other than my situation. (gzip
worked fine on the file on its own, and even when the file was submitted
as the only input to the application, rather than as part of the whole
mail tree).
> ... or I would replace the
> gzip call with one of the many Perl modules that implement gzip.
Well, in the end that's what I did: I'm well out of my comfort zone in
rebuilding modules with debugging information and attaching them to
running processes. IO::Compress::Gzip and its return code mechanism is
quite sufficient; and the application runs through to the end.
Now the odd bit. Something one of you said made me wonder whether gzip
had prompted for information and was waiting, so I ran the original
version with the backticks when it hung I entered a "Y" ... and off it
went! I can't imagine what gzip was waiting for _half-way through_ a
compress operation.
So anyone who finds themselves reading this in future remember: if
whatever you invoked via backticks talks to you, you won't see what it
says, and it will just wait for you to answer.
--
Henry Law Manchester, England
------------------------------
Date: Mon, 05 Dec 2011 11:48:21 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Command invoked by backticks hangs, silently - bypassed and also solved, sort of
Message-Id: <_NmdnUBED5YbMkHTnZ2dnUVZ8qKdnZ2d@giganews.com>
On 05/12/11 11:23, Ilya Zakharevich wrote:
> What made you think it is "half-way through"? I suspect it found the
> *.gz file already present, and is asking you for a permission to overwrite...
Because, as I remember, I cleared everything down before running my
tests. But maybe not, since it's the best hypothesis for the observed facts.
Anyway, fixed now.
--
Henry Law Manchester, England
------------------------------
Date: Sun, 04 Dec 2011 18:58:39 +0000
From: Henry Law <news@lawshouse.org>
Subject: Command invoked by backticks hangs, silently: how to diagnose?
Message-Id: <pPudnYSU24N9X0bTnZ2dnUVZ8kudnZ2d@giganews.com>
(There is no way I can post a minimal runnable example for this: it
happens randomly with individual data files, which are large and
confidential, and not when they are processed individually by the
application. It's debugging advice I'm after)
I have an RYO application which archives mail from MBOX-format files.
It removes the lines of messages older than a certain date, writes the
rest to a temporary file, and then replaces the original with the
temporary, pruned, version.
Before deleting the original version it moves it to a backup directory
and compresses it using gzip (this is under Linux).
Nearly all the time it works flawlessly, but every so often the gzip
command hangs and never returns. It's not consuming CPU, and it's not
just slow: I've left it for an hour and more, monitoring the size of the
.gz file and it doesn't change.
The file which causes the hang is not always the same one if the overall
data tree has changed (e.g. today's mail tree rather than yesterday's),
but if I cancel the run and start it again with the same data it stops
at the same place.
Is there some diagnostic technique within Perl that would help me get to
the bottom of this? I'm quite prepared to find eventually that it's a
Linux problem, but he's not giving me _any_ help at all, just sitting
sulking!
Here's the code (cut down, and not runnable because of the subroutines)
sub cleanup_mailbox {
my ( $infile, $backup_directory, $batch_id ) = @_;
my ( $infilename, undef, $suffix ) = fileparse($infile, qr/\.[^.]*/);
my $bak_file = "$backup_directory/$infilename-archived-$batch_id"
. ( $suffix ? "$suffix" : '');
move( $infile, $bak_file ) or
die logrec( 87, \%globals, SEVERE, $infile, $backup_directory, $! );
my $compressed = compress_file( $bak_file ) or
die logrec( 26, \%globals, UNRECOVERABLE, $bak_file, $@ );
# ...etc more code here
return;
}
sub compress_file {
my $file = shift;
my $rc = `gzip -v $file 2>&1`;
if ( $rc =~ /replaced with (.*)/ ){
return $1;
}
else {
$@ = $rc;
return;
}
}
--
Henry Law Manchester, England
------------------------------
Date: Sun, 04 Dec 2011 20:14:44 +0100
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Command invoked by backticks hangs, silently: how to diagnose?
Message-Id: <t8hnd7hioj0krk0s2fcvi76khrnbnvuga2@hive.bjoern.hoehrmann.de>
* Henry Law wrote in comp.lang.perl.misc:
>Nearly all the time it works flawlessly, but every so often the gzip
>command hangs and never returns. It's not consuming CPU, and it's not
>just slow: I've left it for an hour and more, monitoring the size of the
>.gz file and it doesn't change.
I note that the file system might be fooling you about that, Windows for
instance no longer updates the file size information while files are be-
ing written to. Anyway, your problem seems to be "gzip hangs" and those
words seem to produce a fair number of results in my favourite search
engine. I would either attach a debugger to the gzip process when it is
hanging and check what is doing or waiting for, or I would replace the
gzip call with one of the many Perl modules that implement gzip.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
------------------------------
Date: Sun, 04 Dec 2011 11:20:11 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Command invoked by backticks hangs, silently: how to diagnose?
Message-Id: <4uhnd7dhcq3n569jdnhpdjc4cik7qtde1g@4ax.com>
Henry Law <news@lawshouse.org> wrote:
>Nearly all the time it works flawlessly, but every so often the gzip
>command hangs and never returns.
You may want to take a look at
perldoc -q timeout
jue
------------------------------
Date: Sun, 04 Dec 2011 17:59:40 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Command invoked by backticks hangs, silently: how to diagnose?
Message-Id: <8aOdnQwX07nxlEHTnZ2dnUVZ8nCdnZ2d@bt.com>
Quoth Henry Law <news@lawshouse.org>:
> (There is no way I can post a minimal runnable example for this: it
> happens randomly with individual data files, which are large and
> confidential, and not when they are processed individually by the
> application. It's debugging advice I'm after)
>
> I have an RYO application which archives mail from MBOX-format files.
> It removes the lines of messages older than a certain date, writes the
> rest to a temporary file, and then replaces the original with the
> temporary, pruned, version.
>
> Before deleting the original version it moves it to a backup directory
> and compresses it using gzip (this is under Linux).
>
> Nearly all the time it works flawlessly, but every so often the gzip
> command hangs and never returns. It's not consuming CPU, and it's not
> just slow: I've left it for an hour and more, monitoring the size of the
> .gz file and it doesn't change.
Are any these files on NFS? Are they all in the same directory, and/or
the same filesystem? Have you got any sort of mandatory locking set up
(for instance, I believe on Linux Samba uses some sort of wait-for-me-to-
get-my-hands-off-this locks)?
> The file which causes the hang is not always the same one if the overall
> data tree has changed (e.g. today's mail tree rather than yesterday's),
> but if I cancel the run and start it again with the same data it stops
> at the same place.
What happens if you cancel a hung run and immediately run exactly the
gzip command which hung? Does it run to completion? Will the main app
then restart and finish without further problems?
> Is there some diagnostic technique within Perl that would help me get to
> the bottom of this? I'm quite prepared to find eventually that it's a
> Linux problem, but he's not giving me _any_ help at all, just sitting
> sulking!
Have you asked nicely? :)
I see someone else has mentioned attaching a C debugger to the gzip
process to see what it's doing; that's not a bad idea, but it can be
rather difficult to find out what's going on if you're not used to
debugging C programs, especially since your gzip probably isn't built
with debugging symbols. You could, of course, *build* a gzip (and
possibly a libc) with debugging symbols, but that's something of a last
resort.
A simpler but cruder way to see what's going on is to look at the
syscall interface. If gzip isn't using any CPU it must be stuck in a
syscall: which one? You can find that from the WCHAN or MWCHAN field in
ps. If you change the perl program to run all the gzip commands under
strace (I believe strace has an option to send the trace output to a
file?) you will be able to see what exactly gzip was trying to do when
it failed.
> sub compress_file {
> my $file = shift;
> my $rc = `gzip -v $file 2>&1`;
Have you tried running it with system, redirected to a file, rather than
using a pipe?
Have you tried using IO::Compress::Gzip instead? I realise it doesn't
give you the -v output, but you can just compare the before-and-after
file sizes instead.
Ben
------------------------------
Date: Mon, 5 Dec 2011 15:59:36 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: DBD::SQLite install with PPM, MD5 bootstrap parameter
Message-Id: <0fb7952e-6aed-46d9-a6f3-bd9141074792@q9g2000yqe.googlegroups.com>
Guys,
I've been trying most of the afternoon to get SQLite working with
Perl. I've got both Perl64 (on Windows 7) and SQLite going, but they
don't seem to communicate. DBI tells me that the SQLite DBD is
available but not installed. Yeah.
Using PPM, I get this message when I try to install DBD::SQLite---
Synchronizing Database ... done
DBD-SQLite marked for install
Installing package ...
Downloading DBD-SQLite-1.35 ... done
Unpacking DBD-SQLite-1.35 ... done
Generating HTML for DBD-SQLite-1.35 ... done
Updating files in site area ... failed
Installing package failed
ERROR: Digest::MD5 object version 2.51 does not match bootstrap
parameter 2.36_01
When I try to installDigest::MD5, I get this message---
DBD-SQLite unmarked for install
Digest-MD5 marked for install
Installing package ...
Downloading Digest-MD5-2.51 ... done
Unpacking Digest-MD5-2.51 ... done
Generating HTML for Digest-MD5-2.51 ... done
Updating files in site area ... failed
Installing package failed
ERROR: Attempt to reload Digest/MD5.pm aborted.
Compilation failed in require
I can't use CPAN because my network administrator absolutely forbids
both make and Mingw, so I seem to be stuck with PPM.
Any suggestions would be greatly appreciated.
Thanks, CC.
------------------------------
Date: Sun, 04 Dec 2011 08:55:02 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IO::Socket::INET hostname restrictions?
Message-Id: <m4ednQa8m8lbFEbTnZ2dnUVZ7qGdnZ2d@bt.com>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> I'm using a program called BWwhois that uses the code
>
> my $rs = IO::Socket::INET->new(
> PeerAddr => $w_host,
> PeerPort => $port,
> Proto => $protoname,
> Timeout => $g->{timeout},
> LocalAddr => $g->{LocalAddr}
> );
>
> This normally works; however, if the hostname[1] has a CNAME RR rather
> than an A RR it fails. I couldn't find anything in the documentation
> as to how the host name is resolved.
It's not documented in detail, no.
If you don't set MultiHomed, I:S::INET calls Socket::inet_aton, which
first calls C's inet_aton(3) and then calls gethostbyname(3) if that
fails. (If perl -V:d_inetaton doesn't say 'define' then perl uses its
own implementation of inet_aton(3), since it didn't find one on your
system it could use.) Does your system's gethostbyname(3) work properly?
> Is this an oversight, or is the caller expected to look up the
> hostname in A DNS server and replace it if it finds a CNAME RR?
It works for me, here (FreeBSD). What does
perl -MSocket -E'say inet_ntoa inet_aton "www.google.com"'
(adjust quotes as necessary) say for you? If Perl's inet_aton is working
as designed it ought to properly resolve the CNAME.
Ben
------------------------------
Date: Mon, 05 Dec 2011 07:53:17 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IO::Socket::INET hostname restrictions?
Message-Id: <6P6dnRQcZp1QUUHTnZ2dnUVZ8rOdnZ2d@bt.com>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> In <m4ednQa8m8lbFEbTnZ2dnUVZ7qGdnZ2d@bt.com>, on 12/04/2011
> at 08:55 AM, Ben Morrow <ben@morrow.me.uk> said:
>
> Does your system's gethostbyname(3) work properly?
>
> AFAIK, but I can run some tests.
>
> > perl -MSocket -E'say inet_ntoa inet_aton "www.google.com"'
>
> Can't find string terminator "'" anywhere before EOF at -e line 1.
You need to change the quotes, then. I don't know how OS/2 does quoting:
everything after the -E should be passed to perl as a single argument.
Try
perl -MSocket -E"say inet_ntoa inet_aton 'www.google.com'"
or put this in a file and run it through perl:
use 5.010;
use Socket;
say inet_ntoa inet_aton "www.google.com";
Ben
------------------------------
Date: Mon, 05 Dec 2011 19:44:22 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IO::Socket::INET hostname restrictions?
Message-Id: <Nf-dnZw65uvr7kDTnZ2dnUVZ8tydnZ2d@bt.com>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
>
> So why does IO::Socket::INET fail?
>
> IO::Socket::INET->new(
> PeerAddr => whois.nic.mn,
> PeerPort => 43,
> Proto => tcp,
> Timeout => 60,
> LocalAddr => )
> errno 22: Invalid argument
> host whois.nic.mn not found
> 22
> IO::Socket::INET: connect: Invalid argument
*Interesting*. I believe there's at least one bug here, in IO::Socket,
but it's not entirely clear.
First, the workaround: don't use Timeout. Find some other way of timing
out the operation, like alarm(). The CNAMEs are a red herring: what
matters is that that machine doesn't accept connections on port 43. The
'Invalid argument' is just the wrong error: without Timeout, you should
see 'Connection refused', which is the right answer.
[You don't need to read the rest unless you're interested...]
That ->new call gives me exactly the same result as you: EINVAL from
connect(). Since I didn't think connect(2) was even *able* to return
EINVAL, I ran it under ktrace: this showed two calls to connect. The
first failed with EINPROGRESS, the second with EINVAL. Retrying without
Timeout consistently gave 'Connection refused' instead.
Looking at the source of IO::Socket, the logic if Timeout is specified
is approximately
set non-blocking mode on the socket
try to connect
if connect fails with EINPROGRESS
select(2) for write, with the given timeout
if the select doesn't time out
retry the connect
if that connect succeeds, return success
if it failed with EISCONN, or we are on Win32 and it failed
with WSAEINVAL, return *success*
otherwise, return the error from the second connect
The EISCONN case is the strange one. There is a comment
# Some systems refuse to re-connect() to
# an already open socket and set errno to EISCONN.
# Windows sets errno to WSAEINVAL (10022)
and it turns out that it's not just Win32 that returns EINVAL in that
case, it's at least current versions of FreeBSD and, presumably, OS/2 as
well. However, even given that, returning success is *completely wrong*.
The sequence of events is
- app calls connect(2) on a non-blocking socket
- connect(2) fails with EINPROGRESS
- app calls select(2)-for-write
- some time later, a RST packet comes in
- select(2) returns socket as ready
- app calls connect(2) again
- connect(2) fails with EISCONN/EINVAL
The EISCONN/EINVAL error is saying 'this socket isn't fit to be reused':
it doesn't tell you *anything* about whether the second connection
attempt succeeded or failed. (In fact, you get the same EINVAL if you
attempt to re-connect a TCP socket while it's in TIME_WAIT state after a
successful close.)
Looking about a bit, I found http://cr.yp.to/docs/connect.html, which
mentions this connect-twice strategy as a way of performing a non-
blocking connect and still getting the correct error. It also says that
it doesn't always work, and that you should use getpeername instead (and
for all djb's... um... charm, he's usually right about things like
this). So, I think this counts as a bug in IO::Socket, since there are
common situations on common operating systems where it doesn't work
properly.
[Oddly, it looks from the CVS log as though FreeBSD used to return
EISCONN in this situation, as the IO::Socket code was kind-of expecting,
but it was changed to EINVAL in 2006. It's not clear to me why,
especially since there now appears to be no way to get an EISCONN error
from a TCP socket.]
Ben
------------------------------
Date: Mon, 05 Dec 2011 00:00:51 -0500
From: Lewis G Rosenthal <lgrosenthal@invalid-invalid.com>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <jbhj66$r8l$1@speranza.aioe.org>
On 11/30/11 05:41 pm, Andy thus wrote :
> On Tue, 29 Nov 2011 00:56:14 UTC, Shmuel (Seymour J.) Metz
> <spamtrap@library.lspace.org.invalid> wrote:
>
>> In<stfVq7QNr4pc-pn2-l0gOdRWfdBbo@localhost>, on 11/28/2011
>> at 11:00 PM, "Andy"<nospam-abwillis1-nopspam@nospam-gmail.com>
>> said:
>>
>>> There is an open bug on this issue I believe:
>>
>> Thanks.
>>
>>> http://mantis.smedley.info/view.php?id=303
>>
>> That requires a login. Are you allowed to post the information here?
>>
> I didn't because it is quite long but:
> Summary 0000303: CPAN (make) under 5.10.0 fails to build with "No rule
> to make target `/perl5/lib/5.10.0/os2/Config.pm'"
> Description I'm not sure if this is related to 236 or perhaps a
> remnant of 224, but I can't for the life of me get past this one.
> Here's a snippet:
>
I do *love* seeing my words immortalized via NNTP...
I keep forgetting this bug report of mine, as each time I run into it, I
waste a day trying to get past it, and then end up installing manually,
anyway.
I'm curious to test out Ben's statements concerning paths a few posts
back. When I have an opportunity, I'll do so and make mention here. If
anything constructive comes of it, I'll update the bug report on Paul's
Mantis.
Cheers/2
--
Lewis
-------------------------------------------------------------
Lewis G Rosenthal, CNA, CLP, CLE, CWTS
Rosenthal & Rosenthal, LLC www.2rosenthals.com
Need a managed Wi-Fi hotspot? www.hautspot.com
visit my IT blog www.2rosenthals.net/wordpress
-------------------------------------------------------------
------------------------------
Date: Mon, 05 Dec 2011 19:59:48 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <OtOdneN9eYaJ6kDTnZ2dnUVZ8kOdnZ2d@bt.com>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> In <CPKdnQOEztE08kTTnZ2dnUVZ8ladnZ2d@bt.com>, on 12/02/2011
> at 06:39 PM, Ben Morrow <ben@morrow.me.uk> said:
>
> >Net::DNS, AFAICT, uses $Config{cc} and $Config{full_ar}, so these
> >need to be set correctly. That perl appears to have them set to 'gcc'
> >and 'ar' respectively, so you need the right versions of those
> >utilities in your PATH. (Or you can edit Config_heavy.pl again, of
> >course, and put in a full path to the correct utility.)
>
> Now I get
>
> gcc.exe: gcc.exe: error executing U:/usr/i386-pc-os2-emx/bin/as.exe:
> No such fil e or directory
>
> However,
>
> Directory of U:\usr\i386-pc-os2-emx\bin
>
> 6-11-07 9:19a 212,992 0 a--- as.exe
Weird. Did you put gcc in your path, or did you edit Config_heavy.pl? If
you edited Config_heavy, which slashes did you use? Does OS/2 allow you
to run a command (from the cmd.exe prompt) using forward slashes in the
path, or is it like Win32 and treats / as the option character?
(Even if forward slashes are the problem, I can't see how it gives
*that* symptom. I would've expected the invocation of gcc to fail, not
of as.)
Can you run gcc at all? (I've seen Win32 give 'file not found' errors
when a .exe which is there depends on a .dll which isn't.)
> Also, I get an IPv6 dependency; is that optional or do I need to
> install and build the package in order to build Net::DNS even though I
> don't (currently) support or use IPv6?
It's optional.
Ben
------------------------------
Date: Mon, 5 Dec 2011 04:54:58 -0800 (PST)
From: Krzysztof Poc <fajfusio@wp.pl>
Subject: simple xml - change tag name
Message-Id: <8310999f-c334-4d0d-801e-e8370d358215@m7g2000vbc.googlegroups.com>
Hi
I would like to change the tag name in an XML document. Can I do that
using
XML::Simple. If so could you give me a simple example of how to do
that.
To be exact I would like to convert the following:
<album>
<name> John </name>
<age> 25 </age>
</album>
into:
<album>
<surname> John </surname>
<age> 25 </age>
</album>
thank you for help
------------------------------
Date: Mon, 05 Dec 2011 13:51:53 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: simple xml - change tag name
Message-Id: <dfqdnTJ3eczkUUHTnZ2dnUVZ8j2dnZ2d@giganews.com>
On 05/12/11 12:54, Krzysztof Poc wrote:
> Hi
>
> I would like to change the tag name in an XML document. Can I do that
> using
> XML::Simple. If so could you give me a simple example of how to do
> that.
XML::Simple won't do it directly (the word "rename" doesn't appear in
its CPAN page!); its main function is to parse some XML and present its
content as a Perl hash (or the other way round). As you would have
found if you'd tried it, your XML example will, with default settings,
turn up like this:
$somename = {
'name' => ' John ',
'age' => ' 25 '
};
(where $somename is the variable you used for the XMLin function).
What you want to do isn't hard, given that structure. Something like
this (untested) would work:
$somename->{surname} = $somename->{name};
delete $somename->{name};
If you want to learn some other XML module to do this -- because there's
more to your problem than you've explained so far, perhaps -- then fire
away and someone here will help you debug your code. Me, I'd use
XML::Simple since I'm very familiar with it and the code above isn't
hard. If I had to do it a lot I might even write a function which got
invoked like this
rename_hash_key( $somename, { name=>'surname', otherkey=>'itsnewname'} );
--
Henry Law Manchester, England
------------------------------
Date: Mon, 5 Dec 2011 14:54:39 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: simple xml - change tag name
Message-Id: <slrnjdpmpf.fov.willem@toad.stack.nl>
Henry Law wrote:
) What you want to do isn't hard, given that structure. Something like
) this (untested) would work:
)
) $somename->{surname} = $somename->{name};
) delete $somename->{name};
Did you know that delete returns the element(s) it deleted:
$somename->{surname} = delete $somename->{name};
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Mon, 05 Dec 2011 08:59:08 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: simple xml - change tag name
Message-Id: <4Yednd4-4OKhQUHTnZ2dnUVZ8oGdnZ2d@bt.com>
Quoth Krzysztof Poc <fajfusio@wp.pl>:
>
> I would like to change the tag name in an XML document. Can I do that
> using
> XML::Simple. If so could you give me a simple example of how to do
> that.
>
> To be exact I would like to convert the following:
>
> <album>
> <name> John </name>
> <age> 25 </age>
> </album>
>
> into:
>
> <album>
> <surname> John </surname>
> <age> 25 </age>
> </album>
Assuming your actual XML is larger and more nested than this, this sound
to me like a job for a SAX filter.
Ben
------------------------------
Date: Mon, 05 Dec 2011 16:43:49 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: simple xml - change tag name
Message-Id: <I7GdnfNRkv9YaUHTnZ2dnUVZ8kGdnZ2d@giganews.com>
On 05/12/11 14:54, Willem wrote:
> Henry Law wrote:
> )
> ) $somename->{surname} = $somename->{name};
> ) delete $somename->{name};
>
> Did you know that delete returns the element(s) it deleted:
> $somename->{surname} = delete $somename->{name};
I missed that! Makes what the OP wants to do even easier.
Pleased to learn something more.
--
Henry Law Manchester, England
------------------------------
Date: Mon, 5 Dec 2011 17:19:15 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: simple xml - change tag name
Message-Id: <slrnjdpv8j.18pn.willem@toad.stack.nl>
Krzysztof Poc wrote:
) I would like to change the tag name in an XML document. Can I do that
) using XML::Simple. If so could you give me a simple example of how to
) do that.
Why would you want to do that with Perl?
This is one of the few things that XSLT is actually good at!
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 3559
***************************************