[32048] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3312 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 9 00:09:31 2011

Date: Tue, 8 Mar 2011 21:09:10 -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           Tue, 8 Mar 2011     Volume: 11 Number: 3312

Today's topics:
    Re: "getting" a website <Uno@example.invalid>
    Re: "getting" a website <Uno@example.invalid>
    Re: "getting" a website <Uno@example.invalid>
    Re: "getting" a website <jurgenex@hotmail.com>
    Re: "getting" a website <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: "getting" a website <Uno@example.invalid>
    Re: contexts <cwilbur@chromatico.net>
    Re: contexts <hjp-usenet2@hjp.at>
    Re: contexts <uri@StemSystems.com>
        Variable length array of arrays into tree structure - h <dpich@polartel.com>
    Re: Variable length array of arrays into tree structure <glex_no-spam@qwest-spam-no.invalid>
    Re: Variable length array of arrays into tree structure <nobody@nowhere.com>
    Re: Variable length array of arrays into tree structure <glex_no-spam@qwest-spam-no.invalid>
        Who is on Stack Overblow . com? sln@netherlands.com
    Re: Who is on Stack Overblow . com? sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 08 Mar 2011 17:38:24 -0700
From: Uno <Uno@example.invalid>
Subject: Re: "getting" a website
Message-Id: <8to0g2Ft9nU1@mid.individual.net>

On 03/07/2011 06:34 PM, Tad McClellan wrote:
> Uno<Uno@example.invalid>  wrote:
>
>> I have the _Perl Cookbook_, but have never actually gone and taken
>> somebody's website before.
>
>
> What do you mean when you say "take" a website?
>
>
>> Looking for tips as I do this with or without you.
>
>
> Tips on how to do what, exactly?
>
>
> And how do expect to use Perl for whatever it is that you do mean to do?
>
> Ask us a question about Perl, and we will answer it.
>
>

Boy, I must have been plowed when I wrote that.  Upset, too, these guys 
severely abused my uncle, who is ga-ga for Dietrich Bonhoeffer. 
Anyways, this is from the material in chp 20:

$ cat gurl1.pl
#!/usr/bin/perl -w
# gurl - get content from an url

use LWP::Simple;
my $URL = 'http://germanresistance.com';
my $content = get($URL);

unless (defined ($content = get $URL)) {
     die "could not get $URL\n";
}

print $content;
$

Really straightforward stuff here.

$ pwd
/home/dan/source/cookbook.examples/ch20
$ perl gurl1.pl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

<head profile="http://gmpg.org/xfn/11">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="template" content="K2 1.0-RC8" />

	<title> Christ and the German Resistance</title>

	<link rel="stylesheet" type="text/css" media="screen" 
href="http://germanresistance.com/wp-content/themes/k2/style.css" />

 ...

The output goes forever.

q1) What's best way to serialize a website with perl?

q2) What things don't get gotten with get?
-- 
Uno


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

Date: Tue, 08 Mar 2011 17:44:15 -0700
From: Uno <Uno@example.invalid>
Subject: Re: "getting" a website
Message-Id: <8to0r1Fv4mU1@mid.individual.net>

On 03/07/2011 08:50 PM, Michael Vilain wrote:
> In article<8tletiFjriU1@mid.individual.net>, Uno<Uno@example.invalid>
> wrote:
>
>> My family owns this website, and I serve as an agent in its behalf.
>>
>> http://germanresistance.com/
>>
>> I have the _Perl Cookbook_, but have never actually gone and taken
>> somebody's website before.  I can assure you that the law is on my side
>> here, unless it isn't because Barack has pointy ears.
>>
>> The guys I'm taking it from have to answer to the fbi and the local fuzz.
>>
>> Looking for tips as I do this with or without you.
>
> If you don't have ftp access to the server's docroot, you'll only get
> static html and image files.  Since this is a Wordpress site, perl
> programming will only help you capture the pages that the CMS constructs
> and presents to a browser.  I'd let the authorities do their job before
> you muddy the waters of your case and make it that much harder to
> prosecute the owners of the site.  Start by contacting 1and1, the ISP
> hosting the site.
>
> Open your wallet wide.
>

