[31828] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3091 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 22 00:09:22 2010

Date: Sat, 21 Aug 2010 21:09:04 -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           Sat, 21 Aug 2010     Volume: 11 Number: 3091

Today's topics:
    Re: ActivePerl Migration Win 2003 Server to Win 2008 Se <m@rtij.nl.invlalid>
    Re: Help with regular expression <markhobley@yahoo.donottypethisbit.co>
    Re: I HACK $3500 FROM PAYPAL... <stevem_@nogood.com>
        Multi-level list generation <tuxedo@mailinator.com>
    Re: Multi-level list generation <stevem_@nogood.com>
    Re: Multi-level list generation <jurgenex@hotmail.com>
    Re: Multi-level list generation <tuxedo@mailinator.com>
    Re: Multi-level list generation <tuxedo@mailinator.com>
    Re: Multi-level list generation <stevem_@nogood.com>
    Re: Multi-level list generation <cartercc@gmail.com>
    Re: Multi-level list generation <uri@StemSystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 22 Aug 2010 00:11:58 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: ActivePerl Migration Win 2003 Server to Win 2008 Server
Message-Id: <eiv5k7-slo.ln1@news.rtij.nl>

On Sat, 21 Aug 2010 10:31:15 +0200, Mart van de Wege wrote:

> Heh. If only. Experience tells me that there is always a chance that
> something that worked in testing falls flat in production.

In some environments where I work, it is more than "a chance". :-)

M4


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

Date: Sat, 21 Aug 2010 23:43:21 +0000 (UTC)
From: Mark Hobley <markhobley@yahoo.donottypethisbit.co>
Subject: Re: Help with regular expression
Message-Id: <i4poan$1n78$1@adenine.netfront.net>

On Tue, 03 Aug 2010 10:54:26 -0500, Ted Zlatanov wrote:

> I don't think even a grammar will help.  The requirements are
> fundamentally broken because there's more than one way to interpret
> nested parens.  The OP should explain what he's trying to do and give
> real-world examples he needs parsed.

I was basically looking for a regular expression to include in checkbashisms
for the purpose of detecting double parenthesis shell arithmetic, preventing
false positives, if possible.

Mark.

-- 
Mark Hobley
Linux User: #370818  http://markhobley.yi.org/


--- news://freenews.netfront.net/ - complaints: news@netfront.net ---


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

Date: Sat, 21 Aug 2010 14:30:56 -0500
From: Steve <stevem_@nogood.com>
Subject: Re: I HACK $3500 FROM PAYPAL...
Message-Id: <UBXbo.90768$xZ2.54541@newsfe07.iad>

On 08/21/2010 12:47 PM, Ben Morrow wrote:
>
> Quoth Hot Hot Hot<m.appalakonda@gmail.com>:
>> I HACK $3500 FROM PAYPAL  At http://XXXXXXXXXXXX
>>
>> i have hidden the PAYPAL FORM link in an image.
>> in that website on Right Side below search box, click
>> on image and enter your name and PAYPAL ID.
>
> Good God, that's a bit desparate, isn't it?
>
> Ben
>

And the sad part is some (nobody here, I hope) people might fall for it...

\s


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

Date: Sat, 21 Aug 2010 21:04:28 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Multi-level list generation
Message-Id: <i4p7vs$9eo$02$1@news.t-online.com>

I have a question about how to generate a multi-level (nested) list 
structure by perl. I currently have a 2-level 
<ul><li><ul><li></li></ul></li></ul> structure produced via a perl script, 
which works fine for its purpose. An example HTML output by the existing 
script is:

<ul>
   <li><a href=subject_1.0.html>Subject 1.0</a>
      <ul>
         <li><a href=page_1.1.html>Page 1.1</a></li> 
         <li><a href=page_1.2.html>Page 1.2</a></li> 
         <li><a href=page_1.3.html>Page 1.3</a></li> 
     </ul>
   </li>
</ul>

There's more non-relevant code that I've stripped for a bit of clarity, 
such as CSS etc. In fact, the actual HTML code is largely irrelavant. 
Anyway, a barebone version of the perl procedure generating the above is:

#!/usr/bin/perl -w

use Tie::IxHash;
use strict;
use warnings;

my $object1 = tie my %listoflinks, "Tie::IxHash";

