[24778] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6931 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 29 21:11:20 2004

Date: Sun, 29 Aug 2004 18:10: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           Sun, 29 Aug 2004     Volume: 10 Number: 6931

Today's topics:
    Re: perl - data structure build to transpose data <dwall@fastmail.fm>
    Re: perl - data structure build to transpose data (Anno Siegel)
    Re: perl - data structure build to transpose data <tadmc@augustmail.com>
    Re: perl - data structure build to transpose data (Anno Siegel)
    Re: perl - data structure build to transpose data <dwall@fastmail.fm>
    Re: perl - data structure build to transpose data (Anno Siegel)
    Re: perl - data structure build to transpose data <dwall@fastmail.fm>
    Re: perl - data structure build to transpose data (Anno Siegel)
    Re: perl - data structure build to transpose data <dwall@fastmail.fm>
    Re: perl - data structure build to transpose data (Anno Siegel)
        perl and memory (Marcus)
    Re: perl and memory <dwall@fastmail.fm>
    Re: Resizing JPG images with Perl? <mgjv@tradingpost.com.au>
        XML::Twig constructor disregarding map_xmlns - bug in m (Andres Monroy-Hernandez)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 29 Aug 2004 21:04:10 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: perl - data structure build to transpose data
Message-Id: <Xns9554ADA4BB893dkwwashere@216.168.3.30>

srigowrisn@hotmail.com (shree) wrote:

> Sample Data filein.dat
>            Jan-04     Feb-04     Mar-04
> Supp1     %     20.00%     10.17%     7.14%
>      Defects     200     122     100
>      Total     1000     1200     1400
> Supp2     %     3.00%     1.82%     1.90%
>      Defects     60     40     40
>      Total     2000     2200     2100
> 
> Desired Output fileout.txt                    
> Supp1     %     20.00%     Jan-04     1
> Supp1     Defects     200     Jan-04     1
> Supp1     Total     1000     Jan-04     1
> Supp1     %     10.17%     Feb-04     2
> Supp1     Defects     122     Feb-04     2
> Supp1     Total     1200     Feb-04     2
> Supp1     %     7.14%     Mar-04     3
> Supp1     Defects     100     Mar-04     3
> Supp1     Total     1400     Mar-04     3
> Supp2     %     3.00%     Jan-04     1
> Supp2     Defects     60     Jan-04     1
> Supp2     Total     2000     Jan-04     1
> Supp2     %     1.82%     Feb-04     2
> Supp2     Defects     40     Feb-04     2
> Supp2     Total     2200     Feb-04     2
> Supp2     %     1.90%     Mar-04     3
> Supp2     Defects     40     Mar-04     3
> Supp2     Total     2100     Mar-04     3

Yet another way:

use strict;
use warnings;

chomp( my @months = split ' ', <DATA> );
while (not eof DATA) {

    my (%supplier, $supplier_name);
    for ( 1..3 ) {
        my ($name, $type, @data) = split /\s+/, <DATA>;
        $supplier_name = $name if $name;
        @{$supplier{$type}}{@months} = @data;
    }
    
    my $month_num;
    for my $month ( @months ) {
        $month_num++;
        for my $type (sort keys %supplier) {
            print join( "\t", 
                    $supplier_name, 
                    $type, 
                    $supplier{$type}{$month},
                    $month,
                    $month_num
                ),
                "\n";
        }
    }
}


__DATA__
	 	Jan-04	Feb-04	Mar-04
Supp1	%	20.00%	10.17%	7.14%
	Defects	200	122	100
	Total	1000	1200	1400
Supp2	%	3.00%	1.82%	1.90%
	Defects	60	40	40
	Total	2000	2200	2100


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

Date: 29 Aug 2004 21:40:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgtifu$44j$1@mamenchi.zrz.TU-Berlin.DE>