I'm just a cash-flow device anymore.  The "webmaster" is part of the 
scam that bilked this guy out of shocking amounts of $$, and I've got to 
make him superfluous somehow.

I'll get ftp access.  Thx.
-- 
Uno


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

Date: Tue, 08 Mar 2011 19:11:47 -0700
From: Uno <Uno@example.invalid>
Subject: Re: "getting" a website
Message-Id: <8to5v4FraeU1@mid.individual.net>

On 03/07/2011 06:34 PM, Tad McClellan wrote:

> Ask us a question about Perl, and we will answer it.
>
>
$ perl gurl3.pl
Wide character in print at gurl3.pl line 16.
<td height="14"><a 
href="http://www.germanresistance.com/documents/Intro_to_Bonhoeffer.pdf" 
target="_blank">Introduction to Dietrich Bonhoeffer</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Chronology_of_the_life_of_Dietrich_Bonhoeffer.pdf" 
target="_blank">Chronology of the life of Dietrich Bonhoeffer</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Bonhoeffer_on_Abortion.pdf" 
target="_blank">Dietrich Bonhoeffer on Abortion</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Luther_Bonhoeffer_and_Revolution.pdf" 
target="_blank">Luther, Bonhoeffer and Revolution</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_Russian_Religious_Renaissance.pdf" 
target="_blank">Dietrich Bonhoeffer and the Russian Religious 
Renaissance</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_the_resistance_and_the_two_kingdoms.pdf" 
target="_blank">Dietrich Bonhoeffer, the resistance, and the two 
kingdoms</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Pius_XII_and_the_Jews.pdf" 
target="_blank">Pius XII and the Jews</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_German_Resistance_'95.pdf" 
target="_blank">Dietrich Bonhoeffer and the German Resistance</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_Liberalism.pdf" 
target="_blank">Dietrich Bonhoeffer and Liberalism</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_Canossa.pdf" 
target="_blank">Dietrich Bonhoeffer and Canossa</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Invidious_Comparisons.pdf" 
target="_blank">Invidious Comparisons</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Agent_of_Grace.pdf" 
target="_blank">Dietrich Bonhoeffer &#8211; a discussion of 
&#8220;Bonhoeffer: Agent of Grace&#8221;</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/The_stereotyping_of_Dietrich_Bonhoeffer.pdf" 
target="_blank">The stereotyping of Dietrich Bonhoeffer</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/From_Dietrich_Bonhoeffer’s_Wedding_Sermon.pdf" 
target="_blank">From Dietrich Bonhoefer’s Wedding Sermon</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_Theology_of_the_Cross.pdf" 
target="_blank">Dietrich Bonhoeffer and the Theology of the Cross</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_on_Authority.pdf" 
target="_blank">Dietrich Bonhoeffer on Authority</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_Formula_of_Concord.pdf" 
target="_blank">Dietrich Bonhoeffer and the Formula of Concord</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/The_German_Resistance_60_years.pdf" 
target="_blank">The German Resistance &#8211; 60 years</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_Karl_Barth.pdf" 
target="_blank">Dietrich Bonhoeffer and Karl Barth</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/Luther_and_Bonhoeffer_misunderstood.pdf" 
target="_blank">Luther and Bonhoeffer misunderstood</a></td>
<td height="14"><a 
href="http://www.germanresistance.com/documents/The_German_Resistance_and_Dietrich_Bonhoeffer_'07.pdf" 
target="_blank">The German Resistance and Dietrich Bonhoeffer</a></td>
$ cat gurl3.pl
#!/usr/bin/perl -w
# gurl - get content from an url

use LWP::Simple;

if ( ! open FILE, ">bonhoeffer") {
       die "Cannot create file: $!";
}
my $URL = 'http://germanresistance.com/index-of-papers/';
my $content = get($URL);

unless (defined ($content = get $URL)) {
     die "could not get $URL\n";
}

print FILE $content;
close FILE;

if ( ! open FILE2, "<bonhoeffer") {
       die "Cannot open file: $!";
}

while (<FILE2>) {
if (m{
http://www.germanresistance.com/documents # first part
 .*  #anything in between
pdf # last part
}six)  {
print $_;
}
}
$