%listoflinks = ('subject_1.0.html', => 'Subject 1.0',
                'page1.1.html', => 'Page 1.1',
                'page1.2.html', => 'Page 1.2',
                'page1.3.html', => 'Page 1.3');

for (\%listoflinks) {
my $firstkey = each %$_;

print "<ul>\n"; # open 1st UL

print "<li><a href=$firstkey>$listoflinks{$firstkey}</a>\n"; # open 1st LI

print "<ul>\n"; # open nested UL

while ( local $_ = each %$_ ) { 
   { print "<li><a href=$_>$listoflinks{$_}</a></li> \n" } # print some LI's
   }

print "</ul>\n"; # close nested UL
print "</li>\n"; # close first LI
print "</ul>\n"; # close first UL

}

The above procedure was put together with good help from this group ages 
ago. As mentioned, the code takes care of the 2-level list structure and 
does so by fetching the $firstkey from the array entries or LoH and 
inserting the needed opening and closing UL's and LI's in the right places.

However, I'm not quite sure how to change the script to generate a third 
level, such as:

<ul>
   <li><a href=subject_1.0.html>Subject 1.0</a>
      <ul>
         <li><a href=page_1.1.html>Page 1.1</a></li> 
         <li><a href=page_1.2.html>Page 1.2</a></li> 
         <li><a href=page_1.3.html>Page 1.3</a></li> 
         <li><a href=subject_2.0.html>Subject 2.0</a>
            <ul>
               <li><a href=page_2.1.html>Page 2.1</a></li>
               <li><a href=page_2.1.html>Page 2.2</a></li>
            </ul>
         </li>
     </ul>
   </li>
</ul>

Or for example, the same structure, with another two second-level list 
items at the end:

<ul>
   <li><a href=subject_1.0.html>Subject 1.0</a>
      <ul>
         <li><a href=page_1.1.html>Page 1.1</a></li> 
         <li><a href=page_1.2.html>Page 1.2</a></li> 
         <li><a href=page_1.3.html>Page 1.3</a></li> 
         <li><a href=subject_2.0.html>Subject 2.0</a>
            <ul>
               <li><a href=page_2.1.html>Page 2.1</a></li>
               <li><a href=page_2.1.html>Page 2.2</a></li>
            </ul>
         </li>
         <li><a href=page_1.4.html>Page 1.4</a></li> 
         <li><a href=page_1.5.html>Page 1.5</a></li>
     </ul>
   </li>
</ul>

Naturally a different array structure would be required in my %listoflinks 
to output the above. Any advise or examples how this may be pieced together 
would be most helpful.

Perhaps someone has a procedure in use that does something similar already?

Many thanks,
Tuxedo

NB: System load efficiency is not an issue, as the procedure will run only 
occasionally on a local machine to generate HTML sent onto a web server in 
static format. In other words, the script will not run against any real web 
page requests. The procedure is simply meant to be an easy maintenance tool.




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

Date: Sat, 21 Aug 2010 12:44:17 -0500
From: Steve <stevem_@nogood.com>
Subject: Re: Multi-level list generation
Message-Id: <Y1Wbo.71705$4B7.58781@newsfe16.iad>