shree <srigowrisn@hotmail.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> I have been asked to transpose a data file extracted from an Excel
> report and saved as a .txt file. It lists time (MonthYear) in the
> header (first row). The data consists of blocks of 3 lines per
> supplier. In the example extract shown below, for Jan-04, total items
> supplied by supplier 1 were 1000, of which there were 200 defects,
> giving a defect ratio of 20%. I need to read-in this data file and
> output a file whose format I can best illustrate via an example shown
> below. Please note in the outfile's last column, it shows MonthID. If
> the data were to begin with Feb-04 and go till July-04, instead of
> Jan-04 to Mar-04 as shown below, then Feb-04 would be 1, Mar-04 2 and
> so on.
> 
> Anyway, I'm struggling on thoughts of how to build a data structure to
> transform the data into the desired output file. Any pointers, code
> snippets will be greatly appreciated and I thank you in advance.

It would be nice to see a snippet of your code, or even of your
thoughts about the problem.  Just dumping the problem description
*you* got to the newsgroup is frowned upon.  You haven't even begun
an analysis.

> Sample Data filein.dat
> 	 	Jan-04	Feb-04	Mar-04
> Supp1	%	20.00%	10.17%	7.14%
> 	Defects	200	122	100
> 	Total	1000	1200	1400
> Supp2	%	3.00%	1.82%	1.90%
> 	Defects	60	40	40
> 	Total	2000	2200	2100

So the first data line is special and gives you the months to expect.
Assuming the data in DATA, get the list of months and generate the
MonthID's like this (all untested):

    my ( @months, %month_id);
    @months = split for ( scalar <DATA> );
    @month_id{ @months} = 1 .. @months;

Also set an output format at this point, you'll need it later:

    my $ofmt = "%-5s %-7s %-7s %-6s %2d\n";

You can save yourself the effort of setting this up and use my
module Text::Table instead, but the format will do.

Now you can process the following lines in groups of three:

    line: while ( 1 ) {
        my ( $supp, %supp_data);
        for ( scalar <DATA> ) { # get one line in $_
            last line unless defined; # regular end of file
            ( $supp, undef, @{ $supp_data{ '%'}}{ @months}) = split;
        }
        for ( scalar <DATA> ) {
            die "data error 2" unless defined;
            ( undef, @{ $supp_data{ Defects}}{ @months}) = split;
        }
        for ( scalar <DATA> ) {
            die "data error 3" unless defined;
            ( undef, @{ $supp_data{ Total}}{ @months}) = split;
        }

There should probably be data checks in a real program, besides the
end-of-file test I provided.  Anyway, now you have collected all data
for one supplier and can print it in any format you want, for instance
this:

        for my $month ( @months) {
            for ( qw( % Defects Total) ) {
                printf $ofmt, $supp, $_, $supp_data{ $_}->{ $month},
                    $month, $month_id{ $month};
            }
        }
    }


> Desired Ouput file out.txt				

[snipped]

Anno


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

Date: Sun, 29 Aug 2004 12:30:08 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl - data structure build to transpose data
Message-Id: <slrncj44l0.g00.tadmc@magna.augustmail.com>

wfsp <wfsp@removeyahoo.com> wrote:

> I should have said:
>> my $month_count = $#months;