So I'm pecking away at this.  I want this script to match on the pdf 
documents.  I think I get them all to match, but how do I strip off all 
the rest of it?

For example this is now:
<td height="14"><a 
href="http://www.germanresistance.com/documents/The_German_Resistance_60_years.pdf" 
target="_blank">The German Resistance &#8211; 60 years</a></td>

, and I want it to be:
http://www.germanresistance.com/documents/The_German_Resistance_60_years.pdf

, without the newline.

Also, I couldn't really think of a way to get this done without opening 
a file twice, but I'm sure there is a way to a) Have $content stored in 
a file and b) run it through the while clause.

Thanks for your comment.
-- 
Uno



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

Date: Tue, 08 Mar 2011 19:19:10 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: "getting" a website
Message-Id: <q8sdn65f1ovb9d4sbsnc1i1v9rm0qeqdpp@4ax.com>

Uno <Uno@example.invalid> wrote:
>For example this is now:
><td height="14"><a 
>href="http://www.germanresistance.com/documents/The_German_Resistance_60_years.pdf" 
>target="_blank">The German Resistance &#8211; 60 years</a></td>
>
>, and I want it to be:
>http://www.germanresistance.com/documents/The_German_Resistance_60_years.pdf

Simple. Exactly the same way as it has been done a gazillion of times
before in this NG: you take an HTML parser, you run your text through
that parser, and you retrieve the value of the href attribute.

jue


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

Date: Tue, 8 Mar 2011 19:32:57 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: "getting" a website
Message-Id: <909j48xs5h.ln2@goaway.wombat.san-francisco.ca.us>

On 2011-03-09, Uno <Uno@example.invalid> wrote:
>
> q1) What's best way to serialize a website with perl?

I'm going to take a WAG that you want to download as much as possible
using GETs (ftp will be better, since you mentioned that you're trying
to get it).  You will probably want to look at wget's recursive
retrieval options.  If you later need to parse and modify the HTML, then
as Jurgen suggested you should use the various HTML parsers available
(e.g., HTML::Parser, HTML::TreeBuilder).

If that's wrong then you need to explain exactly what "serializing" a
website means.

> q2) What things don't get gotten with get?

Anything dynamic, e.g., a backend database, scripts, flat files
generated dynamically, SSI directives (do people still use those?),
probably lots more.

If you get ftp access, you could use the Net::FTP module to retrieve
files (or use a tool like ncftpget).

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



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

Date: Tue, 08 Mar 2011 21:57:00 -0700
From: Uno <Uno@example.invalid>
Subject: Re: "getting" a website
Message-Id: <8tofksFe9jU1@mid.individual.net>

On 03/08/2011 08:19 PM, Jürgen Exner wrote:

> Simple. Exactly the same way as it has been done a gazillion of times
> before in this NG: you take an HTML parser, you run your text through
> that parser, and you retrieve the value of the href attribute.

Alright, thx, jue, I think I'm getting pretty close here:

$ perl gurl5.pl
Title: Index of Papers � Christ and the German Resistance
http://www.germanresistance.com/documents/Intro_to_Bonhoeffer.pdf
http://www.germanresistance.com/documents/Chronology_of_the_life_of_Dietrich_Bonhoeffer.pdf
http://www.germanresistance.com/documents/Bonhoeffer_on_Abortion.pdf
http://www.germanresistance.com/documents/Luther_Bonhoeffer_and_Revolution.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_Russian_Religious_Renaissance.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_the_resistance_and_the_two_kingdoms.pdf
http://www.germanresistance.com/documents/Pius_XII_and_the_Jews.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_German_Resistance_'95.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_Liberalism.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_Canossa.pdf
http://www.germanresistance.com/documents/Invidious_Comparisons.pdf
http://www.germanresistance.com/documents/Agent_of_Grace.pdf
http://www.germanresistance.com/documents/The_stereotyping_of_Dietrich_Bonhoeffer.pdf
http://www.germanresistance.com/documents/From_Dietrich_Bonhoeffer’s_Wedding_Sermon.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_Theology_of_the_Cross.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_on_Authority.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_the_Formula_of_Concord.pdf
http://www.germanresistance.com/documents/The_German_Resistance_60_years.pdf
http://www.germanresistance.com/documents/Dietrich_Bonhoeffer_and_Karl_Barth.pdf
http://www.germanresistance.com/documents/Luther_and_Bonhoeffer_misunderstood.pdf
http://www.germanresistance.com/documents/The_German_Resistance_and_Dietrich_Bonhoeffer_'07.pdf
$ cat gurl5.pl
#!/usr/bin/perl -w
# gurl - get content from an url

