[22558] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4779 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 28 18:11:08 2003

Date: Fri, 28 Mar 2003 15:10:16 -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           Fri, 28 Mar 2003     Volume: 10 Number: 4779

Today's topics:
        Match words between two files <sbour@niaid.nih.gov>
    Re: MIME Entity is looking for dumpskeleto.al (Matthias Jaekle)
    Re: MIME Entity is looking for dumpskeleto.al <tassilo.parseval@rwth-aachen.de>
        other CPAN search (was Re: CPAN Sloooooww) <uri@stemsystems.com>
    Re: other CPAN search (was Re: CPAN Sloooooww) <bigus NO @ SPAM creationfactor .net>
    Re: other CPAN search (was Re: CPAN Sloooooww) <tassilo.parseval@rwth-aachen.de>
        Perl CGI aplication on local host without Web server <dejan.tomazic@szkbanka.si>
    Re: Perl CGI aplication on local host without Web serve <noreply@gunnar.cc>
    Re: Perl modules. <jurgenex@hotmail.com>
    Re: Perl modules. <jurgenex@hotmail.com>
    Re: Perl modules. (Quantum Mechanic)
    Re: Perl/LWP Question <ethan@draupnir.gso.saic.com>
    Re: Perl/LWP Question <uri@stemsystems.com>
        print out multi queries <member17678@dbforums.com>
    Re: print out multi queries <glex_nospam@qwest.net>
        Putative bug inheriting private fields in fields/base p <tarik.alkasab@tufts.edu>
    Re: search and replace long hex string <dougkite@yahoo.com>
    Re: search and replace long hex string <dougkite@yahoo.com>
    Re: Sorting keys in a hash runs slower now. <grazz@nyc.rr.com>
    Re: Ugh. Better way to turn strings into trees. SOLUTIO <apollock11@hotmail.com>
    Re: why heredoc? was: Re: print here-documents question <mpapec@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 28 Mar 2003 11:15:59 -0500
From: Stephan Bour <sbour@niaid.nih.gov>
Subject: Match words between two files
Message-Id: <BAA9DF6F.69E4%sbour@niaid.nih.gov>

> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3131694960_8983328
Content-type: text/plain; charset="ISO-8859-1"
Content-transfer-encoding: 8bit

I¹ve looked all over my beginner books and I couldn't find any way to
compare two files for common words. I have an html file on one side with
someone¹s last name embedded in the code (not separated by white space). On
the other side I have a comma-delimited file used as a hash to match the
last name with a valid email address. Right now I use a fairly inflexible
regular expression split function to extract the name from the html and then
match it with the hash key. However, I was wondering whether I could skip
the split routine altogether by parsing the html file and have it look
directly in the hash file for a match. Is this possible?
Thank you,

Stephan.

--B_3131694960_8983328
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Match words between two files</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana">I&#8217;ve looked all over my beginner books and I cou=
ldn't find any way to compare two files for common words. I have an html fil=
e on one side with someone&#8217;s last name embedded in the code (not separ=
ated by white space). On the other side I have a comma-delimited file used a=
s a hash to match the last name with a valid email address. Right now I use =
a fairly inflexible regular expression split function to extract the name fr=
om the html and then match it with the hash key. However, I was wondering wh=
ether I could skip the split routine altogether by parsing the html file and=
 have it look directly in the hash file for a match. Is this possible?<BR>
Thank you,<BR>
<BR>
Stephan.</FONT>
</BODY>
</HTML>


--B_3131694960_8983328--



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

Date: 28 Mar 2003 12:06:04 -0800
From: foo.bar@jaekle.net (Matthias Jaekle)
Subject: Re: MIME Entity is looking for dumpskeleto.al
Message-Id: <e6a23a7a.0303281206.6915cfad@posting.google.com>

Hello,

> > But on my computer, there is no file called so. If just installed
> > MIME::Entity from CPAN. 
> Are you sure you installed it?
I did:
perl -MCPAN -e 'install MIME::Entity'
perl -MCPAN -e 'install Mail::Internet'

But there is no dumpskeleto.al on my system at all.

> Are you sure you didn't just unpack it and try to move the files into
> place by hand?
I also went to /root/.cpan/build/MIME-tools-5.411/ where the source
should be and manually run a perl Makefile.PL, make, make test and
make install.
But this file is missing. 
There must be real file dumpskeleto.al on my system. Correct ?

Any ideas ?

Many Thanks

Matthias


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