>>   for (my $i=1;$i<=$month_count+1;$i++){
> It works as is but looking at it again it's clearer this way.


   foreach my $i ( 1 .. @mounths )

would be clearer yet.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 29 Aug 2004 22:31:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgtlfl$65m$1@mamenchi.zrz.TU-Berlin.DE>

bowsayge  <bowsayge@nomail.afraid.org> wrote in comp.lang.perl.misc:
> shree said to us:
> 
> [...]
> > Anyway, I'm struggling on thoughts of how to build a data structure to
> > transform the data into the desired output file. Any pointers, code
> > snippets will be greatly appreciated and I thank you in advance.
> [...]
> 
> This isn't pretty, but it is one way of doing it. 
> 
>     local $_;      
>     my ($current, %supp, @months);
> 
>     while ($_ = <STDIN>) {
>         chomp;
>         if (@months < 1) {
>             s/(\w{3}-\d{2})/push @months, $1; ''/eg;
>         } else {
>             if (/^([a-zA-Z0-9]+)\s+\%\s+/) {
>                 my $sn = $1;
>                 push @{$supp{suppliers}}, $sn;
>                 s/^.*?%\s+//;
>                 s/([\d\.\%]+)/push @{$supp{"$sn,\%"}}, $1; ''/eg;
>                 $current = $sn;
>             } elsif (/^\s+Defects/) {
>                 s/^\D+//;
>                 s/(\d+)\s*/push @{$supp{"$current,defects"}}, $1; ''/eg;
>             } elsif (/^\s+Total/) {
>                 s/^\D+//;
>                 s/(\d+)\s*/push @{$supp{"$current,total"}}, $1; ''/eg;
>             }
>         }
>     }
> 
>     foreach my $sn (@{$supp{suppliers}}) {
>         foreach my $no (0..$#months) {
>             my $pref = $supp{"$sn,%"};
>             my $dref = $supp{"$sn,defects"};
>             my $tref = $supp{"$sn,total"};
>             my $suffix = "\t$months[$no]\t@{[ $no + 1 ]}\n";
>             print "$sn\t\%\t$pref->[$no]$suffix";
>             print "$sn\tDefects\t$dref->[$no]$suffix";
>             print "$sn\tTotal\t$tref->[$no]$suffix";
>         }
>     }
> 
> __END__

I'll believe you, for one because I know you test your programs :)

> EXPLANATION:
> The list of months is grabbed from the first line. 
> 
> Then a hash is created that contains a list of supplier names. The hash also
> is built up to contain the defect percentages, the number of defects and
> the totals. 
> 
> When it's time to create the output, the program iterates over the
> list of suppliers. For each supplier, the program iterates over the
> months, outputting the various statistics for that month. 

I haven't analyzed your program to the last statement, but I have
some remarks.

It is much more general than necessary, in that it could read the
input data in any sequence and produce the right output.  Even the
title line (which defines the expected months) could be buried
anywhere, if I'm not mistaken.

I interpret the OPs sample data to say that there is a title line
and then a sequence of groups of three, all formatted alike.  It
is easier to read the file that way, expecting from each line a
given format.  You can also handle each supplier as soon as you have
read the three lines, so you don't have to keep everything in memory.
With your approach, you will have to do that.

I'm also not too happy about your way to do serious data processing in
an s///e expression.  This approach can be powerful, but it's hard to
follow, and it's not needed here.  The data is far better split() (on
white space) first.  Then the fields can be processed as needed.

The rule (known as Randal's Rule) is: If you know what to keep, use
a match, if you know what to throw away, use split.  "Know" can
be translated as "know the simpler regex for".  Here, the default
split on white space is the obvious choice.

> The program doesn't do exactly what you want, since it gets input from
> STDIN and outputs to STDOUT, but you can easily adjust it. 

That's a minor point.  Example programs on Usenet (in Perl) routinely
print to STDOUT, and read from DATA or STDIN.

> Now watch someone convert this into a one-liner :)

Hardly.  I have posted another solution (before I saw yours), that
takes the three-lines-at-a-time approach.  You will note that it
takes some effort to deal with end-of-file correctly.  That is typical
for this way of reading a file in groups of n lines and is a drawback.

Anno


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

Date: Sun, 29 Aug 2004 23:00:43 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: perl - data structure build to transpose data
Message-Id: <Xns9554C1670FFC0dkwwashere@216.168.3.30>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> It is much more general than necessary, in that it could read the
> input data in any sequence and produce the right output.  Even the
> title line (which defines the expected months) could be buried
> anywhere, if I'm not mistaken.

That's a valid criticism of my post as well, since it will produce the 
"correct" output as long as the three lines for title/percent, defects, and 
total are all grouped together. I'll admit I was thinking of this as a 
strength, because another line could be added to a supplier record with 
minimal changes to the code. But in your post you mentioned data checks, 
something I hadn't considered since I assumed the data was okay. It's good to 
see another viewpoint. 

Maybe if it were MY data I would have been more careful. :-)


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