use LWP::Simple;
require HTML::TokeParser;

my $file = "bonhoeffer2";
my $URL = 'http://germanresistance.com/index-of-papers/';
my $content = getstore($URL, $file);


## print out the title
## not necessary for the task at hand
## but instructive for me
my $q = HTML::TokeParser->new(bonhoeffer2);

   if ($q->get_tag("title")) {
       my $title = $q->get_trimmed_text;
       print "Title: $title\n";
   }


my $p = HTML::TokeParser->new(bonhoeffer2);


   while (my $token = $p->get_tag("a")) {
       my $url = $token->[1]{href} || "-";
       if ($url =~ "http://www.germanresistance.com/documents.*pdf" ) {
print "$url\n";
getstore( $url, "/pdfs/$url" );
}
}

So I made a directory called pdfs in the same directory as the script. 
Unfortunately, I don't get any pdf's stored there.  I suspect my 
getstore statement isn't right, but I don't know why.
-- 
Uno


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

Date: Tue, 08 Mar 2011 14:40:14 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: contexts
Message-Id: <86hbbde6zl.fsf@mithril.chromatico.net>

>>>>> "RS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

I originally answered this point-by-point, but I decided that wasn't
helpful.

    RS> I think you could legitimately say that Perl is *hard* for the
    RS> *casual* programmer.  But it's not meant for the casual
    RS> programmer.  It's meant for the professional programmer.  If
    RS> you're not hacking Perl at least an hour a day, feel free to use
    RS> something else.

You do realize that I've been making my living using Perl for over a
decade?

Responding to any criticism -- especially reasonable criticisms -- of
your favorite programming language as if it were a racial slur is the
sort of thing that rabid fanboys do -- as is the implication that
because I don't think Perl is flawless and perfect that I should go off
and use something else.  You are, or at least should be, better than
that.

Steve Yegge made some reasonable criticisms of Perl.  They are almost
all design decisions that might reasonably have been made differently,
and it is possible, despite what one might infer from your reply, to
think that Perl is a great language that might yet be better if certain
issues had been decided otherwise.

Charlton







-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Tue, 8 Mar 2011 23:48:18 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: contexts
Message-Id: <slrnindchj.fbm.hjp-usenet2@hrunkner.hjp.at>

On 2011-03-08 14:47, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Charlton" == Charlton Wilbur <cwilbur@chromatico.net> writes:
>
>Charlton> The core of the commentary is that flattening lists in Perl4
>Charlton> was a bad decision because it makes hierarchical data
>Charlton> structures difficult,
>
> But it made sense since Perl4 didn't have hierarchical data structures!
>
> That statement makes about as much sense as
>   
>   "Perl4 didn't have elephant harnesses, so it made dealing with
>   elephants difficult."
>
> Uh yeah.  Not designed for that.

True, but "not designed for that" is exactly the problem. A programming
language without hierarchical data structures is of limited utility.

If Larry had planned to design a general purpose programming language,
he would have included hierarchical data structures from the beginning.
But he didn't. He just wanted a simple language to replace shell and
awk. So he left them out. But people who started to use Perl for the
simple tasks it was designed for soon wanted to use it for more complex
tasks and discovered that that was hard without hierarchical data
structures.

So they had to be added.

But they had to be added in backward-compatible way, and that led to a
syntax and semantics that can hardly be called elegant. (And the mess
that "perldoc perlref" was at the time certainly didn't help. Hooray to
MJD for writing perlreftut - it came too late for me, but at least we
can now point newbies at reasonable documentation.)

(I'm speculating about Larry's intentions, of course. I wasn't around at
the time)

