[30377] in Perl-Users-Digest
Perl-Users Digest, Issue: 1620 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 8 09:10:14 2008
Date: Sun, 8 Jun 2008 06:09:07 -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, 8 Jun 2008 Volume: 11 Number: 1620
Today's topics:
Re: FAQ 5.38 How do I select a random line from a file? <ben@morrow.me.uk>
Re: FAQ 5.38 How do I select a random line from a file? <danrumney@warpmail.new>
Re: FAQ 5.38 How do I select a random line from a file? <ced@blv-sam-01.ca.boeing.com>
Re: FAQ 5.38 How do I select a random line from a file? <ced@blv-sam-01.ca.boeing.com>
Re: FAQ 5.5 How can I copy a file? <bill@ts1000.us>
Re: Few questions about arguments and subroutines/modul <rkb@i.frys.com>
Re: Few questions about arguments and subroutines/modul <jurgenex@hotmail.com>
Re: File Locked After Close? <bill@ts1000.us>
how to change the date format of all my htmls? <robertchen117@gmail.com>
Re: how to change the date format of all my htmls? <RedGrittyBrick@SpamWeary.foo>
new CPAN modules on Sun Jun 8 2008 (Randal Schwartz)
Re: Performance on Windows: Cygwin is much faster. Why? <dutch@example.com>
Self extractor in perl <jismagic@gmail.com>
Re: XML::Parser Tree Style <benkasminbullock@gmail.com>
Re: XML::Parser Tree Style sln@netherlands.co
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 8 Jun 2008 02:14:50 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <adorh5-47o1.ln1@osiris.mauzo.dyndns.org>
Quoth brian d foy <brian.d.foy@gmail.com>:
>
[random line from a file]
> The solution that I think about (but have never implemented), is some
> sort of pre-indexing of line endings so you have a list of file
> positions where all the lines line (or start, or whatever). When you
> want a random line, you choose a random element from that list. Open
> the file, seek, and read a line.
Isn't that called Tie::File, perhaps slightly modified to make the
offset cache persistant?
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
Date: Sat, 07 Jun 2008 21:35:51 -0400
From: Dan Rumney <danrumney@warpmail.new>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <484b3781$0$5735$4c368faf@roadrunner.com>
brian d foy wrote:
> In article <484adab2$0$30196$4c368faf@roadrunner.com>, Dan Rumney
> <danrumney@warpmail.new> wrote:
>
>> Peter J. Holzer wrote:
>>> On 2008-06-04 19:03, PerlFAQ Server <brian@stonehenge.com> wrote:
>>>> 5.38: How do I select a random line from a file?
>
>
>
>>> If your file is large, and the lines are roughly of equal length, it is
>>> probably preferrable to just do a random seek into the file and read the
>>> line you've hit (by searching backwards and forwards for $/).
>
>> The problem with that is that the probability of selecting a line
>> becomes a function of that line's length.
>>
>> The algorithm above ensures that the probability of selecting a line is
>> precisely 1/N where N is the total number of lines in the file.
>
> From time to time, I think about how I would solve this problem if I
> actually needed it for something important. That is, not as some
> thought experiment or quote-for-the-sig thing.
>
> Has anyone solved this for something non-trivial? Say, for something
> with huge numbers of lines or large file sizes, or where you want to
> choose several random lines?
A simplistic solution might me:
my %linePostiion;
$linePostion{$.} = tell($fh) while <$fh>;
Then use %linePosition with a random index to find the file position of
a random line.
Probably needs some refinement, but the big question is whether this
costs more or less then Knuth's algorithm.
I imagine that it costs more for a single line. The big question is, how
many random line requests does it take before it becomes cheaper?
------------------------------
Date: Sat, 7 Jun 2008 20:00:23 -0700 (PDT)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <2c2fc0f7-9db5-4596-b7bd-41355d2a56e4@t12g2000prg.googlegroups.com>
On Jun 7, 6:35 pm, Dan Rumney <danrum...@warpmail.new> wrote:
> brian d foy wrote:
> > In article <484adab2$0$30196$4c368...@roadrunner.com>, Dan Rumney
> > <danrum...@warpmail.new> wrote:
>
> >> Peter J. Holzer wrote:
> >>> On 2008-06-04 19:03, PerlFAQ Server <br...@stonehenge.com> wrote:
> >>>> 5.38: How do I select a random line from a file?
>
> >>> If your file is large, and the lines are roughly of equal length, it is
> >>> probably preferrable to just do a random seek into the file and read the
> >>> line you've hit (by searching backwards and forwards for $/).
>
> >> The problem with that is that the probability of selecting a line
> >> becomes a function of that line's length.
>
> >> The algorithm above ensures that the probability of selecting a line is
> >> precisely 1/N where N is the total number of lines in the file.
>
> > From time to time, I think about how I would solve this problem if I
> > actually needed it for something important. That is, not as some
> > thought experiment or quote-for-the-sig thing.
>
> > Has anyone solved this for something non-trivial? Say, for something
> > with huge numbers of lines or large file sizes, or where you want to
> > choose several random lines?
>
> A simplistic solution might me:
>
> my %linePostiion;
>
> $linePostion{$.} = tell($fh) while <$fh>;
> Then use %linePosition with a random index to find the file position of
> a random line.
A tad faster to just index into
a simple array of file positions:
push @pos, tell($fh) while <$fh>;
> ...
--
Charles DeRykus
------------------------------
Date: Sat, 7 Jun 2008 20:08:10 -0700 (PDT)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <f58dd534-e29c-47c0-b599-eab85c87f6a0@v1g2000pra.googlegroups.com>
On Jun 7, 8:00 pm, "comp.llang.perl.moderated" <c...@blv-
sam-01.ca.boeing.com> wrote:
> On Jun 7, 6:35 pm, Dan Rumney <danrum...@warpmail.new> wrote:
>
>
>
> > brian d foy wrote:
> > > In article <484adab2$0$30196$4c368...@roadrunner.com>, Dan Rumney
> > > <danrum...@warpmail.new> wrote:
>
> > >> Peter J. Holzer wrote:
> > >>> On 2008-06-04 19:03, PerlFAQ Server <br...@stonehenge.com> wrote:
> > >>>> 5.38: How do I select a random line from a file?
>
> > >>> If your file is large, and the lines are roughly of equal length, it is
> > >>> probably preferrable to just do a random seek into the file and read the
> > >>> line you've hit (by searching backwards and forwards for $/).
>
> > >> The problem with that is that the probability of selecting a line
> > >> becomes a function of that line's length.
>
> > >> The algorithm above ensures that the probability of selecting a line is
> > >> precisely 1/N where N is the total number of lines in the file.
>
> > > From time to time, I think about how I would solve this problem if I
> > > actually needed it for something important. That is, not as some
> > > thought experiment or quote-for-the-sig thing.
>
> > > Has anyone solved this for something non-trivial? Say, for something
> > > with huge numbers of lines or large file sizes, or where you want to
> > > choose several random lines?
>
> > A simplistic solution might me:
>
> > my %linePostiion;
>
> > $linePostion{$.} = tell($fh) while <$fh>;
> > Then use %linePosition with a random index to find the file position of
> > a random line.
>
> A tad faster to just index into
> a simple array of file positions:
>
> push @pos, tell($fh) while <$fh>;
Simpler but I made a kneejerk assertion that it's
faster... just suspect in lots of cases, it will be.
--
Charles DeRykus
------------------------------
Date: Sun, 8 Jun 2008 04:01:17 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: FAQ 5.5 How can I copy a file?
Message-Id: <9b0f424f-c102-4163-9fc8-8e340d976dae@m3g2000hsc.googlegroups.com>
On Jun 7, 3:03=A0pm, PerlFAQ Server <br...@stonehenge.com> wrote:
> This is an excerpt from the latest version perlfaq5.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> --------------------------------------------------------------------
>
> 5.5: How can I copy a file?
>
> =A0 =A0 (contributed by brian d foy)
>
> =A0 =A0 Use the File::Copy module. It comes with Perl and can do a true co=
py
> =A0 =A0 across file systems, and it does its magic in a portable fashion.
>
> =A0 =A0 =A0 =A0 =A0 =A0 use File::Copy;
>
> =A0 =A0 =A0 =A0 =A0 =A0 copy( $original, $new_copy ) or die "Copy failed: =
$!";
>
> =A0 =A0 If you can't use File::Copy, you'll have to do the work yourself: =
open
> =A0 =A0 the original file, open the destination file, then print to the
> =A0 =A0 destination file as you read the original.
What is the advantage of using this over using system("cp $original
$new_copy"); (or system("copy $original $new_copy"); on windows)? Is
it faster or is it just "perlish"? Or am I missing something obvious?
Bill H
PS When did Google Groups drop the captcha?
------------------------------
Date: Sat, 7 Jun 2008 18:21:13 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Few questions about arguments and subroutines/modules
Message-Id: <a042fd98-e1a3-4e8a-97a4-281bad1118e4@q24g2000prf.googlegroups.com>
On Jun 7, 3:50 pm, Telemach <telem...@go2.pl> wrote:
> I'm newbie who is looking for some online tutorial about advanced use
> of arguments for subroutines and modules.
>
> Let's say I have a script that would take 3 arguments
>
> first - single word
> second - sentence
> third - path
>
> additional one that would display help
>
> How to :
>
> - declare a default value for first argument if not provided by user
> - allow input of the full sentence ; right now script takes only the
> first word from sentence
> - create a condition that would for example : download a certain file
> if third argument (which is a path) is provided, no argument shall not
> trigger download
> - display help after running for example example.pl -h
>
> I was browsing thru different tutorials but haven't yet found answers
> to above.
>
> - Telemach -
The documentation for these modules should be clear enough to be used
as tutorials.
http://search.cpan.org/~jv/Getopt-Long-2.37/lib/Getopt/Long.pm
http://search.cpan.org/~rgarcia/perl-5.10.0/lib/Getopt/Std.pm
http://search.cpan.org/~rsavage/Getopt-Simple-1.49/lib/Getopt/Simple.pm
------------------------------
Date: Sun, 08 Jun 2008 06:59:52 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Few questions about arguments and subroutines/modules
Message-Id: <k00n4494htiem7sk326dbg2vq0notncpnc@4ax.com>
Telemach <telemach@go2.pl> wrote:
>
>I'm newbie who is looking for some online tutorial about advanced use
>of arguments for subroutines and modules.
>
>Let's say I have a script that would take 3 arguments
I am confused. Are you talking about arguments that are passed to
functions/subroutines as you said 3 lines above or arguments passed to
the script from the command line as you said in previous line?
>first - single word
>second - sentence
>third - path
>additional one that would display help
Your design has several problems which are not specific to Perl but are
generic for any comannd line parameters.
>How to :
>- declare a default value for first argument if not provided by user
In general you would do something like
if (defined $ARGV[0]) {
$myvalue = shift @ARGV;
} else {
$myvalue = 'whateverdefaultvalueyoulike'
}
(there are shorter idioms using the same idea).
However because of the way you designed your parameters there is no easy
way to recognize if the first argument is missing or not. Even counting
the arguments doesn't help because you still wouldn't know if the first
or the last argument were omitted.
My suggestion would be to rethink the way you pass arguments and use a
style like e.g.
myprog.pl -w=word -s="Whatever Sentence you want" -f=filename
>- allow input of the full sentence ; right now script takes only the
>first word from sentence
This has probably nothing to do with Perl but everything with your
shell. All shells I know of will pass individual words as separate
arguments unless you enclose them in quotes. Details vary somewhat from
shell to shell.
>- create a condition that would for example : download a certain file
>if third argument (which is a path) is provided, no argument shall not
>trigger download
Same as above for an omitted first argument.
>- display help after running for example example.pl -h
Catch a '-h' as first argument first before doing any other analysis of
the commandline.
jue
------------------------------
Date: Sun, 8 Jun 2008 03:46:48 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: File Locked After Close?
Message-Id: <703e9a43-75d0-4b2d-81a2-4cdd063efaff@79g2000hsk.googlegroups.com>
On Jun 7, 3:37=A0pm, xmp...@yahoo.com wrote:
> Hi,
>
> The last line of the following code snippet fails:
>
> open FILE, '<file.dat' || die '...';
> process(FILE);
> close FILE;
> system('command file.dat');
>
> It looks like FILE is still locked because if I break out the last
> line into a separate script, it works. =A0In fact, if I open FILE on
> another file, the last line also works. =A0I'd like to fix the issue
> with something more elegant than re-opening the handle on a dummy
> file.
>
> Any suggestions? =A0I'm using ActiveState Perl on Windows running in a
> DOS shell.
>
> Thanks.
I believe this is more a function of Windows. I have had similiar
experiences with other software. If I open a in some programs just to
view it I find that I can't u/l it to a server with an ftp program
cause it is locked. When I close it I can.
I think the same thing is happening here, when you do the "system"
command windows is starting a new instance of command this new
instance cant access the file cause your original instance is "using"
the file.
If your perl code isn't doing anything after you make file.dat maybe
you could have an initial batch file that runs the perl script then
runs the file.dat pert after perl has exited.
Bill H
------------------------------
Date: Sat, 7 Jun 2008 20:31:45 -0700 (PDT)
From: "robertchen117@gmail.com" <robertchen117@gmail.com>
Subject: how to change the date format of all my htmls?
Message-Id: <4d396361-d145-4d37-9cbd-eb35576f441a@i18g2000prn.googlegroups.com>
I have many html files in my directory, I want to change all date with
dd/mm/yy format to /mm/dd/yyyy in the files.
Please let me know how to do it in perl...
thanks
------------------------------
Date: Sun, 08 Jun 2008 13:26:35 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: how to change the date format of all my htmls?
Message-Id: <XJydnegXO7NmUtbVnZ2dneKdnZydnZ2d@bt.com>
robertchen117@gmail.com wrote:
> I have many html files in my directory, I want to change all date with
> dd/mm/yy format to /mm/dd/yyyy in the files.
>
> Please let me know how to do it in perl...
>
> thanks
On Unix something like
perl -p -i -e 's|(\d\d)/(\d\d)/(\d\d)|"$2/$1/".($3<50?20:19).$3|eg' \ *.html
As I expect you know, on MS Windows you have to use -e'' instead of -e""
which means I usually change the inner "foo" to qq(foo).
--
RGB
------------------------------
Date: Sun, 8 Jun 2008 04:42:18 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Jun 8 2008
Message-Id: <K24nqI.1Ky4@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Config-INI-MVP-Reader-0.018
http://search.cpan.org/~rjbs/Config-INI-MVP-Reader-0.018/
multi-value capable .ini file reader (for plugins)
----
Config-Mini-0.03
http://search.cpan.org/~jhiver/Config-Mini-0.03/
Very simple INI-style configuration parser
----
Data-Omap-0.05
http://search.cpan.org/~bbaxter/Data-Omap-0.05/
Perl module to implement ordered mappings
----
Data-Pairs-0.05
http://search.cpan.org/~bbaxter/Data-Pairs-0.05/
Perl module to implement ordered mappings with possibly duplicate keys.
----
Data-Section-0.001
http://search.cpan.org/~rjbs/Data-Section-0.001/
read multiple hunks of data out of your DATA section
----
Data-Section-0.002
http://search.cpan.org/~rjbs/Data-Section-0.002/
read multiple hunks of data out of your DATA section
----
Fuse-PDF-0.09
http://search.cpan.org/~cdolan/Fuse-PDF-0.09/
Filesystem embedded in a PDF document
----
Glib-Ex-ConnectProperties-2
http://search.cpan.org/~kryde/Glib-Ex-ConnectProperties-2/
link properties between objects
----
Google-AJAX-Library-0.02
http://search.cpan.org/~rkrimen/Google-AJAX-Library-0.02/
Access the Google AJAX Libaries API in Perl
----
Gtk2-Ex-Clock-4
http://search.cpan.org/~kryde/Gtk2-Ex-Clock-4/
simple digital clock widget
----
List-Compare-0.37
http://search.cpan.org/~jkeenan/List-Compare-0.37/
Compare elements of two or more lists
----
List-oo-v0.2.1
http://search.cpan.org/~ewilhelm/List-oo-v0.2.1/
object interface to list (array) methods
----
Log-Fine-0.14
http://search.cpan.org/~cfuhrman/Log-Fine-0.14/
Yet another logging framework
----
OpenGuides-0.62
http://search.cpan.org/~dom/OpenGuides-0.62/
A complete web application for managing a collaboratively-written guide to a city or town.
----
POE-Component-Pool-DBI-0.01
http://search.cpan.org/~tag/POE-Component-Pool-DBI-0.01/
Simplified DBI access through a pooled resource.
----
Parse-BooleanLogic-0.03
http://search.cpan.org/~ruz/Parse-BooleanLogic-0.03/
parser of boolean expressions
----
PerlIO-Util-0.40
http://search.cpan.org/~gfuji/PerlIO-Util-0.40/
A selection of general PerlIO utilities
----
PerlIO-Util-0.41
http://search.cpan.org/~gfuji/PerlIO-Util-0.41/
A selection of general PerlIO utilities
----
Regexp-Assemble-0.33
http://search.cpan.org/~dland/Regexp-Assemble-0.33/
Assemble multiple Regular Expressions into a single RE
----
SVG-Calendar-0.0.6
http://search.cpan.org/~ivanwills/SVG-Calendar-0.0.6/
Creates calendars in SVG format which can be printed
----
Software-License-0.006
http://search.cpan.org/~rjbs/Software-License-0.006/
packages that provide templated software licenses
----
Sys-Info-0.52_2
http://search.cpan.org/~burak/Sys-Info-0.52_2/
Fetch information from the host system
----
Test-A8N-0.05
http://search.cpan.org/~nachbaur/Test-A8N-0.05/
Storytest Automation Runner
----
Test-U32-0.01
http://search.cpan.org/~jfreeman/Test-U32-0.01/
Designed to test the proposition that U32 is 32 bits wide
----
Time-Piece-MySQL-0.06
http://search.cpan.org/~kasei/Time-Piece-MySQL-0.06/
Adds MySQL-specific methods to Time::Piece
----
Win32-PowerPoint-0.08_01
http://search.cpan.org/~ishigaki/Win32-PowerPoint-0.08_01/
helps to convert texts to PP slides
----
YAML-LibYAML-0.27
http://search.cpan.org/~ingy/YAML-LibYAML-0.27/
----
lib-0.57
http://search.cpan.org/~smueller/lib-0.57/
manipulate @INC at compile time
----
version-0.75
http://search.cpan.org/~jpeacock/version-0.75/
Perl extension for Version Objects
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Sun, 8 Jun 2008 10:49:01 +0200
From: "Dutch" <dutch@example.com>
Subject: Re: Performance on Windows: Cygwin is much faster. Why?
Message-Id: <484b9cfe$0$14353$e4fe514c@news.xs4all.nl>
"Ben Morrow" <ben@morrow.me.uk> wrote:
>
> This means that all intermediate results are IVs, which in this case
> are 64bit C long longs. Integer arithmetic is much faster than floating-
> point arithmetic [...], so that's why cygwin is faster.
I can understand how this works, thanks for the explanation.
> AFAICT, it is not possible to build a perl for Win32 with the
> equivalent of use64bitint, the way the cygwin perl is built, so if you
> need speed, either get a 64bit processor and OS and build a 64bit perl
> or stick to cygwin.
The performance isn't a problem, I just thought it was rather strange that
one was twice as fast on the same hardware. I will be migrating away from
Windows anyway (unrelated to this issue).
Thanks for teaching me something about the inner workings of Perl! ;-)
I'm guessing the benchmarks with the different versions of Perl on Windows
aren't necessary anymore as the mystery is solved. However, if anyone really
wants to see the results, I'll do it and will post here. Just let me know.
Dutch
------------------------------
Date: Sun, 8 Jun 2008 01:21:33 -0700 (PDT)
From: jis <jismagic@gmail.com>
Subject: Self extractor in perl
Message-Id: <a5c967e4-cad6-4ebe-8990-b92b9d2c0448@v26g2000prm.googlegroups.com>
I want to attach files along with th e exe i generate using perl. is
it possible for me to implement this.pls guide.
jis
------------------------------
Date: Sun, 8 Jun 2008 01:48:40 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: XML::Parser Tree Style
Message-Id: <g2fdpo$58o$1@ml.accsnet.ne.jp>
On Sat, 07 Jun 2008 19:19:23 +0200, Peter J. Holzer wrote:
> First parsing one text format into a tree, then serializing the tree
> into a different text format, and finally parsing that text format using
> regexes is really evil.
Yes! I had assumed that readers of the newsgroup would pick up on that
point and immediately jump to the conclusion that I was being facetious.
The original poster's problem was more to do with not understanding array
references, and I also posted a fairly carefully structured answer to
that, which I'll take the liberty of repeating here, minus one extraneous
bit of code:
#!/usr/bin/perl
use strict;
use warnings;
use XML::Parser;
use Data::Dumper;
my $xml=<<EOF;
<?xml version='1.0' encoding='UTF-8'?>
<list name="Nialls list">
<person>
<firstname>Niall</firstname>
<lastname>Carter</lastname>
<age>24</age>
</person>
<person>
<firstname>Ruth</firstname>
<lastname>Brewster</lastname>
<age>22</age>
</person>
<person>
<firstname>Cas</firstname>
<lastname>Creer</lastname>
<age>23</age>
</person>
</list>
EOF
my $p = new XML::Parser( Style => 'Tree' );
my $tree = $p->parse($xml);
my $depth = 0;
sub recursively_descend
{
$depth++;
my $indent = ' 'x$depth;
my ($thing) = @_;
if (!ref($thing)) {
if ($thing =~ /^\s+$/) {
print "whitespace\n";
} else {
print "'$thing'\n";
}
} elsif (ref($thing) eq 'ARRAY') {
print "ARRAY\n";
my $count = 0;
for my $k (@{$thing}) {
print $indent,"$count:";
recursively_descend ($k);
$count++;
}
} elsif (ref($thing) eq 'HASH') {
my @k = keys %{$thing};
if (@k) {
print "HASH: keys @k\n";
} else {
print "HASH: empty\n";
}
for my $b (@k) {
print $indent,"$b:";
recursively_descend ($$thing{$b});
}
} elsif (ref($thing) eq 'SCALAR') {
print "SCALAR '$$thing'\n";
}
$depth--;
}
recursively_descend ($tree);
It doesn't actually print out an answer to the original poster's
question, but running the above and carefully studying it would lead him
to a solution.
> Besides, it doesn't work. Consider
> <firstname>Mary-Ann</firstname>, for which your code prints "Ann\n".
I had no expectation that it would work beyond the three examples given.
It is a deliberately atrociously bad solution to the problem, like a
solution of matching whether number A is in a range of numbers B and C
using regexes only.
------------------------------
Date: Sat, 07 Jun 2008 21:06:58 -0700
From: sln@netherlands.co
Subject: Re: XML::Parser Tree Style
Message-Id: <8lmm44pu5b0e2dnjm7opdf475k9gcnjupp@4ax.com>
On Sun, 8 Jun 2008 01:48:40 +0000 (UTC), Ben Bullock <benkasminbullock@gmail.com> wrote:
>On Sat, 07 Jun 2008 19:19:23 +0200, Peter J. Holzer wrote:
>
>> First parsing one text format into a tree, then serializing the tree
>> into a different text format, and finally parsing that text format using
>> regexes is really evil.
>
>Yes! I had assumed that readers of the newsgroup would pick up on that
>point and immediately jump to the conclusion that I was being facetious.
>The original poster's problem was more to do with not understanding array
>references, and I also posted a fairly carefully structured answer to
>that, which I'll take the liberty of repeating here, minus one extraneous
>bit of code:
>
Why don't you use the advanced features of RegexParse 1.3
Sln
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1620
***************************************