[31653] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2916 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 21 16:09:35 2010

Date: Wed, 21 Apr 2010 13:09:13 -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, 21 Apr 2010     Volume: 11 Number: 2916

Today's topics:
    Re: Best way to extract content of SVN target/revision  <thepoet_nospam@arcor.de>
        Can not intercept and disable MouseWheel on a canvas <paduille.4061.mumia.w+nospam@earthlink.net>
        Extending a class that uses 'fields' <fred@resel.fr>
    Re: Extending a class that uses 'fields' <ben@morrow.me.uk>
    Re: FAQ 5.35 How do I close a file descriptor by number <vilmos@soti.ca>
    Re: FAQ 5.35 How do I close a file descriptor by number (Alan Curry)
    Re: FAQ 5.35 How do I close a file descriptor by number <ben@morrow.me.uk>
    Re: FAQ 5.35 How do I close a file descriptor by number <hjp-usenet2@hjp.at>
    Re: FAQ 5.35 How do I close a file descriptor by number <ben@morrow.me.uk>
    Re: FAQ 5.35 How do I close a file descriptor by number <vilmos@soti.ca>
        Get XML content using XML::Twig <kalyanrajsista@gmail.com>
    Re: Get XML content using XML::Twig <tadmc@seesig.invalid>
    Re: Get XML content using XML::Twig <john@castleamber.com>
    Re: Get XML content using XML::Twig <klaus03@gmail.com>
    Re: Get XML content using XML::Twig sln@netherlands.com
    Re: Get XML content using XML::Twig <klaus03@gmail.com>
    Re: Threads and Directory Handles <smallpond@juno.com>
        Trying to add exception handling, getting errors after  <davidmichaelkarr@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 21 Apr 2010 05:34:26 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Best way to extract content of SVN target/revision for searching?
Message-Id: <4bce7242$0$6885$9b4e6d93@newsspool2.arcor-online.net>

david.karr wrote:
[...]
> Next, I have to be able to get the text content of the target element
> at each of those revisions, in order to search for a substring.  The
> only obvious interface in SVN::Client that gives me access to the
> element content is the "cat()" method, which writes the content to a
> file descriptor. I suppose I could get this to work, but this seems
> pretty indirect.
> 
> Assuming I'm not missing a different way to do this with SVN::Client,
> among the numerous other SVN Perl packages, is there another one that
> would give me convenient access to the content of an element at a
> revision?

You can always use Perl's feature of "in memory" files to avoid
writing to disk and re-reading the contents:

my $memfile;
open( CURRFILE, ">", \$memfile)
   or die "Failed to open in-memory file: $!";
$ctx->cat(\*CURRFILE, $target, $revision, $pool);

-Chris


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

Date: Wed, 21 Apr 2010 14:15:19 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Can not intercept and disable MouseWheel on a canvas
Message-Id: <9sGdnd542JIU01LWnZ2dnUVZ_ugAAAAA@earthlink.com>

I am having a problem disabling or replacing the MouseWheel
default callback routine for a canvas.

I have an application that uses a canvas; unfortunately, I also have
a habit of turning the mouse wheel at random times. Most applications
ignore this, but the Tk canvas widget scrolls its content when it
receives MouseWheel events.

I've tried to disable this misfeature using several methods. Here is an
example program that shows the problem:

#!/usr/bin/perl
use strict;
use warnings;
use Tk;

my $main = MainWindow->new;
my $f1 = $main->Frame(-width => 300, -height => 300,
     -bd => 1, -relief => 'solid');

my $canvas = $f1->Canvas(-width => 150, -height => 110,
     -bg => 'orange')->pack;
my $rect_id = $canvas->createRectangle(20, 20, 100, 100,
     -fill => 'white');
my $rect2_id = $canvas->createRectangle(120, 20, 140, 40,
     -fill => 'white');
# $canvas->bind($rect_id, 'Button2-MouseWheel', sub { print "Wheel
event\n" }); # ignored
# $canvas->itemconfigure('all', -state => 'disabled');
# $canvas->bind('<Button-1>', sub { print "Sonorm\n" }); # ignored
# $canvas->configure(-state => 'disabled'); # ignored
# $canvas->bind($rect_id, '<ButtonRelease-1>', sub { print "Btn-1\n" });
# $canvas->bind('<MouseWheel>', sub { print "MouseWheel\n" });
# $canvas->CanvasBind('<Button-2>', sub { print "Here-button\n"; });
$canvas->CanvasBind('<MouseWheel>', sub { print "Mwheel\n"; });

$f1->Button(-text => 'Okay', -command => [$main, 'destroy'])->pack;
$f1->packPropagate(1);
$f1->pack;

MainLoop;

__END__

None of these methods, and a dozen others I tried, work to disable
mouse-wheel scrolling for canvas widgets. How do I do this? I'm using
Debian 5.0, Perl 5.10.0 and Perl-tk 804.028.




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