Date: 28 Mar 2003 21:51:26 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: MIME Entity is looking for dumpskeleto.al
Message-Id: <b62g4u$58k$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Matthias Jaekle:

> Hello,
> 
>> > But on my computer, there is no file called so. If just installed
>> > MIME::Entity from CPAN. 
>> Are you sure you installed it?
> I did:
> perl -MCPAN -e 'install MIME::Entity'
> perl -MCPAN -e 'install Mail::Internet'
> 
> But there is no dumpskeleto.al on my system at all.

I am hardly surprised. The method is called dump_skeleton(). Mind the
underscore.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Fri, 28 Mar 2003 21:29:42 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: other CPAN search (was Re: CPAN Sloooooww)
Message-Id: <x7he9n41tl.fsf_-_@mail.sysarch.com>

>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de> writes:

  TvP> Also sprach Bigus:
  >> Is it me or is the CPAN site incredibly slow the past few days?

  TvP> I wish it was. It hasn't been accessible for me at all during the past
  TvP> two days. I'm sure someone will look after that soon.

use a CPAN mirror for the archive and for searching CPAN use WAIT:

          http://theory.uwinnipeg.ca/SFgate/WAIT4CPAN.html

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 28 Mar 2003 21:31:17 -0000
From: "Bigus" <bigus NO @ SPAM creationfactor .net>
Subject: Re: other CPAN search (was Re: CPAN Sloooooww)
Message-Id: <Oa3ha.2313$8s6.18049@newsfep4-glfd.server.ntli.net>

"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7he9n41tl.fsf_-_@mail.sysarch.com...
> >>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de>
writes:
>
>   TvP> Also sprach Bigus:
>   >> Is it me or is the CPAN site incredibly slow the past few days?
>
>   TvP> I wish it was. It hasn't been accessible for me at all during the
past
>   TvP> two days. I'm sure someone will look after that soon.
>
> use a CPAN mirror for the archive and for searching CPAN use WAIT:
>
>           http://theory.uwinnipeg.ca/SFgate/WAIT4CPAN.html

Thanks. I tried a couple of mirrors but the Search feature that I was after
took me back to the dead CPAN one.

Regards
Bigus




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

Date: 28 Mar 2003 22:05:19 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: other CPAN search (was Re: CPAN Sloooooww)
Message-Id: <b62guv$5ps$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Uri Guttman:

>>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de> writes:
> 
>  TvP> Also sprach Bigus:
>  >> Is it me or is the CPAN site incredibly slow the past few days?
> 
>  TvP> I wish it was. It hasn't been accessible for me at all during the past
>  TvP> two days. I'm sure someone will look after that soon.
> 
> use a CPAN mirror for the archive and for searching CPAN use WAIT:
> 
>           http://theory.uwinnipeg.ca/SFgate/WAIT4CPAN.html

The alternative interfaces are, for me anyway, not so useful. One of the
features of search.cpan.org that I use most is to comfortably view the
sources of modules. A lot of modules look interesting to me from a
technical standpoint (that is: I have no use for them myself but would
love to know how they fullfill their magic).

That, and the convenient layout of search.cpan.org is still unmatched, I
think.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Fri, 28 Mar 2003 18:31:06 +0100
From: "dejan" <dejan.tomazic@szkbanka.si>
Subject: Perl CGI aplication on local host without Web server
Message-Id: <3e8487a0$1@news.perftech.si>

Hi!

I know it is possible to ran CGI perl application on localhost like some CD
distribution of HTML documentation.

I just need to know where I can find some tutorials or samples how to do it.

Please send me some links and have a nice day twice as much, as much again.

bye dejan




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

Date: Fri, 28 Mar 2003 18:24:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl CGI aplication on local host without Web server
Message-Id: <b621g7$u6io$1@ID-184292.news.dfncis.de>

dejan wrote:
> I know it is possible to ran CGI perl application on localhost ...

     http://www.indigostar.com/indigoperl.htm

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Fri, 28 Mar 2003 16:06:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl modules.
Message-Id: <jq_ga.162$gp1.95@nwrddc02.gnilink.net>

Phil Latio wrote:
> "Helgi Briem" <helgi@decode.is> wrote in message
> I don't have Perl on this Windows PC, only on my Linux server.

Then for your own and other peoples sake install it.
I don't understand how someone would insist on developing software in the
most complicated way by not being able to consult the documentation or even
to run a simple syntax check on his developement computer.
It's like boxing with both your hands tied behind your back.

jue




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

Date: Fri, 28 Mar 2003 16:08:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl modules.
Message-Id: <0s_ga.165$gp1.112@nwrddc02.gnilink.net>