On 08/21/2010 02:04 PM, Tuxedo wrote:
> I have a question about how to generate a multi-level (nested) list
> structure by perl. I currently have a 2-level
> <ul><li><ul><li></li></ul></li></ul>  structure produced via a perl script,
> which works fine for its purpose. An example HTML output by the existing
> script is:
>
> <ul>
>     <li><a href=subject_1.0.html>Subject 1.0</a>
>        <ul>
>           <li><a href=page_1.1.html>Page 1.1</a></li>
>           <li><a href=page_1.2.html>Page 1.2</a></li>
>           <li><a href=page_1.3.html>Page 1.3</a></li>
>       </ul>
>     </li>
> </ul>
>
> There's more non-relevant code that I've stripped for a bit of clarity,
> such as CSS etc. In fact, the actual HTML code is largely irrelavant.
> Anyway, a barebone version of the perl procedure generating the above is:
>
> #!/usr/bin/perl -w
>
> use Tie::IxHash;
> use strict;
> use warnings;
>
> my $object1 = tie my %listoflinks, "Tie::IxHash";
>
> %listoflinks = ('subject_1.0.html', =>  'Subject 1.0',
>                  'page1.1.html', =>  'Page 1.1',
>                  'page1.2.html', =>  'Page 1.2',
>                  'page1.3.html', =>  'Page 1.3');
>
> for (\%listoflinks) {
> my $firstkey = each %$_;
>
> print "<ul>\n"; # open 1st UL
>
> print "<li><a href=$firstkey>$listoflinks{$firstkey}</a>\n"; # open 1st LI
>
> print "<ul>\n"; # open nested UL
>
> while ( local $_ = each %$_ ) {
>     { print "<li><a href=$_>$listoflinks{$_}</a></li>  \n" } # print some LI's
>     }
>
> print "</ul>\n"; # close nested UL
> print "</li>\n"; # close first LI
> print "</ul>\n"; # close first UL
>
> }
>
> The above procedure was put together with good help from this group ages
> ago. As mentioned, the code takes care of the 2-level list structure and
> does so by fetching the $firstkey from the array entries or LoH and
> inserting the needed opening and closing UL's and LI's in the right places.
>
> However, I'm not quite sure how to change the script to generate a third
> level, such as:
>
> <ul>
>     <li><a href=subject_1.0.html>Subject 1.0</a>
>        <ul>
>           <li><a href=page_1.1.html>Page 1.1</a></li>
>           <li><a href=page_1.2.html>Page 1.2</a></li>
>           <li><a href=page_1.3.html>Page 1.3</a></li>
>           <li><a href=subject_2.0.html>Subject 2.0</a>
>              <ul>
>                 <li><a href=page_2.1.html>Page 2.1</a></li>
>                 <li><a href=page_2.1.html>Page 2.2</a></li>
>              </ul>
>           </li>
>       </ul>
>     </li>
> </ul>
>
> Or for example, the same structure, with another two second-level list
> items at the end:
>
> <ul>
>     <li><a href=subject_1.0.html>Subject 1.0</a>
>        <ul>
>           <li><a href=page_1.1.html>Page 1.1</a></li>
>           <li><a href=page_1.2.html>Page 1.2</a></li>
>           <li><a href=page_1.3.html>Page 1.3</a></li>
>           <li><a href=subject_2.0.html>Subject 2.0</a>
>              <ul>
>                 <li><a href=page_2.1.html>Page 2.1</a></li>
>                 <li><a href=page_2.1.html>Page 2.2</a></li>
>              </ul>
>           </li>
>           <li><a href=page_1.4.html>Page 1.4</a></li>
>           <li><a href=page_1.5.html>Page 1.5</a></li>
>       </ul>
>     </li>
> </ul>
>
> Naturally a different array structure would be required in my %listoflinks
> to output the above. Any advise or examples how this may be pieced together
> would be most helpful.
>
> Perhaps someone has a procedure in use that does something similar already?
>
> Many thanks,
> Tuxedo
>
> NB: System load efficiency is not an issue, as the procedure will run only
> occasionally on a local machine to generate HTML sent onto a web server in
> static format. In other words, the script will not run against any real web
> page requests. The procedure is simply meant to be an easy maintenance tool.
>
>

I use recursive routines a *lot* in printing out nested data structures, 
and they are your friend in cases like this...

The below is:
1) not tested in any way,
2) may not even compile,
3) and is just a concept.

%hash = ( whatever, too lazy to make one );

recurse_hash( \%hash );

sub recurse_hash {
     my $refhash = shift;
     $refhash or return '';

     print "<ul>\n";

     while( keys %{$refhash} ){
         if( ref $refhash->{$_} eq 'HASH' ){
             recurse_hash( $refhash->{$_} );
         }
         else{
             print "<li>$refhash->{$_}</li>\n";
         }
     }

     print "</ul>\n";
}

The beauty of a recursive is it flat doesn't matter how many levels deep 
the data structure is.

The downside is it flat doesn't matter how many levels deep the 
recursive 'thinks' the data structure is and sloppy programming can 
bite you big time..... infinite recursion anyone?

hth,

\s




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

Date: Sat, 21 Aug 2010 13:07:00 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Multi-level list generation
Message-Id: <esb076pgapjr1k238mtth1f0gop7duitkp@4ax.com>

Tuxedo <tuxedo@mailinator.com> wrote:
>I have a question about how to generate a multi-level (nested) list 
>structure by perl. I currently have a 2-level 
><ul><li><ul><li></li></ul></li></ul> structure produced via a perl script, 
>which works fine for its purpose. An example HTML output by the existing 
>script is:
[...]