Date: Wed, 21 Apr 2010 10:24:45 +0200
From: =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin  <fred@resel.fr>
Subject: Extending a class that uses 'fields'
Message-Id: <kgg633l1acy.fsf@pc-df-203.priv.enst-bretagne.fr>

Hello,

I want to subclass Net::SSH::Expect, by adding a couple of fields to
it.  Using "perldoc fields" as a guide, I did the following:

---------------- 8< ----------------

#!/usr/bin/perl

{
    package essai;
    use base 'Net::SSH::Expect';
    use fields qw/ new_field /;
    use Data::Dumper;

    sub new {
    my $class = shift;
    my $self = fields::new($class);
        $self->SUPER::new(host => "server.invalid",
                          password => "password");
        print Dumper $self;
        $self->run_ssh;
        $self->{new_field} = "something";
        return $self;
    }
}

package main;

my $ssh = essai->new();

---------------- 8< ----------------

But when $self->run_ssh is called, the ->run_ssh method croaks with:

> croak(ILLEGAL_STATE . " field 'host' is not set.") unless $host;

We see that the pseudo-hash has all its fields, including new_field,
but there is no data.

Looking at the Net::SSH::Expect->new method, I see that it doesn't
initiate the object in the same way as "perldoc fields" does. I fixed
that by patching the new method in the following way (indentation was
already broken):