>Charlton>  that
>Charlton> objects and references seem like a bolted-on solution to people who are
>Charlton> accustomed to languages that are OO from the ground up,
>
> Necessary to stay within backward compatibility.  Perl6 makes a
> different set of sins though.
>
>Charlton>  and that
>Charlton> contexts baffle people who are unaccustomed to them.
>
> And yet, you can pronounce "w i n d" as either the thing that blows or a
> circular motion just fine given the *context* of the sentence.  So,
> you're clearly familiar with contextual clues.

Sure. And other programming languages have context, too. But in Perl the
context works differently than in other programming languages people are
accustomed to. I don't say that's a bad thing. If you want C, use C, not
Perl. But it is baffling at first (and it needs to be explained
properly. I'm sure the Llama book does a good job, but there are so many
bad books and web tutorials which make a complete mess of it).


>Charlton>   Also, Perl has a
>Charlton> lot of edge cases where what code should do is not apparent or
>Charlton> intuitive.
>
> Really?  Name 3.  3 would be a subset of "a lot".  But I bet you have a
> strange meaning for "edge case".
>
> It's taken me a while, but Perl doesn't surprise me, at all.  I find it
> *very* apparent and *very* intuitive, once you learn to think like a
> Perl programmer.

Well I'm rarely surprised by Perl, too. But then I've now used it for 16
years (and discussed it on Usenet for nearly as long), so it shouldn't.
But there are still some aspects of the language which I do not find
intuitive. For example (since we were talking about references)
autovivification. Referencing $x->[0][0] automatically creates $x->[0]
as a reference to an empty array, but @{ $x->[0] } throws an exception.
Why? Both cases seem almost exactly analogous to me.

	hp


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

Date: Tue, 08 Mar 2011 18:13:20 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: contexts
Message-Id: <87ei6h8aun.fsf@quad.sysarch.com>

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

  PJH> On 2011-03-08 14:47, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
  >>>>>>> "Charlton" == Charlton Wilbur <cwilbur@chromatico.net> writes:
  >> 
  Charlton> The core of the commentary is that flattening lists in Perl4
  Charlton> was a bad decision because it makes hierarchical data
  Charlton> structures difficult,
  >> 
  >> But it made sense since Perl4 didn't have hierarchical data structures!
  >> 
  >> That statement makes about as much sense as
  >> 
  >> "Perl4 didn't have elephant harnesses, so it made dealing with
  >> elephants difficult."
  >> 
  >> Uh yeah.  Not designed for that.

  PJH> True, but "not designed for that" is exactly the problem. A programming
  PJH> language without hierarchical data structures is of limited utility.

  PJH> If Larry had planned to design a general purpose programming language,
  PJH> he would have included hierarchical data structures from the beginning.
  PJH> But he didn't. He just wanted a simple language to replace shell and
  PJH> awk. So he left them out. But people who started to use Perl for the
  PJH> simple tasks it was designed for soon wanted to use it for more complex
  PJH> tasks and discovered that that was hard without hierarchical data
  PJH> structures.

and you can do hierarchal stuff in perl4. i did a major 6 month project
doing just that. i had to hack my own tree stuff from a large array and
joined strings of index numbers, and typeglobs and supporting subs. it
worked well and it was useful. i still have the codebase for archival
and humorous purposes! i even did a boring lightning talk on it at
yapc::montreal way back when. so it can be done. it just is much easier,
faster and cleaner with perl5. anyone with basic algorithms and
structures should be able to produce ANY data structure from just a
single array. hell, that is all c gives you in effect. and assembler
gives you less.

  PJH> So they had to be added.

they had to be improved by adding refs and objects.

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: Tue, 08 Mar 2011 10:31:02 -0600
From: Don Pich <dpich@polartel.com>
Subject: Variable length array of arrays into tree structure - help
Message-Id: <A-SdnUeycINbxOvQnZ2dnUVZ_oSdnZ2d@polarcomm.com>

I need help figuring out how to print this properly.

I have generated an array of arrays from a csv file.  Here is an example 
of the data stored in the array (note:  the ' - ' are just element 
dividers and not actual elements.  They are just text).