>The above procedure was put together with good help from this group ages 
>ago. As mentioned, the code takes care of the 2-level list structure and 
>does so by fetching the $firstkey from the array entries or LoH and 
>inserting the needed opening and closing UL's and LI's in the right places.
>
>However, I'm not quite sure how to change the script to generate a third 
>level, such as:

If you keep adding additional levels then recursion is your friend:
(sketch in pseudo-code, transfer into actual Perl is left as an
excercise):

sub print_elem {
#arguments: single argument, either reference to list or single item
if (ref $_[0]) { # this element is a reference to  a nested list
	print_header(); #print header for the sub-list
	for (@_) {
		print_elem(@{$_}); #print each element of the sub-list
	}
	print_footer(); #print footer for the sub-list

} else { #this element is a single item
	print_item($_[0]; #just print it
}
)


jue


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

Date: Sat, 21 Aug 2010 22:32:08 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Multi-level list generation
Message-Id: <i4pd48$jhv$02$1@news.t-online.com>

Steve wrote:

> On 08/21/2010 02:04 PM, Tuxedo wrote:
> > I have a question about how to generate a multi-level (nested) list
> > structure by perl. I currently have a 2-level
> > <ul><li><ul><li></li></ul></li></ul>  structure produced via a perl
> > script, which works fine for its purpose. An example HTML output by the
> > existing script is:
> >
> > <ul>
> >     <li><a href=subject_1.0.html>Subject 1.0</a>
> >        <ul>
> >           <li><a href=page_1.1.html>Page 1.1</a></li>
> >           <li><a href=page_1.2.html>Page 1.2</a></li>
> >           <li><a href=page_1.3.html>Page 1.3</a></li>
> >       </ul>
> >     </li>
> > </ul>
> >
> > There's more non-relevant code that I've stripped for a bit of clarity,
> > such as CSS etc. In fact, the actual HTML code is largely irrelavant.
> > Anyway, a barebone version of the perl procedure generating the above
> > is:
> >
> > #!/usr/bin/perl -w
> >
> > use Tie::IxHash;
> > use strict;
> > use warnings;
> >
> > my $object1 = tie my %listoflinks, "Tie::IxHash";
> >
> > %listoflinks = ('subject_1.0.html', =>  'Subject 1.0',
> >                  'page1.1.html', =>  'Page 1.1',
> >                  'page1.2.html', =>  'Page 1.2',
> >                  'page1.3.html', =>  'Page 1.3');
> >
> > for (\%listoflinks) {
> > my $firstkey = each %$_;
> >
> > print "<ul>\n"; # open 1st UL
> >
> > print "<li><a href=$firstkey>$listoflinks{$firstkey}</a>\n"; # open 1st
> > LI
> >
> > print "<ul>\n"; # open nested UL
> >
> > while ( local $_ = each %$_ ) {
> >     { print "<li><a href=$_>$listoflinks{$_}</a></li>  \n" } # print
> >     some LI's }
> >
> > print "</ul>\n"; # close nested UL
> > print "</li>\n"; # close first LI
> > print "</ul>\n"; # close first UL
> >
> > }
> >
> > The above procedure was put together with good help from this group ages
> > ago. As mentioned, the code takes care of the 2-level list structure and
> > does so by fetching the $firstkey from the array entries or LoH and
> > inserting the needed opening and closing UL's and LI's in the right
> > places.
> >
> > However, I'm not quite sure how to change the script to generate a third
> > level, such as:
> >
> > <ul>
> >     <li><a href=subject_1.0.html>Subject 1.0</a>
> >        <ul>
> >           <li><a href=page_1.1.html>Page 1.1</a></li>
> >           <li><a href=page_1.2.html>Page 1.2</a></li>
> >           <li><a href=page_1.3.html>Page 1.3</a></li>
> >           <li><a href=subject_2.0.html>Subject 2.0</a>
> >              <ul>
> >                 <li><a href=page_2.1.html>Page 2.1</a></li>
> >                 <li><a href=page_2.1.html>Page 2.2</a></li>
> >              </ul>
> >           </li>
> >       </ul>
> >     </li>
> > </ul>
> >
> > Or for example, the same structure, with another two second-level list
> > items at the end:
> >
> > <ul>
> >     <li><a href=subject_1.0.html>Subject 1.0</a>
> >        <ul>
> >           <li><a href=page_1.1.html>Page 1.1</a></li>
> >           <li><a href=page_1.2.html>Page 1.2</a></li>
> >           <li><a href=page_1.3.html>Page 1.3</a></li>
> >           <li><a href=subject_2.0.html>Subject 2.0</a>
> >              <ul>
> >                 <li><a href=page_2.1.html>Page 2.1</a></li>
> >                 <li><a href=page_2.1.html>Page 2.2</a></li>
> >              </ul>
> >           </li>
> >           <li><a href=page_1.4.html>Page 1.4</a></li>
> >           <li><a href=page_1.5.html>Page 1.5</a></li>
> >       </ul>
> >     </li>
> > </ul>
> >
> > Naturally a different array structure would be required in my
> > %listoflinks to output the above. Any advise or examples how this may be
> > pieced together would be most helpful.
> >
> > Perhaps someone has a procedure in use that does something similar
> > already?
> >
> > Many thanks,
> > Tuxedo
> >
> > NB: System load efficiency is not an issue, as the procedure will run
> > only occasionally on a local machine to generate HTML sent onto a web
> > server in static format. In other words, the script will not run against
> > any real web page requests. The procedure is simply meant to be an easy
> > maintenance tool.
> >
> >
> 
> I use recursive routines a *lot* in printing out nested data structures,
> and they are your friend in cases like this...
> 
> The below is:
> 1) not tested in any way,
> 2) may not even compile,
> 3) and is just a concept.
> 
> %hash = ( whatever, too lazy to make one );
> 
> recurse_hash( \%hash );
> 
> sub recurse_hash {
>      my $refhash = shift;
>      $refhash or return '';
> 
>      print "<ul>\n";
> 
>      while( keys %{$refhash} ){
>          if( ref $refhash->{$_} eq 'HASH' ){
>              recurse_hash( $refhash->{$_} );
>          }
>          else{
>              print "<li>$refhash->{$_}</li>\n";
>          }
>      }
> 
>      print "</ul>\n";
> }
> 
> The beauty of a recursive is it flat doesn't matter how many levels deep
> the data structure is.
> 
> The downside is it flat doesn't matter how many levels deep the
> recursive 'thinks' the data structure is and sloppy programming can
> bite you big time..... infinite recursion anyone?
> 
> hth,
> 
> \s
> 
> 