# diff -C1 Expect.pm.orig Expect.pm
*** Expect.pm.orig      2010-04-21 09:44:29.000000000 +0200
--- Expect.pm   2010-04-21 09:46:34.000000000 +0200
***************
*** 25,29 ****
  sub new {
!     my $type = shift;
        my %args = @_;
!     my Net::SSH::Expect $self = fields::new(ref $type || $type);
  
--- 25,31 ----
  sub new {
!     my Net::SSH::Expect $self = shift;
        my %args = @_;
!     unless (ref $self) {
!       $self = fields::new($self);
!     }
  
Is this a genuine bug in Net::SSH::Expect, or am I doing something
wrong?

-- 
Fred


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

Date: Wed, 21 Apr 2010 16:50:57 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Extending a class that uses 'fields'
Message-Id: <1gj3a7-h1g2.ln1@osiris.mauzo.dyndns.org>


Quoth =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin  <fred@resel.fr>:
> Hello,
> 
> I want to subclass Net::SSH::Expect, by adding a couple of fields to
> it.  Using "perldoc fields" as a guide, I did the following:
> 
> ---------------- 8< ----------------
> 
> #!/usr/bin/perl
> 
> {
>     package essai;

Don't use lowercase names for your own modules. They are reserved for
pragmas (modules like warnings and strict, which affect how Perl parses
your program).

>     use base 'Net::SSH::Expect';
>     use fields qw/ new_field /;

This is really unsafe. You have no way of knowing if the next version
of NSE will add a new field that happens to be called 'new_field'. Use
an inside-out object instead:

    use Scalar::Util qw/refaddr/;

    my %new_field;

    sub new {
       my $class = shift;
       my $self = $class->SUPER::new(...);
       $new_field{refaddr $self} = "something";
    }

Be aware that this will fail if your program uses threads. If you can
depend on 5.10, you can use the core Hash::Util::Fieldhash to fix this
(and also avoid the 'refaddr'). You can also use Object::InsideOut,
which works on older perls but is a little heavy for my taste.

>     use Data::Dumper;
> 
>     sub new {
>     my $class = shift;
>     my $self = fields::new($class);
>         $self->SUPER::new(host => "server.invalid",
>                           password => "password");

This is wrong. Net::SSH::Expect->new is a class method, not an object
method, so you should be calling it on the class.

    my $self = $class->SUPER::new(...);

I believe (though I haven't tested it) that this will fix your original
problem, as well, since N::S::E->new will now call fields::new with your
classname.

Ben



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

Date: 20 Apr 2010 13:41:58 -0700
From: Vilmos Soti <vilmos@soti.ca>
Subject: Re: FAQ 5.35 How do I close a file descriptor by number?
Message-Id: <lqsk6pc0vd.fsf@glia.msmri.medicine.ubc.ca>

Jürgen Exner <jurgenex@hotmail.com> writes:

>> How do I find all the open file descriptors so I can close them?
>>
>> I have a program which basically does this (runs on Unix):
>>
>> $ ./perl-program
>>  sub bye () {
>>        umount /mnt/cdrom;
>>        eject cd;
>>  }
>>
>>  $SIG{INT} = bye;
>>
>>  close cd tray;
>>  mount /mnt/cdrom;
>>  cp -r /mnt/cdrom/ /destdir/;
>>  bye;
>> $
> 
> You must have a different Perl than I. My Perl knows neither cp nor
> mount or umount and the syntax for close looks rather strange, too.

Fair enough. :-) I just wanted to give a quick pseudo code (from the
top of my head) which describes the problem.

>> The problem is that if the user hits Ctrl-C in the middle of the copy,
>> the open file descriptors on /mnt/cdrom will prevent umounting and
>> ejecting.
> 
> AFAIR file descriptors are closed automatically when they go out of
> scope. So scope them correctly and you shouldn't have any problems.

How do I do this?

Here is an actual (and running) perl program which demonstrates this problem:

---------------------- code starts ---------------------
#!/usr/bin/perl

use File::Copy;
use File::Find;

my $find_code = sub {
  copy ($File::Find::name, "/dev/null") if -f $File::Find::name;
};

sub bye () {
      system ("/bin/umount /mnt/cdrom");
      system ("/usr/bin/eject /mnt/cdrom");
      exit;
}
 
$SIG{INT} = \&bye;

system ("/usr/bin/eject -t /mnt/cdrom");          # close the cd tray
system ("/bin/mount /mnt/cdrom");
print "copy starts\n";
find ( { wanted => $find_code, follow => 0, no_chdir => 1 }, "/mnt/cdrom");
print "copy ends\n";
bye;
---------------------- code ends ---------------------

And here are two runs: The second one is interrupted. The output
is formatted for easy readability.

$ ./s.pl
      copy starts
      copy ends
$               # at this point, the cd is ejected.
$ ./s.pl
      copy starts
      umount: /mnt/cdrom: device is busy
      umount: /mnt/cdrom: device is busy
      umount: /mnt/cdrom: device is busy
      umount: /mnt/cdrom: device is busy
      /usr/bin/eject: unmount of `/dev/scd0' failed
$

Now I manually have to unmount and eject the cd.

Basically I would like something like this in the bye function:

foreach (@OPEN_FILE_DESCRIPTORS) {
        next if stdin or stdout or stderr;
        close $_;
}

The question is ... how can I get a list of open file descriptors.

Thanks for your time, Vilmos


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

Date: Tue, 20 Apr 2010 22:25:02 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: FAQ 5.35 How do I close a file descriptor by number?
Message-Id: <hql9jt$jf9$1@speranza.aioe.org>

In article <lqsk6pc0vd.fsf@glia.msmri.medicine.ubc.ca>,
Vilmos Soti  <vilmos@soti.ca> wrote:
|
|my $find_code = sub {
|  copy ($File::Find::name, "/dev/null") if -f $File::Find::name;
|};
|
|sub bye () {
|      system ("/bin/umount /mnt/cdrom");
|      system ("/usr/bin/eject /mnt/cdrom");
|      exit;
|}
| 
|$SIG{INT} = \&bye;
|
|system ("/usr/bin/eject -t /mnt/cdrom");          # close the cd tray
|system ("/bin/mount /mnt/cdrom");
|print "copy starts\n";
|find ( { wanted => $find_code, follow => 0, no_chdir => 1 }, "/mnt/cdrom");
|print "copy ends\n";
|bye;

Put the find() in a subprocess, ignore SIGINT in the parent, do the unmount
after the subprocess is finished.

-- 
Alan Curry


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

Date: Tue, 20 Apr 2010 23:52:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 5.35 How do I close a file descriptor by number?
Message-Id: <kpn1a7-ep72.ln1@osiris.mauzo.dyndns.org>


Quoth Vilmos Soti <vilmos@soti.ca>:
> PerlFAQ Server <brian@theperlreview.com> writes:
> 
> > 5.35: How do I close a file descriptor by number?
> > 
> >     If, for some reason, you have a file descriptor instead of a filehandle
> >     (perhaps you used "POSIX::open"), you can use the "close()" function
> >     from the "POSIX" module:
> 
> I have a related question:
> 
> How do I find all the open file descriptors so I can close them?

There is no way to do this in general, short of calling _exit(2) (or
something else that calls _exit, like Perl's exit). One crude way is
something like

    POSIX::close $_ for 3..1024;

for some suitably large value of '1024'; most systems have some sort of
limit on the maximum possible fd, so check your system documentation.

Ben



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

Date: Wed, 21 Apr 2010 10:09:34 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.35 How do I close a file descriptor by number?
Message-Id: <slrnhstclu.212.hjp-usenet2@hrunkner.hjp.at>

On 2010-04-20 20:41, Vilmos Soti <vilmos@soti.ca> wrote:
> Jürgen Exner <jurgenex@hotmail.com> writes:
>
>>> How do I find all the open file descriptors so I can close them?
>>>
>>> I have a program which basically does this (runs on Unix):
[...]
>>> The problem is that if the user hits Ctrl-C in the middle of the copy,
>>> the open file descriptors on /mnt/cdrom will prevent umounting and
>>> ejecting.
>> 
>> AFAIR file descriptors are closed automatically when they go out of
>> scope.

File descriptors are handled by the OS. They don't go out of scope until
the process exits (or execs, if they are marked "close on exec").

But it looks like you care about Perl handles anyway, not about file
descriptors.



>> So scope them correctly and you shouldn't have any problems.
>
> How do I do this?
>
> Here is an actual (and running) perl program which demonstrates this problem:
>
> ---------------------- code starts ---------------------
> #!/usr/bin/perl
>
> use File::Copy;
> use File::Find;
>
> my $find_code = sub {
>   copy ($File::Find::name, "/dev/null") if -f $File::Find::name;
> };
>
> sub bye () {
>       system ("/bin/umount /mnt/cdrom");
>       system ("/usr/bin/eject /mnt/cdrom");
>       exit;
> }
>  
> $SIG{INT} = \&bye;

Here is the problem. You are calling bye() as a signal handler, so it is
called while the process is still busy copying files. 

Instead you could just die in the signal handler:

$SIG{INT} = sub { die "interrupted" }

and then wrap the copy operations into an eval block:

> system ("/usr/bin/eject -t /mnt/cdrom");          # close the cd tray
> system ("/bin/mount /mnt/cdrom");

> print "copy starts\n";
> find ( { wanted => $find_code, follow => 0, no_chdir => 1 }, "/mnt/cdrom");
> print "copy ends\n";

eval {
    print "copy starts\n";
    find ( { wanted => $find_code, follow => 0, no_chdir => 1 }, "/mnt/cdrom");
    print "copy ends\n";
};
if ($@) {
    print "caught exception: $@\n";
}

> bye;

Then, when you press Ctrl-C, perl will cleanly abort whatever it is
doing (freeing any container[1] which goes out of scope) and jump to the
end of eval block. Finally, bye is called, just as if the block had
been processed normally.


The problem with this approach is that it will only close lexical file
handles. Bareword filehandles never go out of scope, so they won't be
closed. And I haven't checked now, but I'm almost sure that File::Copy
uses bareword filehandles, simply because it is older than lexical
filehandles.


> Basically I would like something like this in the bye function:
>
> foreach (@OPEN_FILE_DESCRIPTORS) {
>         next if stdin or stdout or stderr;
>         close $_;
> }
>
> The question is ... how can I get a list of open file descriptors.

I don't think you can get them. You could uswe the same approach as in
C: Simply calling POSIX::close on all filedescriptors between 3 and some
maximum. 

	hp


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

Date: Wed, 21 Apr 2010 16:42:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 5.35 How do I close a file descriptor by number?
Message-Id: <50j3a7-h1g2.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>
> The problem with this approach is that it will only close lexical file
> handles. Bareword filehandles never go out of scope, so they won't be
> closed. And I haven't checked now, but I'm almost sure that File::Copy
> uses bareword filehandles, simply because it is older than lexical
> filehandles.

File::Copy (at least, v2.14, which comes with 5.10.1) uses
    
    my $fh = \do { local *FH };

which is how you created a scoped filehandle before 5.6. At least in
modern perls, these handles will also auto-close on scope exit.

Ben



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

Date: 21 Apr 2010 11:09:54 -0700
From: Vilmos Soti <vilmos@soti.ca>
Subject: Re: FAQ 5.35 How do I close a file descriptor by number?
Message-Id: <lqochcbrt9.fsf@glia.msmri.medicine.ubc.ca>

"Peter J. Holzer" <hjp-usenet2@hjp.at> writes:

> But it looks like you care about Perl handles anyway, not about file
> descriptors.

Well, yes.

> and then wrap the copy operations into an eval block:

I guess the solution in this case is to use eval, and there no
sane way to have a list of file descriptors.

Thanks for everybody, Vilmos


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

Date: Wed, 21 Apr 2010 05:35:32 -0700 (PDT)
From: alwaysonnet <kalyanrajsista@gmail.com>
Subject: Get XML content using XML::Twig
Message-Id: <13cf12e4-e181-42d1-bbc0-d0032fd98321@y38g2000prb.googlegroups.com>

Hello all,
I'm trying to parse the XML using XML::Twig Module as my XML could be
very large to handle using XML::Simple. Please help me out of how to
print the values based on the following...
 <B>get the values of Sender, Receiver</B>
 <B>get the FileType. In this case possible values are
InitTAP,FatalRAP,ReTxTAP</B>

<CODE>
 get the values of Sender, Receiver
 get the FileType. In this case possible values are
InitTAP,FatalRAP,ReTxTAP
</CODE>
<P>Here is the XML content....</P>
<CODE>
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<ConnectionList>
   <Connection>
       <Sender>BRADD</Sender>
       <Receiver>SHANE</Receiver>
       <FileItemList>
           <FileItem>
               <FileID>378910</FileID>
               <Tmstp>2009-01-16T16:59:07+01:00</Tmstp>
               <FileType>
               <InitTAP>
                   <TAPSeqNo>00083</TAPSeqNo>
                   <NotifFileInd>false</NotifFileInd>
                   <ChargeInfo>
                       <TAPTxCutoffTmstp>2009-01-16T09:43:26+02:00</
TAPTxCutoffTmstp>
                       <TAPAvailTmstp>2009-01-16T16:59:07+01:00</
TAPAvailTmstp>
                       <TAPCurrency>XDR</TAPCurrency>
                       <TotalNoOfCalls>39</TotalNoOfCalls>
                       <TotalNetCharge>11.470</TotalNetCharge>
                       <TotalTax>0.000</TotalTax>
                   </ChargeInfo>
               </InitTAP>
               </FileType>
           </FileItem>
           <FileItem>
               <FileID>380582</FileID>
               <Tmstp>2009-01-20T18:00:00+01:00</Tmstp>
               <FileType>
               <ReTxTAP>
                   <TAPSeqNo>00083</TAPSeqNo>
                   <NotifFileInd>false</NotifFileInd>
                   <RefRAPSeqNo>00044</RefRAPSeqNo>
                   <RefRAPID>380573</RefRAPID>
                   <ChargeInfo>
                       <TAPTxCutoffTmstp>2009-01-16T09:43:26+02:00</
TAPTxCutoffTmstp>
                       <TAPAvailTmstp>2009-01-20T18:00:00+01:00</
TAPAvailTmstp>
                       <TAPCurrency>XDR</TAPCurrency>
                       <TotalNoOfCalls>39</TotalNoOfCalls>
                       <TotalNetCharge>11.470</TotalNetCharge>
                       <TotalTax>0.000</TotalTax>
                   </ChargeInfo>
               </ReTxTAP>
               </FileType>
           </FileItem>
           <FileItem>
               <FileID>380573</FileID>
               <Tmstp>2009-01-16T20:34:45+01:00</Tmstp>
               <FileType>
               <FatalRAP>
                   <RAPSeqNo>00044</RAPSeqNo>
                   <RAPStatus>Exchanged</RAPStatus>
                   <RefTAPSeqNo>00083</RefTAPSeqNo>
                   <RefTAPID>378910</RefTAPID>
                   <RAPCreatTmstp>2009-01-16T20:21:30+01:00</
RAPCreatTmstp>
                   <RAPAvailTmstp>2009-01-16T20:21:30+01:00</
RAPAvailTmstp>
                   <ChargeInfo>
                       <TAPTxCutoffTmstp>2009-01-16T09:43:26+02:00</
TAPTxCutoffTmstp>
                       <TAPAvailTmstp>2009-01-16T16:59:07+01:00</
TAPAvailTmstp>
                       <TAPCurrency>XDR</TAPCurrency>
                       <TotalNoOfCalls>-39</TotalNoOfCalls>
                       <TotalNetCharge>-11.470</TotalNetCharge>
                       <TotalTax>0.000</TotalTax>
                   </ChargeInfo>
               </FatalRAP>
               </FileType>
           </FileItem>
       </FileItemList>
   </Connection>
</ConnectionList>
</Data>
</CODE>


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

Date: Wed, 21 Apr 2010 08:13:50 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Get XML content using XML::Twig
Message-Id: <slrnhstu8a.9p1.tadmc@tadbox.sbcglobal.net>

alwaysonnet <kalyanrajsista@gmail.com> wrote:

> I'm trying to parse the XML using XML::Twig Module


What have you tried so far?

If you show us your broken code we will help you fix it.

Have you seen the Posting Guidelines that are posted here frequently yet?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Wed, 21 Apr 2010 08:49:55 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: Get XML content using XML::Twig
Message-Id: <87zl0woqyk.fsf@castleamber.com>

alwaysonnet <kalyanrajsista@gmail.com> writes:

> Hello all,
> I'm trying to parse the XML using XML::Twig Module as my XML could be
> very large to handle using XML::Simple. Please help me out of how to
> print the values based on the following...
>  <B>get the values of Sender, Receiver</B>
>  <B>get the FileType. In this case possible values are
> InitTAP,FatalRAP,ReTxTAP</B>

For very simple things like this I would (probably, based on what I just
read) use XML::SAX or (even) XML::Parser. Regarding the latter, 
http://johnbokma.com/perl/ has some simple examples under "XML
Processing using Perl"

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


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

Date: Wed, 21 Apr 2010 10:06:14 -0700 (PDT)
From: Klaus <klaus03@gmail.com>
Subject: Re: Get XML content using XML::Twig
Message-Id: <23007162-1b3b-4d06-9f3c-a3bb394792bb@e7g2000yqf.googlegroups.com>

On 21 avr, 14:35, alwaysonnet <kalyanrajsi...@gmail.com> wrote:
> Hello all,
> I'm trying to parse the XML using XML::Twig Module as my XML could be
> very large to handle using XML::Simple. Please help me out of how to
> print the values based on the following...
> =A0<B>get the values of Sender, Receiver</B>
> =A0<B>get the FileType. In this case possible values are
> InitTAP,FatalRAP,ReTxTAP</B>
>
> <CODE>
> =A0get the values of Sender, Receiver
> =A0get the FileType. In this case possible values are
> InitTAP,FatalRAP,ReTxTAP
> </CODE>

What Tad McClellan and John Bokma suggested should be your first path
of investigation.

However, let me bring in a shameless plug:

You could also use my module XML::Reader
http://search.cpan.org/~keichner/XML-Reader-0.32/lib/XML/Reader.pm

This module is specifically designed to handle very big XML files, it
only uses the memory it needs to have one XML element at a time in
memory (plus a small additional memory for buffering, which is
independent of the size of the XML file)

Here is a sample program:

use strict;
use warnings;
use XML::Reader;

my $rdr =3D XML::Reader->newhd(\*DATA, {filter =3D> 5},
    { root =3D> '/Data/ConnectionList/Connection/Sender',   branch =3D>
[ '/' ] },
    { root =3D> '/Data/ConnectionList/Connection/Receiver', branch =3D>
[ '/' ] },
    { root =3D> '/Data/ConnectionList/Connection/FileItemList/FileItem/
FileType', branch =3D> [
      '/InitTAP/TAPSeqNo',
      '/ReTxTAP/TAPSeqNo',
      '/FatalRAP/RAPSeqNo',
    ] },
  );

my ($sender, $receiver);

while ($rdr->iterate) {
    if    ($rdr->rx =3D=3D 0) { $sender   =3D $rdr->rvalue->[0]; }
    elsif ($rdr->rx =3D=3D 1) { $receiver =3D $rdr->rvalue->[0]; }
    else {
        my ($InitTAP, $ReTxTAP, $FatalRAP) =3D @{$rdr->rvalue};
        my ($type, $seqno) =3D defined $InitTAP  ? ('InitTAP',
$InitTAP)
                           : defined $ReTxTAP  ? ('ReTxTAP',
$ReTxTAP)
                           : defined $FatalRAP ? ('FatalRAP',
$FatalRAP)
                           :                     ('???',      '???');

        printf "Sender: %-5s, Receiver: %-5s, Type: %-8s, Seqno: %s
\n",
          $sender, $receiver, $type, $seqno;
    }
}

__DATA__
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<Data>
<ConnectionList>
   <Connection>
       <Sender>BRADD</Sender>
       <Receiver>SHANE</Receiver>
       <FileItemList>
           <FileItem>
               <FileID>378910</FileID>
               <Tmstp>2009-01-16T16:59:07+01:00</Tmstp>
               <FileType>
               <InitTAP>
                   <TAPSeqNo>00083</TAPSeqNo>
                   <NotifFileInd>false</NotifFileInd>
                   <ChargeInfo>
                       <TAPTxCutoffTmstp>2009-01-16T09:43:26+02:00</
TAPTxCutoffTmstp>
                       <TAPAvailTmstp>2009-01-16T16:59:07+01:00</
TAPAvailTmstp>
                       <TAPCurrency>XDR</TAPCurrency>
                       <TotalNoOfCalls>39</TotalNoOfCalls>
                       <TotalNetCharge>11.470</TotalNetCharge>
                       <TotalTax>0.000</TotalTax>
                   </ChargeInfo>
               </InitTAP>
               </FileType>
           </FileItem>
           <FileItem>
               <FileID>380582</FileID>
               <Tmstp>2009-01-20T18:00:00+01:00</Tmstp>
               <FileType>
               <ReTxTAP>
                   <TAPSeqNo>00083</TAPSeqNo>
                   <NotifFileInd>false</NotifFileInd>
                   <RefRAPSeqNo>00044</RefRAPSeqNo>
                   <RefRAPID>380573</RefRAPID>
                   <ChargeInfo>
                       <TAPTxCutoffTmstp>2009-01-16T09:43:26+02:00</
TAPTxCutoffTmstp>
                       <TAPAvailTmstp>2009-01-20T18:00:00+01:00</
TAPAvailTmstp>
                       <TAPCurrency>XDR</TAPCurrency>
                       <TotalNoOfCalls>39</TotalNoOfCalls>
                       <TotalNetCharge>11.470</TotalNetCharge>
                       <TotalTax>0.000</TotalTax>
                   </ChargeInfo>
               </ReTxTAP>
               </FileType>
           </FileItem>
           <FileItem>
               <FileID>380573</FileID>
               <Tmstp>2009-01-16T20:34:45+01:00</Tmstp>
               <FileType>
               <FatalRAP>
                   <RAPSeqNo>00044</RAPSeqNo>
                   <RAPStatus>Exchanged</RAPStatus>
                   <RefTAPSeqNo>00083</RefTAPSeqNo>
                   <RefTAPID>378910</RefTAPID>
                   <RAPCreatTmstp>2009-01-16T20:21:30+01:00</
RAPCreatTmstp>
                   <RAPAvailTmstp>2009-01-16T20:21:30+01:00</
RAPAvailTmstp>
                   <ChargeInfo>
                       <TAPTxCutoffTmstp>2009-01-16T09:43:26+02:00</
TAPTxCutoffTmstp>
                       <TAPAvailTmstp>2009-01-16T16:59:07+01:00</
TAPAvailTmstp>
                       <TAPCurrency>XDR</TAPCurrency>
                       <TotalNoOfCalls>-39</TotalNoOfCalls>
                       <TotalNetCharge>-11.470</TotalNetCharge>
                       <TotalTax>0.000</TotalTax>
                   </ChargeInfo>
               </FatalRAP>
               </FileType>
           </FileItem>
       </FileItemList>
   </Connection>
</ConnectionList>
</Data>

=3D=3D=3D=3D=3D=3D=3D
Here is the output:

Sender: BRADD, Receiver: SHANE, Type: InitTAP , Seqno: 00083
Sender: BRADD, Receiver: SHANE, Type: ReTxTAP , Seqno: 00083
Sender: BRADD, Receiver: SHANE, Type: FatalRAP, Seqno: 00044


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

Date: Wed, 21 Apr 2010 11:07:55 -0700
From: sln@netherlands.com
Subject: Re: Get XML content using XML::Twig
Message-Id: <j5fus51t7l57eq1ffui57dp3242l4t44lg@4ax.com>

On Wed, 21 Apr 2010 10:06:14 -0700 (PDT), Klaus <klaus03@gmail.com> wrote:

>On 21 avr, 14:35, alwaysonnet <kalyanrajsi...@gmail.com> wrote:
>> Hello all,
>> I'm trying to parse the XML using XML::Twig Module as my XML could be
>> very large to handle using XML::Simple. Please help me out of how to
>> print the values based on the following...
>>  <B>get the values of Sender, Receiver</B>
>>  <B>get the FileType. In this case possible values are
>> InitTAP,FatalRAP,ReTxTAP</B>
>>
>> <CODE>
>>  get the values of Sender, Receiver
>>  get the FileType. In this case possible values are
>> InitTAP,FatalRAP,ReTxTAP
>> </CODE>
>
>What Tad McClellan and John Bokma suggested should be your first path
>of investigation.
>
>However, let me bring in a shameless plug:
>
>You could also use my module XML::Reader
>http://search.cpan.org/~keichner/XML-Reader-0.32/lib/XML/Reader.pm
Indeed shameless.
>
>This module is specifically designed to handle very big XML files, it
>only uses the memory it needs to have one XML element at a time in
>memory (plus a small additional memory for buffering, which is
>independent of the size of the XML file)
Is memory at a premium?
>
>Here is a sample program:
>
>use strict;
>use warnings;
>use XML::Reader;
>
>my $rdr = XML::Reader->newhd(\*DATA, {filter => 5},
>    { root => '/Data/ConnectionList/Connection/Sender',   branch =>
>[ '/' ] },
>    { root => '/Data/ConnectionList/Connection/Receiver', branch =>
>[ '/' ] },
>    { root => '/Data/ConnectionList/Connection/FileItemList/FileItem/
>FileType', branch => [
>      '/InitTAP/TAPSeqNo',
>      '/ReTxTAP/TAPSeqNo',
>      '/FatalRAP/RAPSeqNo',
            ^^^^^^^^^^^^
What do these have to do with it?
>    ] },
>  );
>
>my ($sender, $receiver);
>
>while ($rdr->iterate) {
>    if    ($rdr->rx == 0) { $sender   = $rdr->rvalue->[0]; }
>    elsif ($rdr->rx == 1) { $receiver = $rdr->rvalue->[0]; }
>    else {
>        my ($InitTAP, $ReTxTAP, $FatalRAP) = @{$rdr->rvalue};
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Again, what do these have to do with it?
[snip]
>=======
>Here is the output:
>
>Sender: BRADD, Receiver: SHANE, Type: InitTAP , Seqno: 00083
>Sender: BRADD, Receiver: SHANE, Type: ReTxTAP , Seqno: 00083
>Sender: BRADD, Receiver: SHANE, Type: FatalRAP, Seqno: 00044

Thats nice. Lets say he generally said "in this case its:"
InitTAP  ReTxTAP  FatalRAP
Why? Because its the file type.
Maybe he wants all file types of the sender/reciever's.
But its hard to know what the OP wants isin't it.

-sln


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

Date: Wed, 21 Apr 2010 11:48:59 -0700 (PDT)
From: Klaus <klaus03@gmail.com>
Subject: Re: Get XML content using XML::Twig
Message-Id: <60f05397-1d0c-49fd-82d4-a38e661e8b2c@r27g2000yqn.googlegroups.com>

On 21 avr, 20:07, s...@netherlands.com wrote:
> On Wed, 21 Apr 2010 10:06:14 -0700 (PDT), Klaus <klau...@gmail.com> wrote=
:
> >On 21 avr, 14:35, alwaysonnet <kalyanrajsi...@gmail.com> wrote:
> >> Hello all,
> >> I'm trying to parse the XML using XML::Twig Module as my XML could be
> >> very large to handle using XML::Simple. Please help me out of how to
> >> print the values based on the following...
> >> =A0<B>get the values of Sender, Receiver</B>
> >> =A0<B>get the FileType. In this case possible values are
> >> InitTAP,FatalRAP,ReTxTAP</B>

> Thats nice. Lets say he generally said "in this case its:"
> InitTAP =A0ReTxTAP =A0FatalRAP
> Why? Because its the file type.
> Maybe he wants all file types of the sender/reciever's.

in that case you use XML::Reader->newhd(... {filter =3D> 2});

use strict;
use warnings;
use XML::Reader;

my $rdr =3D XML::Reader->newhd(\*DATA, {filter =3D> 2});

my ($sender, $receiver);

while ($rdr->iterate) {
    if ($rdr->path eq '/Data/ConnectionList/Connection/Sender') {
        $sender =3D $rdr->value;
    }
    elsif ($rdr->path eq '/Data/ConnectionList/Connection/Receiver') {
        $receiver =3D $rdr->value;
    }
    elsif ($rdr->is_start
    and    $rdr->path =3D~ m{\A /Data/ConnectionList/Connection/
FileItemList/FileItem/FileType/ (\w+) \z}xms) {
        printf "Sender: %-5s, Receiver: %-5s, Type: %s\n",
          $sender, $receiver, $1;
    }
}

Here is the output

Sender: BRADD, Receiver: SHANE, Type: InitTAP
Sender: BRADD, Receiver: SHANE, Type: ReTxTAP
Sender: BRADD, Receiver: SHANE, Type: FatalRAP


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

Date: Tue, 20 Apr 2010 17:39:49 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Threads and Directory Handles
Message-Id: <hql6vo$ms2$1@news.eternal-september.org>

Graham Drabble wrote:
> Hi,
> 
> I've just finished debugging a problem with one of my modules and 
> whilst I've now got it fixed I don't really understand why it broke.

> 
> It looks as though the problem is that then open DIRHANDLE breaks 
> when the new thread is created but I don't really understand why. Any 
> ideas?
> 

perldoc perlopentut

handles are global to the package, so you can't open two different
directories on one dirhandle.  open will close an open handle before
opening a new file on it.  That means whatever the first opendir
associated with the handle in order to support readdir is now wrong.

closedir DIR is the wrong fix unless you know that another
thread hasn't already started and called opendir.  Using a lexical
variable to create a new anonymous handle instead of using DIR is
a better fix.  It also means that the dir is automatically closed
at the end of the sub.


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

Date: Wed, 21 Apr 2010 09:59:18 -0700 (PDT)
From: "david.karr" <davidmichaelkarr@gmail.com>
Subject: Trying to add exception handling, getting errors after adding  Error.pm to path
Message-Id: <845a96e8-3f1f-4ba1-9b66-6724724f213b@r27g2000yqn.googlegroups.com>

I'm trying to implement exception handling on operations calling
SVN::Client. I noticed that Error.pm wasn't in my include path, so I
looked for it (I'm on Cygwin), and I found it at the following
locations:

/usr/lib/perl5/5.10/CPANPLUS/Error.pm
/usr/lib/perl5/vendor_perl/5.10/YAML/Error.pm

So, I tried setting PERL5LIB to include that first directory.  After
adding that, I now get lots of errors, starting with this:

Global symbol "%Config" requires explicit package name at /usr/lib/
perl5/5.10/File/Copy.pm line 106.
Global symbol "%Config" requires explicit package name at /usr/lib/
perl5/5.10/File/Copy.pm line 106.
Global symbol "%Config" requires explicit package name at /usr/lib/
perl5/5.10/File/Copy.pm line 106.
Compilation failed in require at /usr/lib/perl5/5.10/CPANPLUS/
Internals/Utils.pm line 9.

My script starts with this:

#!/usr/bin/perl -w
# -*- mode: Perl; -*-
use SVN::Client;
use Getopt::Long;
use Error qw(:try);


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

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


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