ADMSND70AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.34
ARTHND16AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.26
CAVWND48AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.6
CRYSND04AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.46
CVLRND10AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.90
DYTNND01AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.50
co-gateway - Sessions - NOC-CO - Servers - 10.70.64.33
Genview-EMS - Sessions - NOC-CO - Servers - 172.16.19.254
Mayberry (external) - Sessions - NOC-CO - Servers - 1.3.5.4
Mayberry (internall) - Sessions - NOC-INT - Servers - 172.16.18.103
OPIE2 (SUN NTP SERVER) - Sessions - NOC-INT - Servers - 172.16.18.102
10008PKRV_L - Sessions - NOC-INT - Core - Rotuers - Console - 
donp:7001@10.10.17.68
10008PKRV_R - Sessions - NOC-INT - Core - Rotuers - Console - 
donp:7002@10.10.17.68

What I need to do is setup printing of this data in the following tree 
format:

Sessions
 >NOC-CO
    >AFC
      >ADMSND70AFC.01
        >172.16.22.34
      >ARTHND16AFC.01
        >172.16.22.26
      >CAVWND48AFC.01
        >172.16.22.6
      >CRYSND04AFC.01
        >172.16.22.46
      >CVLRND10AFC.01
        >172.16.22.90
      >DYTNND01AFC.01
        >172.16.22.50
    >Servers
      >co-gateway
        >10.70.64.33
      >Genview-EMS
        >172.16.19.254
      >Mayberry (external)
        >1.3.5.4
  >NOC-INT
    >Servers
      >Mayberry (internall)
        >172.16.18.103
      >OPIE2 (SUN NTP SERVER)
        >172.16.18.102
    >Core
      >Routers
        >Console
          >PKRV_L
            >10.10.17.68
          >PKRV_R
            >10.10.17.68

I.E.
- '172.16.22.34' is a child of 'ADMSND70AFC.01', which is a child of 
'AFC', which is a child of 'NOC-CO', which is a child of 'Sessions'.
- '10.10.17.68' is a child of 'PKRV_R', which is a child of 'Console', 
which is a child of 'Routers', which is a child of 'Core', which is a 
child of 'NOC-INT', which is a child of 'Session'.

I am going to place this in a XML for bookmarks for KDE Konsole.  I need 
to create a tree/folder structure.

The array inside the array ('row' - Sorry for calling it that, but it 
fits) can be variable length.

I've been looking for some form of 'tree' function or script with no luck.

Anyone have any advice?


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

Date: Tue, 08 Mar 2011 11:36:07 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Variable length array of arrays into tree structure - help
Message-Id: <4d765885$0$46851$815e3792@news.qwest.net>

Don Pich wrote:
> I need help figuring out how to print this properly.
> 
> I have generated an array of arrays from a csv file.

Hopefully you're using one of the CSV modules.

You probably want to use hashes too.

> Here is an example 
> of the data stored in the array (note:  the ' - ' are just element 
> dividers and not actual elements.  They are just text).

To show/view the actual data structure, try Data::Dumper. e.g.

use Data::Dumper;
print Dumper( $yourdata );

That way you/we can clearly see the structure of your data.

> 
> ADMSND70AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.34
> ARTHND16AFC.01 - Sessions - NOC-CO - AFC - 172.16.22.26
[...]
> 
> What I need to do is setup printing of this data in the following tree 
> format:
> 
> Sessions
>  >NOC-CO
>     >AFC
>       >ADMSND70AFC.01
>         >172.16.22.34
[...]
> I.E.
> - '172.16.22.34' is a child of 'ADMSND70AFC.01', which is a child of 
> 'AFC', which is a child of 'NOC-CO', which is a child of 'Sessions'.
> - '10.10.17.68' is a child of 'PKRV_R', which is a child of 'Console', 
> which is a child of 'Routers', which is a child of 'Core', which is a 
> child of 'NOC-INT', which is a child of 'Session'.

push ( @{ $data{ 'Sessions' }{ 'NOC-CO' }{ 'AFC' }{ 'ADMSND70AFC.01' } 
}, '172.16.22.34' );

for my $xyz ( sort keys %data})
{
   print "$xyz\n";
   for my $session ( sort keys %{ $data{ $xyz } })
   {
      print " >$session\n";
      for my $aaa ( sort keys %{ $data{ 'Sessions' }{ $session } } )
      {
         print "   >$aaa\n";
         etc....
      }
   }
}