Thanks for the above solution! However, it is a bit difficult for me to 
figure exactly how the %hash = (part may be composed) to generate a 
multi-level list structure. Any additional pointers anyone?

Tuxedo 





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

Date: Sat, 21 Aug 2010 22:37:14 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Multi-level list generation
Message-Id: <i4pddq$k4t$02$1@news.t-online.com>

Jürgen Exner wrote:

> Tuxedo <tuxedo@mailinator.com> wrote:
> >I have a question about how to generate a multi-level (nested) list
> >structure by perl. I currently have a 2-level
> ><ul><li><ul><li></li></ul></li></ul> structure produced via a perl
> >script, which works fine for its purpose. An example HTML output by the
> >existing script is:
> [...]
> 
> >The above procedure was put together with good help from this group ages
> >ago. As mentioned, the code takes care of the 2-level list structure and
> >does so by fetching the $firstkey from the array entries or LoH and
> >inserting the needed opening and closing UL's and LI's in the right
> >places.
> >
> >However, I'm not quite sure how to change the script to generate a third
> >level, such as:
> 
> If you keep adding additional levels then recursion is your friend:
> (sketch in pseudo-code, transfer into actual Perl is left as an
> excercise):
> 
> sub print_elem {
> #arguments: single argument, either reference to list or single item
> if (ref $_[0]) { # this element is a reference to  a nested list
> print_header(); #print header for the sub-list
> for (@_) {
> print_elem(@{$_}); #print each element of the sub-list
> }
> print_footer(); #print footer for the sub-list
> 
> } else { #this element is a single item
> print_item($_[0]; #just print it
> }
> )
> 
> 
> jue

This looks like a good solution. Yet difficult for me to translate into 
functioning code against an array of hash values or items.

Any bit of clearer description would be greatly appreciated.

Thanks,
Tuxedo




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

Date: Sat, 21 Aug 2010 14:26:59 -0500
From: Steve <stevem_@nogood.com>
Subject: Re: Multi-level list generation
Message-Id: <cyXbo.90767$xZ2.26479@newsfe07.iad>

On 08/21/2010 03:32 PM, Tuxedo wrote:
> Steve wrote:
>
>> On 08/21/2010 02:04 PM, Tuxedo wrote:
>>> I have a question about how to generate a multi-level (nested) list
>>> structure by perl. I currently have a 2-level
>>> <ul><li><ul><li></li></ul></li></ul>   structure produced via a perl
>>> script, which works fine for its purpose. An example HTML output by the
>>> existing script is:
>>>
>>> <ul>
>>>      <li><a href=subject_1.0.html>Subject 1.0</a>
>>>         <ul>
>>>            <li><a href=page_1.1.html>Page 1.1</a></li>
>>>            <li><a href=page_1.2.html>Page 1.2</a></li>
>>>            <li><a href=page_1.3.html>Page 1.3</a></li>
>>>        </ul>
>>>      </li>
>>> </ul>
>>>
>>> There's more non-relevant code that I've stripped for a bit of clarity,
>>> such as CSS etc. In fact, the actual HTML code is largely irrelavant.
>>> Anyway, a barebone version of the perl procedure generating the above
>>> is:
>>>
>>> #!/usr/bin/perl -w
>>>
>>> use Tie::IxHash;
>>> use strict;
>>> use warnings;
>>>
>>> my $object1 = tie my %listoflinks, "Tie::IxHash";
>>>
>>> %listoflinks = ('subject_1.0.html', =>   'Subject 1.0',
>>>                   'page1.1.html', =>   'Page 1.1',
>>>                   'page1.2.html', =>   'Page 1.2',
>>>                   'page1.3.html', =>   'Page 1.3');
>>>
>>> for (\%listoflinks) {
>>> my $firstkey = each %$_;
>>>
>>> print "<ul>\n"; # open 1st UL
>>>
>>> print "<li><a href=$firstkey>$listoflinks{$firstkey}</a>\n"; # open 1st
>>> LI
>>>
>>> print "<ul>\n"; # open nested UL
>>>
>>> while ( local $_ = each %$_ ) {
>>>      { print "<li><a href=$_>$listoflinks{$_}</a></li>   \n" } # print
>>>      some LI's }
>>>
>>> print "</ul>\n"; # close nested UL
>>> print "</li>\n"; # close first LI
>>> print "</ul>\n"; # close first UL
>>>
>>> }
>>>
>>> The above procedure was put together with good help from this group ages
>>> ago. As mentioned, the code takes care of the 2-level list structure and
>>> does so by fetching the $firstkey from the array entries or LoH and
>>> inserting the needed opening and closing UL's and LI's in the right
>>> places.
>>>
>>> However, I'm not quite sure how to change the script to generate a third
>>> level, such as:
>>>
>>> <ul>
>>>      <li><a href=subject_1.0.html>Subject 1.0</a>
>>>         <ul>
>>>            <li><a href=page_1.1.html>Page 1.1</a></li>
>>>            <li><a href=page_1.2.html>Page 1.2</a></li>
>>>            <li><a href=page_1.3.html>Page 1.3</a></li>
>>>            <li><a href=subject_2.0.html>Subject 2.0</a>
>>>               <ul>
>>>                  <li><a href=page_2.1.html>Page 2.1</a></li>
>>>                  <li><a href=page_2.1.html>Page 2.2</a></li>
>>>               </ul>
>>>            </li>
>>>        </ul>
>>>      </li>
>>> </ul>
>>>
>>> Or for example, the same structure, with another two second-level list
>>> items at the end:
>>>
>>> <ul>
>>>      <li><a href=subject_1.0.html>Subject 1.0</a>
>>>         <ul>
>>>            <li><a href=page_1.1.html>Page 1.1</a></li>
>>>            <li><a href=page_1.2.html>Page 1.2</a></li>
>>>            <li><a href=page_1.3.html>Page 1.3</a></li>
>>>            <li><a href=subject_2.0.html>Subject 2.0</a>
>>>               <ul>
>>>                  <li><a href=page_2.1.html>Page 2.1</a></li>
>>>                  <li><a href=page_2.1.html>Page 2.2</a></li>
>>>               </ul>
>>>            </li>
>>>            <li><a href=page_1.4.html>Page 1.4</a></li>
>>>            <li><a href=page_1.5.html>Page 1.5</a></li>
>>>        </ul>
>>>      </li>
>>> </ul>
>>>
>>> Naturally a different array structure would be required in my
>>> %listoflinks to output the above. Any advise or examples how this may be
>>> pieced together would be most helpful.
>>>
>>> Perhaps someone has a procedure in use that does something similar
>>> already?
>>>
>>> Many thanks,
>>> Tuxedo
>>>
>>> NB: System load efficiency is not an issue, as the procedure will run
>>> only occasionally on a local machine to generate HTML sent onto a web
>>> server in static format. In other words, the script will not run against
>>> any real web page requests. The procedure is simply meant to be an easy
>>> maintenance tool.
>>>
>>>
>>
>> I use recursive routines a *lot* in printing out nested data structures,
>> and they are your friend in cases like this...
>>
>> The below is:
>> 1) not tested in any way,
>> 2) may not even compile,
>> 3) and is just a concept.
>>
>> %hash = ( whatever, too lazy to make one );
>>
>> recurse_hash( \%hash );
>>
>> sub recurse_hash {
>>       my $refhash = shift;
>>       $refhash or return '';
>>
>>       print "<ul>\n";
>>
>>       while( keys %{$refhash} ){
>>           if( ref $refhash->{$_} eq 'HASH' ){
>>               recurse_hash( $refhash->{$_} );
>>           }
>>           else{
>>               print "<li>$refhash->{$_}</li>\n";
>>           }
>>       }
>>
>>       print "</ul>\n";
>> }
>>
>> The beauty of a recursive is it flat doesn't matter how many levels deep
>> the data structure is.
>>
>> The downside is it flat doesn't matter how many levels deep the
>> recursive 'thinks' the data structure is and sloppy programming can
>> bite you big time..... infinite recursion anyone?
>>
>> hth,
>>
>> \s
>>
>>
>
> Thanks for the above solution! However, it is a bit difficult for me to
> figure exactly how the %hash = (part may be composed) to generate a
> multi-level list structure. Any additional pointers anyone?
>
> Tuxedo
>
>
>