Date: 29 Aug 2004 23:07:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgtnio$7dh$1@mamenchi.zrz.TU-Berlin.DE>

David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> srigowrisn@hotmail.com (shree) wrote:

[specifications]

> Yet another way:

Shree got lucky, undeservedly.

> use strict;
> use warnings;
> 
> chomp( my @months = split ' ', <DATA> );
> while (not eof DATA) {
> 
>     my (%supplier, $supplier_name);
>     for ( 1..3 ) {

This could use

         die "data error $_" if eof;

>         my ($name, $type, @data) = split /\s+/, <DATA>;
>         $supplier_name = $name if $name;
>         @{$supplier{$type}}{@months} = @data;
>     }

Ah, nice common format for all data records.  BTW, the default
split on ' ' wouldn't do, because it skips initial white space,
suppressing leading empty fields.  Did I ever mention that split()
is too clever for its own good? :)

This combines part of bowsayge's flexibility WRT line sequence
with sequential processing in groups of three.  The lines could
be permuted within each supplier and would end up in the right
place.

>     my $month_num;
>     for my $month ( @months ) {
>         $month_num++;
>         for my $type (sort keys %supplier) {
>             print join( "\t", 
>                     $supplier_name, 
>                     $type, 
>                     $supplier{$type}{$month},
>                     $month,
>                     $month_num
>                 ),
>                 "\n";
>         }
>     }
> }

I would... umm, did use a pre-assigned hash %month_num (or somesuch),
instead of counting $month_num each time.  It takes some clutter out
of the print loop.

> __DATA__

[snipped]

I notice that you used the exact same data structure that I used to store
the data for each supplier.  I wouldn't be amazed if you'd come up with it
independently, it seems inherent to the problem.  I haven't analyzed
bowsayge's, but aside from some (unnecessary) trick with appending
key parts, it appears similar.

Anno


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

Date: Sun, 29 Aug 2004 23:07:20 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: perl - data structure build to transpose data
Message-Id: <Xns9554C28653FF2dkwwashere@216.168.3.30>

I wrote:

>     my (%supplier, $supplier_name);
>     for ( 1..3 ) {
>         my ($name, $type, @data) = split /\s+/, <DATA>;
>         $supplier_name = $name if $name;
>         @{$supplier{$type}}{@months} = @data;
>     }

Looking at this again after responding to Anno, I recall just why I used a 
for loop: my original (unposted) solution handled each line separately, but 
when I looked at it I realized I was repeating basically the same code three 
times. I didn't like that, so I condensed it.

(Can you tell it's Sunday evening and I'm bored? :-)


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

Date: 29 Aug 2004 23:30:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgtova$83j$1@mamenchi.zrz.TU-Berlin.DE>

David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> > It is much more general than necessary, in that it could read the
> > input data in any sequence and produce the right output.  Even the
> > title line (which defines the expected months) could be buried
> > anywhere, if I'm not mistaken.
> 
> That's a valid criticism of my post as well, since it will produce the 
> "correct" output as long as the three lines for title/percent, defects, and 
> total are all grouped together. I'll admit I was thinking of this as a 
> strength, because another line could be added to a supplier record with 
> minimal changes to the code. But in your post you mentioned data checks, 
> something I hadn't considered since I assumed the data was okay. It's good to 
> see another viewpoint. 

Your assumption may well be justified.  I seem to remember the data
is produced by some other program, some spreadsheet or the like.
Whatever it is, it won't be in the habit of producing incomplete data or
changing the format at whim.

I don't think my criticism applies as much as it does to bowsayge's.
If I got it right, the lines could be in any permutation, including
the title line.  That is way too much generality.

Allowing for permutations in each group of three (or n) doesn't
disturb the sequential processing of groups, which is my main
objection against the generality.  Un-needed generality is a bonus
if it comes at no cost, as it does with your solution.  In fact,
it enables the processing of all lines in a loop.  My solution,
which expects a fixed sequence, has to unroll the loop.

> Maybe if it were MY data I would have been more careful. :-)