but.. there's probably no reason to actually write that, except for
debugging, since your goal is to create XML.  Using Dumper will be
better, but a bit more verbose.

> 
> I am going to place this in a XML for bookmarks for KDE Konsole.  I need 
> to create a tree/folder structure.
> 
> The array inside the array ('row' - Sorry for calling it that, but it 
> fits) can be variable length.
> 
> I've been looking for some form of 'tree' function or script with no luck.

A 'tree' is nothing more than a data structure:

perldoc perldsc

To produce the XML, XML::Simple has an XMLout method that might be helpful.

perldoc XML::Simple

Create the correct data structure, and use a couple of options to 
XMLout, and it could produce what's needed in very few lines of code.
You could start with a similar XML file, use XMLin and Dumper, to
see what data structure you should use as a model.

Also, since you're starting with a CSV file, XML::CSV might be a good 
option:

http://search.cpan.org/~isterin/XML-CSV-0.15/CSV.pm


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

Date: Tue, 08 Mar 2011 12:43:40 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Variable length array of arrays into tree structure - help
Message-Id: <OrmdnVU70NBB5evQnZ2dnUVZ_judnZ2d@polarcomm.com>

> push ( @{ $data{ 'Sessions' }{ 'NOC-CO' }{ 'AFC' }{ 'ADMSND70AFC.01' }
> }, '172.16.22.34' );

The problem I am having is that I'm dealing with variable lengths.  
Pushing into the above array is 5 elements.  There are other elements 
that are 3 elements long, 4 elements long, etc.  So it's variable.




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

Date: Tue, 08 Mar 2011 13:44:37 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Variable length array of arrays into tree structure - help
Message-Id: <4d768725$0$9074$815e3792@news.qwest.net>

WhoDare wrote:
>> push ( @{ $data{ 'Sessions' }{ 'NOC-CO' }{ 'AFC' }{ 'ADMSND70AFC.01' }
>> }, '172.16.22.34' );
> 
> The problem I am having is that I'm dealing with variable lengths.  
> Pushing into the above array is 5 elements.  There are other elements 
> that are 3 elements long, 4 elements long, etc.  So it's variable.
> 

What happened when you tried it?

my %data;
push ( @{ $data{ 'Sessions' }{ 'NOC-CO' }{ 'XYZ' }}, 'Some Value');
push ( @{ $data{ 'Sessions' }{ 'BLAH' }}, 'Junk' );

%data is a hash, and 'Sessions', 'BLAH', etc. are referred to as keys.

I strongly suggest spending at least a day reading/experimenting with
the code in: perldoc perldsc

Once you understand the various basic data structures it'll be
much easier to do what you want.


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

Date: Tue, 08 Mar 2011 17:44:57 -0800
From: sln@netherlands.com
Subject: Who is on Stack Overblow . com?
Message-Id: <himdn6dbf4lhql004mnuhrgqo3l3k7v76k@4ax.com>

Ok, just a heads up. I am on StackOverblow.com and
am me sln. I am shocked at this system of reward via timebased
instead of thought.

I think there can be some real instant problem solving, but
the up votes based on reputation, and giving the misguided/wrong
answer is bad for beginners, who cast thier lot with reps of 
"fastests gets the upvotes" prevalence.

I think its bad over all.

Any opinions?

-sln


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

Date: Tue, 08 Mar 2011 19:27:14 -0800
From: sln@netherlands.com
Subject: Re: Who is on Stack Overblow . com?
Message-Id: <0psdn69catjviddac5nabhkm1e60g7saf7@4ax.com>

On Tue, 08 Mar 2011 17:44:57 -0800, sln@netherlands.com wrote:

>Ok, just a heads up. I am on StackOverblow.com and
>am me sln. I am shocked at this system of reward via timebased
>instead of thought.
>
>I think there can be some real instant problem solving, but
>the up votes based on reputation, and giving the misguided/wrong
>answer is bad for beginners, who cast thier lot with reps of 
>"fastests gets the upvotes" prevalence.
>
>I think its bad over all.
>

Come on, the bleed from clmp is to StackOverflow,
surely you doesth protest? I know I do!

(come one folks, ... anybody..)

-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:

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


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