Well.....

my %hash = (
     key1 => { subkey => 'value',
               subhash => {
                           subsubkey1 => 'value',
                           subsubkey2 => 'another value',
                          },
             },
     key2 => 'value',
     etc  => {
             },

);

But, 'more better' would be to go a reliable (and vetted) source like:

http://perldoc.perl.org/perldsc.html

hth,

\s


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

Date: Sat, 21 Aug 2010 16:29:48 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Multi-level list generation
Message-Id: <01e74807-9cf9-42a9-a9bd-5a4532009850@s9g2000yqd.googlegroups.com>

On Aug 21, 3:04=A0pm, Tuxedo <tux...@mailinator.com> wrote:
> I have a question about how to generate a multi-level (nested) list
> structure by perl. I currently have a 2-level
> <ul><li><ul><li></li></ul></li></ul> structure produced via a perl script=
,
> which works fine for its purpose. An example HTML output by the existing
> script is:

Mark Jason Dominus, in 'Higher Order Perl' has a section on parsing
HTML in chapter 1. You can download the book over the internet, but
it's well worth buying, and I would encourage you to do so.

CC


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

Date: Sat, 21 Aug 2010 22:33:38 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Multi-level list generation
Message-Id: <87occvv0jh.fsf@quad.sysarch.com>

>>>>> "c" == ccc31807  <cartercc@gmail.com> writes:

  c> On Aug 21, 3:04 pm, Tuxedo <tux...@mailinator.com> wrote:
  >> I have a question about how to generate a multi-level (nested) list
  >> structure by perl. I currently have a 2-level
  >> <ul><li><ul><li></li></ul></li></ul> structure produced via a perl script,
  >> which works fine for its purpose. An example HTML output by the existing
  >> script is:

  c> Mark Jason Dominus, in 'Higher Order Perl' has a section on parsing
  c> HTML in chapter 1. You can download the book over the internet, but
  c> it's well worth buying, and I would encourage you to do so.

the OP isn't parsing but generating html. parsing it should be done with
a module. generating it is done well with templates but he still needs
to learn data structures to work with them. regardless of the
technology, nested html needs nested data which means perl data
structures. they are used in some many perl programs that they are
critical to learn early one. perlreftut, perldsc and perllol are
required reading from the perl docs.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

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


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