I've been slightly wondering about the purpose of this exercise.
It seems to put the data back into a rawer, more redundant form,
one it might have had before it entered the spreadsheet.

But it makes a nice example.

Anno


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

Date: Sun, 29 Aug 2004 23:37:55 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: perl - data structure build to transpose data
Message-Id: <Xns9554C7B63CC8Ddkwwashere@216.168.3.30>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
>> srigowrisn@hotmail.com (shree) wrote:
> 
> [specifications]
> 
>> Yet another way:
> 
> Shree got lucky, undeservedly.

I'm bored.

>> while (not eof DATA) {
>> 
>>     my (%supplier, $supplier_name);
>>     for ( 1..3 ) {
> 
> This could use
> 
>          die "data error $_" if eof;

Yup.

> 
>>         my ($name, $type, @data) = split /\s+/, <DATA>;
>>         $supplier_name = $name if $name;
>>         @{$supplier{$type}}{@months} = @data;
>>     }
> 
> Ah, nice common format for all data records.  BTW, the default
> split on ' ' wouldn't do, because it skips initial white space,
> suppressing leading empty fields.  Did I ever mention that split()
> is too clever for its own good? :)

Yeah. Not using the default split on whitespace was deliberate: I *wanted* 
that empty field. :-)

> This combines part of bowsayge's flexibility WRT line sequence
> with sequential processing in groups of three.  The lines could
> be permuted within each supplier and would end up in the right
> place.

I've already admitted that in another post. Must have crossed each other 
during propogation through usenet.

> I would... umm, did use a pre-assigned hash %month_num (or somesuch),
> instead of counting $month_num each time.  It takes some clutter out
> of the print loop.

That was nice. Wish I'd thought of it.

> I notice that you used the exact same data structure that I used to
> store the data for each supplier.  I wouldn't be amazed if you'd come up
> with it independently, it seems inherent to the problem. 

Yeah, it was independent: it seemed the natural way to do it.

> I haven't
> analyzed bowsayge's, but aside from some (unnecessary) trick with
> appending key parts, it appears similar.

I didn't actually read his; I didn't feel like digging into the s/// stuff. 
It just gave me the urge to write something easier to read. :-)


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

Date: 30 Aug 2004 00:05:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgtqvc$983$1@mamenchi.zrz.TU-Berlin.DE>

David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> > David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> >> srigowrisn@hotmail.com (shree) wrote:
> > 
> > [specifications]
> > 
> >> Yet another way:
> > 
> > Shree got lucky, undeservedly.
> 
> I'm bored.