Phil Latio wrote:
> It's a matter of company policy that you cannot install software,
> even if it's free. As you might have gathered I don't make a living
> out of programming in Perl (well not yet at least !!).

Then tell you boss that he is asking the impossible.
How are you supposed to develop software without having access to
documentation or a suitable development environment.

jue




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

Date: 28 Mar 2003 13:29:54 -0800
From: quantum_mechanic_1964@yahoo.com (Quantum Mechanic)
Subject: Re: Perl modules.
Message-Id: <f233f2f0.0303281329.58ffd75f@posting.google.com>

Ivan Marsh <annoyed@you.now> wrote in message news:<b61oop$rei$2@grandcanyon.binc.net>...
> I'm still wondering though, how do you add a new include directory to @INC 
> permanently? From the brief bits I read about it, it looked like it could 
> only be changed at compile time. I find that hard to believe.

For one value of "permanently"...

Set the environment variables PERLLIB or PERL5LIB, as in

    setenv PERLLIB /dir/one:/dir/two

-QM


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

Date: 28 Mar 2003 11:21:54 -0800
From: Ethan Brown <ethan@draupnir.gso.saic.com>
Subject: Re: Perl/LWP Question
Message-Id: <vrk7ejjnzh.fsf@draupnir.gso.saic.com>