To summarize (time for bed here, so I'm in a summarizing mood) and
to take the chance to plug Text::Table for real, I've put the parts
together.  It's still far from a one-liner, but it's about as compact
as it gets while trying to keep it readable.

Anno

use Text::Table;
my $tb = Text::Table->new( ( '&left') x 5);
my ( @months, %month_id);
@months = split for ( scalar <DATA> );
@month_id{ @months} = 1 .. @months;
while ( ! eof DATA ) {
    my ( $supp_name, %supp_data);
    for ( 1 .. 3 ) {
        die "bad data $_" if eof;
        my ( $name, $type, @data) = split /\s+/, <DATA>;
        $supp_name = $name if $name;
        @{$supp_data{$type}}{@months} = @data;
    }
    for my $month ( @months) {
        for ( sort keys %supp_data ) {
            $tb->add( $supp_name, $_, $supp_data{ $_}->{ $month},
                $month, $month_id{ $month});
        }
    }
}
print $tb;

__DATA__
          Jan-04  Feb-04  Mar-04
Supp1 %       20.00%  10.17%  7.14%
  Defects 200     122     100
  Total   1000    1200    1400
Supp2 %       3.00%   1.82%   1.90%
  Defects 60      40      40
  Total   2000    2200    2100


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

Date: 29 Aug 2004 12:16:35 -0700
From: mygooglegroupsaccount@yahoo.com (Marcus)
Subject: perl and memory
Message-Id: <6fc26ca7.0408291116.4faddcbb@posting.google.com>

Im sitting with fairly big perl scripts that I now need to optimize to
make them less resource intensive for the server.

If someone could provide some general guidelines in this, that would
be much appreciated.

Also, could someone give a proper explanation on the differences
between assigning values like:

$something="kskskdjj";

and

my $something="kskskdjj";

and other alternatives.

I have a feeling this could be a potential memory drain.

Thanks
M


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

Date: Sun, 29 Aug 2004 23:55:00 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: perl and memory
Message-Id: <Xns9554CA9B58E11dkwwashere@216.168.3.30>

mygooglegroupsaccount@yahoo.com (Marcus) wrote:

> Also, could someone give a proper explanation on the differences
> between assigning values like:
> 
> $something="kskskdjj";
> 
> and
> 
> my $something="kskskdjj";
> 
> and other alternatives.

See "Coping with Scoping": http://perl.plover.com/FAQs/Namespaces.html



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

Date: 30 Aug 2004 00:22:18 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Resizing JPG images with Perl?
Message-Id: <slrncj4spp.47i.mgjv@verbruggen.comdyn.com.au>

On Fri, 27 Aug 2004 15:14:42 +0200,
	Patrice Auffret <patrice.auffret@intranode.com> wrote:
> On 26 Aug 2004 09:04:11 -0700
> merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> [..]
>>   So, after invoking convert some 200 to 300 times, slowly varying the
>>   parameters, and trying new things, and then trying to figure out how
>>   to convert that to the Perl bindings, again invoking it some 200
>>   times or so (I'm not joking about these numbers, and I wish I was),
>>   I've come up with [listing one, below].
> 
> 
>   And what about Gimp::* hierarchy ? Have someone in this group 
>   ever tested it ? (I'm curious about it, maybe I'll have to use 
>   it one day).

The last time I looked at it is well over 18 months ago. While the
GIMP is a good product as a user interface, the bindings into its API
left a lot to wish for, most importantly good documentation. I also
had some trouble with the stability when I made mistakes in my code
(i.e. segfaults and other sorts of low level crashes), which I don't
believe should be something a Perl API allows. Also, much of the API
consists of allowing automation of manual GUI tasks, rather than
providing a workable interface to automate tasks in general. I didn't
find it to be much faster than other libraries on general tasks
either.

It may very well be that there is better documentation now, and that
the interface is more Perlish and robust, but when I looked at it,
back then, it certainly wasn't very accessible, and not something I;d
recommend to people who don't already intimately know the GIMP.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | Can't say that it is, 'cause it ain't.
                        | 


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

Date: 29 Aug 2004 12:53:43 -0700
From: andres@monroy.com (Andres Monroy-Hernandez)
Subject: XML::Twig constructor disregarding map_xmlns - bug in module?
Message-Id: <3591b31a.0408291153.5e86847f@posting.google.com>

XML::Twig seems to disregard the map_xmlns argument. The warn
"matched!" never get's called. If I remove the map_xmlns and hardcode
the prefixes, then it works. But the whole point is that I don't want
to hardcode the prefixes and map_xmlns is supposed to be just for
that.

use XML::Twig;
use strict;
my $twig = XML::Twig->new(
    map_xmlns => {
        "http://perlmonks.org"  => 'aaa',
        "http://perlmonks.org/blah"=> 'bbb'
    },
    TwigHandlers => {
        '/aaa:monastery/aaa:foo/bbb:bar/bbb:monk' => sub { warn
"matched!"; $_[0]->purge; }
    }
);

my $xml =<<XML;
<?xml version="1.0" encoding="UTF-8"?>
<prefix:monastery xmlns:prefix="http://perlmonks.org">
  <prefix:foo>
    <prefix2:bar xmlns:prefix2="http://perlmonks.org/blah">
       <prefix2:monk>Larry Wall</prefix2:monk>
    </prefix2:bar>
  </prefix:foo>
</prefix:monastery>
XML

$twig->parse($xml);


Any ideas?

Thanks!


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6931
***************************************


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