>>>>> "Tony" == Tony Curtis <tony_curtis32@yahoo.com> writes:

    >>> On Fri, 28 Mar 2003 01:08:28 GMT,
    >>> "BSK" <mooncm.lbkejwiAhEgSfSe@dAcEbSaS> said:

    >> Hello All, I'm in the process of reading Sean Burke's
    >> book entitled "Perl & LWP" and I came across the
    >> following code on page 26:

    >> use LWP;
    >> my $browser;
    >> sub do_GET{
    >> $browser = LWP::UserAgent->new unless $browser;
    Tony>    ^^^

    Tony> I don't see why $browser is declared outside the sub, nor
    Tony> how it is initialised (note the test).  It should be
    Tony> my()ed here, or a parameter or possibly a class variable
    Tony> if it's coming from somewhere else.

This is a pretty common idiom.  When $browser is declared as 
my $browser;
it is undefined.  $browser gets set on the first call
to do_GET.  Subsequent calls skip the call to "new", since the 
state of $browser is maintained (it is outside the scope of the 
do_GET function).

This would be better written as:
BEGIN
{
    my $browser;
    sub do_GET{
    $browser = LWP::UserAgent->new unless $browser;
    ...
}

so that $browser is scoped only within the context of do_GET, instead
of being in the scope of the entire file.
 
--Ethan Brown
--Keyboards: "The Fabulous Pelicans" (www.pelicans.com)
--In a band?  Use http://www.WheresTheGig.com for free.



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

Date: Fri, 28 Mar 2003 21:28:01 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl/LWP Question
Message-Id: <x7k7ej41we.fsf@mail.sysarch.com>

>>>>> "EB" == Ethan Brown <ethan@draupnir.gso.saic.com> writes:

  >>> use LWP;
  >>> my $browser;
  >>> sub do_GET{
  >>> $browser = LWP::UserAgent->new unless $browser;
  Tony> ^^^

  Tony> I don't see why $browser is declared outside the sub, nor
  Tony> how it is initialised (note the test).  It should be
  Tony> my()ed here, or a parameter or possibly a class variable
  Tony> if it's coming from somewhere else.

  EB> This is a pretty common idiom.  When $browser is declared as 
  EB> my $browser;
  EB> it is undefined.  $browser gets set on the first call
  EB> to do_GET.  Subsequent calls skip the call to "new", since the 
  EB> state of $browser is maintained (it is outside the scope of the 
  EB> do_GET function).

  EB> This would be better written as:
  EB> BEGIN
  EB> {
  EB>     my $browser;
  EB>     sub do_GET{
  EB>     $browser = LWP::UserAgent->new unless $browser;
  EB>     ...
  EB> }

  EB> so that $browser is scoped only within the context of do_GET, instead
  EB> of being in the scope of the entire file.
 
no need for the BEGIN, a plain block will work fine there.

and since $browser is declared outside the sub it could also be
initialized there:

	my $browser = LWP::UserAgent->new ;

	sub do_GET { blah }

and no code need to be in the sub nor does it need to test if it has a
browser.

the only advantage of the initializing in the sub itself is 
that you don't allocate $browser if you never need to.

also another way to initialize only once (in the sub) is this:

	$browser ||= LWP::UserAgent->new ;

which i like better than the posted code.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 28 Mar 2003 17:57:30 +0000
From: Mario542 <member17678@dbforums.com>
Subject: print out multi queries
Message-Id: <2703583.1048874250@dbforums.com>


Does anyone know how to get a script to print two select queries at the
same time? It prints the first select but not the second. Maybe this
cann't be done.
Here is the code that I'm trying to use.


use DBI ;
use CGI ;
CGI::ReadParse ();
$dbName = "DBI:?";
 $user = "";
 $password = "";
 $statement ="select count (*) from Items where Item_StateID=1
  and Item_AvailabilityDate <= GETDATE()
  and Item_ExpirationDate > GETDATE()
 select count (*) from Items where Item_StateID=1";

  $dbh = DBI->connect($dbName, $user, $password) || die "$DBI::errstr";
  $cursor = $dbh->prepare($statement) || die "$DBI::errstr";
  $cursor->execute ;

print "<CENTER><H1>Title</H1>";
print "<BR>\n";
print "<TABLE BORDER=2>";

while (@data =$cursor ->fetchrow_array)


{
        print "<center><TR><TD><h4>$row</h2></TD><TD>@data</TD></TR>";

}

--
Posted via http://dbforums.com


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

Date: Fri, 28 Mar 2003 13:15:53 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: print out multi queries
Message-Id: <M81ha.42$XU3.35712@news.uswest.net>

Mario542 wrote:
> Does anyone know how to get a script to print two select queries at the
> same time? It prints the first select but not the second. Maybe this
> cann't be done.

You need 2 separate queries. Also, no need for the prepare if
you're not using placeholders.

See ya



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

Date: Fri, 28 Mar 2003 17:52:02 GMT
From: Tarik Alkasab <tarik.alkasab@tufts.edu>
Subject: Putative bug inheriting private fields in fields/base pragma in 5.8.0
Message-Id: <6Z%ga.15$zy2.547@news.tufts.edu>

I'm using the fields and base pragmata in 5.8.0 for some OO stuff I'm 
working on. I find the combination pretty elegant, and appreciate them 
very much.

However, I've encountered a small problem (that vexed me quite a bit 
until I figured out where the issue was). Specifically, if *all* of the 
fields in a super-class are private (i.e., their names start with 
underscores), then sub-classes fail to respect them when inheriting. The 
result is that new fields in the sub-class write themselves into the 
same pseudo-hash slots as the fields of the super class. If there is 
even *one* non-private field in the super-class, then the sub-class 
fields make room for *all* of the super-class fields (even the private 
ones).

The problem can be seen in the following two programs (output included 
after __END__):

   http://alfred.hsdb.tufts.edu/src/testfields.pl (broken)
   http://alfred.hsdb.tufts.edu/src/testfields2.pl (pseudo-fixed)

You can find my "perl -V" output at

   http://alfred.hsdb.tufts.edu/src/perl-V.txt

Is this a known problem? Is there a patch already available? If not, to 
whose attention should I bring it? It's not a big deal to work around 
("unused" field, anyone?), but it should probably be fixed.

Thanks,
Terry

--
Tarik Alkasab                             <tarik.alkasab@tufts.edu>
Senior Systems Architect                        Phone: 617-636-3912
Health Sciences Database Project                  Fax: 617-636-3805
Research Assistant Professor           http://alfred.hsdb.tufts.edu
Dept. of Fam. Med. and Comm. Health



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

Date: Fri, 28 Mar 2003 11:42:53 -0500
From: Doug Kite <dougkite@yahoo.com>
Subject: Re: search and replace long hex string
Message-Id: <b61u2e$u0n8$1@ID-77750.news.dfncis.de>

John W. Krahn wrote:
> It looks like you have an endian problem.  Instead of specifying an
> integer \x24F0 that may be translated to \xF024, specify the bytes
> individually.
> 
> perl -i -pe 's{\x24\xf0}{\x14\xf0}g' /foo/bar
> 
> Or even better, use positive look-ahead:
> 
> perl -i -pe 's{\x24(?=\xf0)}{\x14}g' /foo/bar
> 
> And positive look-behind:
> 
> perl -i -pe 's{(?<=\xb3\x01\x00\x16)\x24(?=\xf0)}{\x14}g' /foo/bar

I could not get any of these to work. Only the single byte hex replace 
will work.

Any other ideas?

I can send you a small chunk of the file for demonstration if you want.

Thanks for your help,
Doug



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

Date: Fri, 28 Mar 2003 13:07:02 -0500
From: Doug Kite <dougkite@yahoo.com>
Subject: Re: search and replace long hex string
Message-Id: <3E848F46.1040702@yahoo.com>



John W. Krahn wrote:
> Doug Kite wrote:
> 
>>How can you search and replace a long hex string in a binary file?
<snip>
> It looks like you have an endian problem.  Instead of specifying an
> integer \x24F0 that may be translated to \xF024, specify the bytes
> individually.
> 
> perl -i -pe 's{\x24\xf0}{\x14\xf0}g' /foo/bar
> 
> Or even better, use positive look-ahead:
> 
> perl -i -pe 's{\x24(?=\xf0)}{\x14}g' /foo/bar
> 
> And positive look-behind:
> 
> perl -i -pe 's{(?<=\xb3\x01\x00\x16)\x24(?=\xf0)}{\x14}g' /foo/bar

Finally got it by using tr{}{} instead of s{}{}g

I don't really understand it, but it worked.

Thanks again,
Doug



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

Date: Fri, 28 Mar 2003 16:53:48 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Sorting keys in a hash runs slower now.
Message-Id: <w6%ga.1391$Xf4.340@twister.nyc.rr.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> 
> For one, even integers are stored and processed as floats 
> (unless you "use integer").
>

I heard that rumor, too, but:

  ~ > perl -MDevel::Peek -e 'Dump my $x = 2'
  SV = IV(0x814b300) at 0x813cfe8
    REFCNT = 1
    FLAGS = (PADBUSY,PADMY,IOK,pIOK)
    IV = 2

Would've thought that IV gets promoted to NV as late as 
possible (e.g. on overflow or "/=" or similar).

-- 
Steve


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

Date: Fri, 28 Mar 2003 12:45:25 -0800
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Re: Ugh. Better way to turn strings into trees. SOLUTION!
Message-Id: <b62c99$2i9b$1@agate.berkeley.edu>

Arvin Portlock wrote:

> Ideally I would like to turn a flat series of hash keys into
> a tree structure:
>
> "NAME-1"
> "NAME-1-1"
> "NAME-1-2"
> "NAME-1-3"
> "NAME-1-3-1"
>
I left this alone for a few weeks and returning back to it the
solution seemed so easy and natural. I dreamed about it a couple
of times (very strange, interesting, and tedious dreams) and I'm
certain this helped me figure out the solution. That happens to
me a lot. The only change to the requirements I made was to pad
the numbers with a zero. I could have done that in the sort
subroutine but I thought it was a better solution to put it in
the raw data instead. I've pasted the complete solution below.
I didn't need to go through an intermediate stage as I was prepared
to do. I was able to build my tree directly from the raw data.

This, by the way, is for a generic web template program. Where any
kind of HTML form can be generated from templates and the form
elements will be transformed into XML markup also embedded in the
templates. I wanted to make it purely generic so that it would work
with any kind of DTD or schema and any kind of HTML form. The program
allows for importing extension files that do more sophisticated
processing of the data through user-defined scripts, but I wanted to
put as much functionality in the templates themselves so they would
naturally do things like recognize hierarchical data and encode them
into hierarchical XML without the need for scripting.

Here then is my test script:

%Data = ( 'DATA-03-01-01-03:FIELD1' => 'Data-03-01-01-03',
           'DATA-01-03:FIELD1' => 'Data-01-03',
           'DATA-03-03:FIELD1' => 'Data-03-03',
           'DATA-01-04-01:FIELD1' => 'Data-01-04-01',
           'DATA-02:FIELD1' => 'Data-02',
           'DATA-02:FIELD2' => 'Data-02',
           'DATA-02:FIELD3' => 'Data-02',
           'DATA-03-01-01:FIELD1' => 'Data-03-01-01',
           'DATA-01-01:FIELD1' => 'Data-01-01',
           'DATA-03-01-01-01:FIELD1' => 'Data-03-01-01-01',
           'DATA-01-01-01:FIELD1' => 'Data-01-01-01',
           'DATA-01-04:FIELD1' => 'Data-01-04',
           'DATA:FIELD1' => 'Data:Field1',
           'DATA:FIELD2' => 'Data:Field2',
           'DATA-03-01:FIELD1' => 'Data-03-01',
           'DATA-01-02:FIELD1' => 'Data-01-02',
           'DATA-01-01-02:FIELD1' => 'Data-01-01-02',
           'DATA-03:FIELD1' => 'Data-03',
           'DATA-03-01-02:FIELD1' => 'Data-03-01-02',
           'DATA-01-04-02:FIELD1' => 'Data-01-04-02',
           'DATA-01:FIELD1' => 'Data-01',
           'DATA-01-01-03:FIELD1' => 'Data-01-01-03',
           'DATA-03-01-01-02:FIELD1' => 'Data-03-01-01-02',
           'DATA-03-01-01-02:FIELD2' => 'Data-03-01-01-02',
           'DATA-03-01-01-02:FIELD3' => 'Data-03-01-01-02',
           'DATA-03-02:FIELD1' => 'Data-03-02');

foreach my $key (sort by_prefix keys %Data) {
    my $field;
    $key =~ /:([^:]+)/ && ($field = $1);
    my $var_name;
    $key =~ /^([A-Z0-9_]+)/ && ($var_name = $1);
    my $value = $Data{$key};
    my $node = {};
    $node->{fields}->{$field} = $value;
    $node->{key} = $key;
    $node->{level} = ($key =~ tr/-/-/ + 1);
    &BuildTree ($node, $var_name);
}

&Recurse ($VarTree{DATA});

sub by_prefix {
    my $temp_a = $a;
    my $temp_b = $b;
    $temp_a =~ s/:[^:]+//;
    $temp_b =~ s/:[^:]+//;
    if ($temp_a gt $temp_b) {
       return 1;
    } elsif ($temp_b gt $temp_a) {
       return -1;
    } else {
       return 0;
    }
}

sub Recurse {
    my $node= shift;
    if ($node) {
       print "  " x ($node->{level} - 1);
       print $node->{key}, "\n";
       &Recurse ($node->{sub}, $sub);
       &Recurse ($node->{next}, $sub);
    }
}

sub BuildTree {
    my ($node, $var_name) = @_;
    my $level = $node->{level};
    $VarTree{$var_name} = $node unless $VarTree{$var_name};
    if (@Stack) {
       if ($level <= $Stack[$#Stack]->{level}) {
          my $i = ($#Stack + 1) - $level;
          while ($i > 0) {
             my $item = pop @Stack;
             $i--;
          }
          $Stack[$#Stack]->{next} = $node;
          pop @Stack;
          push @Stack, $node;
       } else {
          $Stack[$#Stack]->{sub} = $node;
          push @Stack, $node;
       }
    } else {
       push @Stack, $node;
    }
}


The Recurse subroutine produces the following output (Yay!):

DATA:FIELD2
DATA:FIELD1
   DATA-01:FIELD1
     DATA-01-01:FIELD1
       DATA-01-01-01:FIELD1
       DATA-01-01-02:FIELD1
       DATA-01-01-03:FIELD1
     DATA-01-02:FIELD1
     DATA-01-03:FIELD1
     DATA-01-04:FIELD1
       DATA-01-04-01:FIELD1
       DATA-01-04-02:FIELD1
   DATA-02:FIELD3
   DATA-02:FIELD1
   DATA-02:FIELD2
   DATA-03:FIELD1
     DATA-03-01:FIELD1
       DATA-03-01-01:FIELD1
         DATA-03-01-01-01:FIELD1
         DATA-03-01-01-02:FIELD2
         DATA-03-01-01-02:FIELD1
         DATA-03-01-01-02:FIELD3
         DATA-03-01-01-03:FIELD1
       DATA-03-01-02:FIELD1
     DATA-03-02:FIELD1
     DATA-03-03:FIELD1










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

Date: Fri, 28 Mar 2003 23:38:07 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: why heredoc? was: Re: print here-documents question
Message-Id: <emj98vs03kce4cr5sljccu5m8os8go3gmk@4ax.com>

X-Ftn-To: Tad McClellan 

tadmc@augustmail.com (Tad McClellan) wrote:
>> IMO, it looks terribly ugly; 
>
>That depends on what is in the string that you are quoting.
>
>I think this is harder to read than the above:
>
>  print "var newLine = unescape(\"%0A\")";
>  print "alert(\"The correct email format is : \"  + newLine + \"username\@domain.extension\")";
>
>
>Here docs are WYSIWYGish.

Yes, but Perl quoting mechanism is even more WYSIWYG!(qq{} q{})
Here doc in great manner resembles shell scripting and just looks awful.

>> is there any reason why Perl manuals still use
>> it like an example of printing multiple lines?
>
>What example are you referring to?

I'm not referring to particular example(can't find one right now :)), you
just run into them now and then.



-- 
Matija


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

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.  

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


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