[32051] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3315 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 10 18:09:29 2011

Date: Thu, 10 Mar 2011 15:09:13 -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           Thu, 10 Mar 2011     Volume: 11 Number: 3315

Today's topics:
        Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <uri@StemSystems.com>
    Re: Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <cartercc@gmail.com>
    Re: Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <uri@StemSystems.com>
    Re: Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <cartercc@gmail.com>
    Re: Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <nobody@nowhere.com>
    Re: Ok, simpler..... <tadmc@seesig.invalid>
    Re: Ok, simpler..... <cartercc@gmail.com>
    Re: Ok, simpler..... <uri@StemSystems.com>
    Re: Text::DAWG (was Re: Hashes are good, but not good e <nospam.gravitalsun@hotmail.com.nospam>
    Re: Variable length array of arrays into tree structure <nobody@nowhere.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 10 Mar 2011 13:12:22 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Ok, simpler.....
Message-Id: <_cWdnaeaBskLv-TQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

I need to produce a 'tree'

  Sessions
     /  \
    /    \
 NOC-CO  NOC-INT
 /  \     /  \


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

Date: Thu, 10 Mar 2011 14:52:12 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Ok, simpler.....
Message-Id: <87y64mn47n.fsf@quad.sysarch.com>

>>>>> "W" == WhoDare  <nobody@nowhere.com> writes:

  W> I need to produce a 'tree'
  W>   Sessions
  W>      /  \
  W>     /    \
  W>  NOC-CO  NOC-INT
  W>  /  \     /  \

looks like you did a fine job there. and your perl question is?

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: Thu, 10 Mar 2011 14:02:49 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Ok, simpler.....
Message-Id: <_cWdnaaaBsn0s-TQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

> looks like you did a fine job there. and your perl question is?
> 
> uri

This is why I don't like asking innocent questions and try to learn.  
There is always someone in the bunch...

I have a perl array with the following data seperated by colons. The data 
is stored in an array of arrays. The length of the array inside the array 
(forgive me-'Row'Unsure ) is variable length.

	Code	

Sessions:NOC-CO:Servers:andy:(Netra t1 105 DNS server):192.168.18.104 
Sessions:NOC-CO:Servers:Blackserver:192.168.19.117 
Sessions:NOC-CO:Servers:Blackserver:VNC:tunnel:192.168.19.117 
Sessions:NOC-CO:Servers:Blueserver:192.168.19.115 
Sessions:NOC-CO:Servers:co-gateway:10.70.64.33 
Sessions:NOC-CO:Servers:Genview-EMS:192.168.19.254 
Sessions:NOC-CO:Servers:Mayberry:(external):192.168.75.8 
Sessions:NOC-CO:Servers:Mayberry:(internall):192.168.18.103 
Sessions:NOC-CO:Servers:OPIE2:192.168.18.102 
Sessions:NOC-INT:Core:Rotuers:Console:10008PKRV_L:192.168.17.68 
Sessions:NOC-INT:Core:Rotuers:Console:10008PKRV_R:192.168.17.68


I need to print a tree format so I can get the data into an XML where 
'Sessions' is the root, NOC-CO and NOC-INT are a branch/children, then 
'Servers' is a branch of NOC-CO and 'Core' is a child of NOC-INT, etc.

So it presents itself like this:
	Code	

                          Sessions 
                          /      \ 
                         /        \ 
                     NOC-CO     NOC-INT

etc.

But it has to be in XML format:

	Code	

<Sessions> 
  <NOC-CO> 
    <stuff> 
       some foo xml stuff.... 
    </stuff> 
  </NOC-CO> 
  <NOC-INT> 
    <otherstuff> 
       some other foo xml stuff.... 
    </otherstuff> 
  </NOC-INT> 
</Sessions>



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

Date: Thu, 10 Mar 2011 12:04:56 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Ok, simpler.....
Message-Id: <d54e0282-69b6-4115-8827-c0b4fbe3a922@f31g2000pri.googlegroups.com>

On Mar 10, 2:12=A0pm, WhoDare <nob...@nowhere.com> wrote:
> I need to produce a 'tree'
>
> =A0 Sessions
> =A0 =A0 =A0/ =A0\
> =A0 =A0 / =A0 =A0\
> =A0NOC-CO =A0NOC-INT
> =A0/ =A0\ =A0 =A0 / =A0\

What do you think a nested hash is? The nice thing about using hashes
is that you can get (and write) the values using whatever you want to
use for the XML elements. There's not any real limit to the depth (or
width) of your hash other than memory, and you can sort them any way
you want.

CPAN probably has modules that can parse and emit XML, but it may be
just as easy to write your own. If you need help, 'Learning Perl
Objects, References, and Modules' can be had from Amazon used for
$3.50 plus shipping, and it get you where you want to be. 'Data
Munging with Perl' can be had for $3.95 from the same source, and it
explicitly covers XML. I can recommend both of these books -- they
overlap but deal with the subject matter from different points of
view.

CC.


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

Date: Thu, 10 Mar 2011 14:08:58 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Ok, simpler.....
Message-Id: <_cWdnaGaBslHsuTQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

Thanks for the advice.  I will educate myself on nested hashes and see 
what I can come up with.


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

Date: Thu, 10 Mar 2011 15:32:51 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Ok, simpler.....
Message-Id: <87pqpyn2bw.fsf@quad.sysarch.com>

>>>>> "W" == WhoDare  <nobody@nowhere.com> writes:

  >> looks like you did a fine job there. and your perl question is?
  >> 
  >> uri

  W> This is why I don't like asking innocent questions and try to learn.  
  W> There is always someone in the bunch...

pot, meet kettle. how in hell would you expect someone to answer a post
like that? you didn't even ask a question. you didn't say ANYTHING about
input or output. you are the one to blame, i just called you out.


  W> I have a perl array with the following data seperated by colons. The data 
  W> is stored in an array of arrays. The length of the array inside the array 
  W> (forgive me-'Row'Unsure ) is variable length.

  W> 	Code	

  W> Sessions:NOC-CO:Servers:andy:(Netra t1 105 DNS server):192.168.18.104 
  W> Sessions:NOC-CO:Servers:Blackserver:192.168.19.117 
  W> Sessions:NOC-CO:Servers:Blackserver:VNC:tunnel:192.168.19.117 
  W> Sessions:NOC-CO:Servers:Blueserver:192.168.19.115 
  W> Sessions:NOC-CO:Servers:co-gateway:10.70.64.33 
  W> Sessions:NOC-CO:Servers:Genview-EMS:192.168.19.254 
  W> Sessions:NOC-CO:Servers:Mayberry:(external):192.168.75.8 
  W> Sessions:NOC-CO:Servers:Mayberry:(internall):192.168.18.103 
  W> Sessions:NOC-CO:Servers:OPIE2:192.168.18.102 
  W> Sessions:NOC-INT:Core:Rotuers:Console:10008PKRV_L:192.168.17.68 
  W> Sessions:NOC-INT:Core:Rotuers:Console:10008PKRV_R:192.168.17.68

that isn't an array of arrays - that is just a list of lines. SHOW YOUR
PERL CODE. SHOW REAL DATA. use Data::Dumper if you have real data.

  W> I need to print a tree format so I can get the data into an XML where 
  W> 'Sessions' is the root, NOC-CO and NOC-INT are a branch/children, then 
  W> 'Servers' is a branch of NOC-CO and 'Core' is a child of NOC-INT, etc.

printing a tree will not get you into xml.

  W> So it presents itself like this:
  W> 	Code	

  W>                           Sessions 
  W>                           /      \ 
  W>                          /        \ 
  W>                      NOC-CO     NOC-INT

  W> etc.

  W> But it has to be in XML format:

perl doesn't do xml itself. xml is a text form of a tree. perl stores
trees with references. you use a module to convert a perl tree to xml.

you need to learn how to express your problems better before you can get
help. also this is about helping with perl, not writing your
programs. what perl have you attempted for this?

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: Thu, 10 Mar 2011 15:31:18 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Ok, simpler.....
Message-Id: <_cWdnaCaBsm73uTQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

> pot, meet kettle. how in hell would you expect someone to answer a post
> like that? you didn't even ask a question. you didn't say ANYTHING about
> input or output. you are the one to blame, i just called you out.
> 
> perl doesn't do xml itself. xml is a text form of a tree. perl stores
> trees with references. you use a module to convert a perl tree to xml.
> 
> you need to learn how to express your problems better before you can get
> help. also this is about helping with perl, not writing your programs.
> what perl have you attempted for this?
> 
> uri

Other's have at least simply pointed me into a direction, which is all 
I'm after.  As by the ORIGINAL post I made:

> Anyone have any advice?

instead of asking 'Can anyone write this for me?'

Per your request, here is the perl script I have so far.  It's not 
written by a 'Professional' perl programmer, just someone trying to learn 
by picking up bits and pieces:

#!/usr/bin/perl
use XML::Simple;

my $infile = '/media/Docs/Scripts/Perl/Putty/TEST.csv';

open (CSVFILE, $infile) || die ("Could not open $infile!");

while ($line = <CSVFILE>) {
  $line =~ s/\"//g;
  $line =~ s/\r|\n//g;
  $line =~ s/\\/:/g;
  ($C1,$C2,$C3,$C4) = split ',', $line;
  @array = ($C2,$C1,$C4);
  push @stuff, [ @array ];
}
close (CSVFILE);
$stuffcount = @stuff;

for ($i = 0; $i <= $stuffcount-1; $i++) {
  $text = $stuff[$i][0];
  @thing = split (':', $text);
  push @c2array, [ @thing ];    
}

for ($h = 1; $h < $stuffcount; $h++) {
  for (my $i = 0; $i < $#{$c2array[$h]}+1; $i++) {
    push ( @finalt, $c2array[$h][$i] );
  }
  push ( @finalt, $stuff[$h][1] );
  push ( @finalt, $stuff[$h][2] );
  push @final, [ @finalt ];
  @finalt = ();
}

for $i ( 0 .. $#final ) {
  print "[ @{$final[$i]} ]\n";
}

Simply prints the contents of @final right now.  snippet:

[ Sessions NOC-CO Pannaway PKRV NETWORK PKRV PKRV.42.04 CO 07 
10.20.23.233 ]
[ Sessions NOC-CO Pannaway PKRV NETWORK PKRV PKRV.42.05 CO 08 
10.20.23.231 ]
[ Sessions NOC-CO Pannaway PKRV NETWORK PKRV PKRV.42.06 CO 09 
10.20.23.229 ]
[ Sessions NOC-CO Pannaway PKRV NETWORK PKRV PKRV.43.01 CO 10 
10.20.23.227 ]
[ Sessions NOC-CO Pannaway PKRV NETWORK PKRV PKRV.43.02 CO 11 
10.20.23.225 ]
[ Sessions NOC-CO Pannaway PKRV NETWORK PSEK PSEK.41.01 10.20.25.252 ]
[ Sessions NOC-CO Pannaway PKRV NETWORK PSEK PSEK.41.02 10.20.25.250 ]
[ Sessions NOC-CO Servers andy (Netra t1 105 DNS server) 172.16.18.104 ]
[ Sessions NOC-CO Servers Blackserver 172.16.19.117 ]
[ Sessions NOC-CO Servers Blackserver VNC tunnel 172.16.19.117 ]
[ Sessions NOC-CO Servers Blueserver 172.16.19.115 ]

Probably not the most efficient, but it confirms the data is in @final.


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

Date: Thu, 10 Mar 2011 15:40:25 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Ok, simpler.....
Message-Id: <_cWdnaOaBsnU2OTQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

Per my previous post, content of the csv file:

"PKRV.42.04 CO 07","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PKRV","","10.20.23.233"
"PKRV.42.05 CO 08","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PKRV","","10.20.23.231"
"PKRV.42.06 CO 09","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PKRV","","10.20.23.229"
"PKRV.43.01 CO 10","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PKRV","","10.20.23.227"
"PKRV.43.02 CO 11","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PKRV","","10.20.23.225"
"PSEK.41.01","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PSEK","","10.20.25.252"
"PSEK.41.02","Sessions\NOC-CO\Pannaway\PKRV NETWORK
\PSEK","","10.20.25.250"
"andy (Netra t1 105 DNS server)","Sessions\NOC-CO
\Servers","","172.16.18.104"
"Blackserver","Sessions\NOC-CO\Servers","","172.16.19.117"
"Blackserver VNC tunnel","Sessions\NOC-CO\Servers","","172.16.19.117"
"Blueserver","Sessions\NOC-CO\Servers","","172.16.19.115"


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

Date: Thu, 10 Mar 2011 13:51:08 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Ok, simpler.....
Message-Id: <c0531046-77fb-476a-9e00-6825c840c8d0@w7g2000pre.googlegroups.com>

On Mar 10, 3:02=A0pm, WhoDare <nob...@nowhere.com> wrote:
> This is why I don't like asking innocent questions and try to learn. =A0

Some say, "Give a man a fish and you feed him for a day. Teach him to
fish and you feed him for a lifetime."

I say, "Build a man a fire and you warm him for an hour. Set him on
fire and you warm him for a lifetime."

Here is a script and the output. The only hard part is the syntax in
printing out the nested references, but that's just some ugliness you
will have to learn to put up with if you decide to use Perl. You are
doing well to ask for help. You will do better to figure this out on
your own. The books I noted are good. There is also a Data Structures
Cookbook in the Perl documentation that you should study.

HERE IS THE SCRIPT
#! perl
use strict;
use warnings;
my %session;
#get data
while(<DATA>)
{
    next unless /\w/;
    chomp;
    my ($ses, $noc, $ser, $name, @rest) =3D split(/:/, $_);
    my $rest =3D join(':', @rest);
    $session{$noc}{$ser}{$name} =3D $rest;
}
#print data as XML
print qq(<SESSION>\n);
foreach my $k1 (sort keys %session)
{
    print qq(  <$k1>\n);
    foreach my $k2 (sort keys %{$session{$k1}})
    {
        print qq(    <$k2>\n);
        foreach my $k3 (sort keys %{$session{$k1}{$k2}})
        {
            print qq(      <$k3>\n);
            print qq(        $session{$k1}{$k2}{$k3}\n);
            print qq(      </$k3>\n);
        }
        print qq(    </$k2>\n);
    }
    print qq(  </$k1>\n);
}
print qq(</SESSION>\n);
exit(0);
__DATA__
Sessions:NOC-CO:Servers:andy:(Netra t1 105 DNS server):192.168.18.104
Sessions:NOC-CO:Servers:Blackserver:192.168.19.117
Sessions:NOC-CO:Servers:Blackserver:VNC:tunnel:192.168.19.117
Sessions:NOC-CO:Servers:Blueserver:192.168.19.115
Sessions:NOC-CO:Servers:co-gateway:10.70.64.33
Sessions:NOC-CO:Servers:Genview-EMS:192.168.19.254
Sessions:NOC-CO:Servers:Mayberry:(external):192.168.75.8
Sessions:NOC-CO:Servers:Mayberry:(internall):192.168.18.103
Sessions:NOC-CO:Servers:OPIE2:192.168.18.102
Sessions:NOC-INT:Core:Rotuers:Console:10008PKRV_L:192.168.17.68
Sessions:NOC-INT:Core:Rotuers:Console:10008PKRV_R:192.168.17.68

HERE IS THE OUTPUT
<SESSION>
  <NOC-CO>
    <Servers>
      <Blackserver>
        VNC:tunnel:192.168.19.117
      </Blackserver>
      <Blueserver>
        192.168.19.115
      </Blueserver>
      <Genview-EMS>
        192.168.19.254
      </Genview-EMS>
      <Mayberry>
        (internall):192.168.18.103
      </Mayberry>
      <OPIE2>
        192.168.18.102
      </OPIE2>
      <andy>
        (Netra t1 105 DNS server):192.168.18.104
      </andy>
      <co-gateway>
        10.70.64.33
      </co-gateway>
    </Servers>
  </NOC-CO>
  <NOC-INT>
    <Core>
      <Rotuers>
        Console:10008PKRV_R:192.168.17.68
      </Rotuers>
    </Core>
  </NOC-INT>
</SESSION>



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

Date: Thu, 10 Mar 2011 16:05:08 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Ok, simpler.....
Message-Id: <_cWdnaKaBsmJ1uTQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

Thank you for your help on this!  You really didn't need to go through 
the efforts of writing the script...  But I thank you.

> I say, "Build a man a fire and you warm him for an hour. Set him on fire
> and you warm him for a lifetime."

Jump in the pool holding your nose will make you swim quicker than 
lessons.  I agree.

This is the part that I can't figure out:

      <andy>
        (Netra t1 105 DNS server):192.168.18.104 # needed one more loop
      </andy>

      <Rotuers>
        Console:10008PKRV_R:192.168.17.68 # needed two more loops
      </Rotuers>

It's the variable length of the array elements that I can't wrap my head 
around.  I'm thinking what I would need to do is figure out the length of 
the array, and then make the loops react to that.  That has been stumping 
me.



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

Date: Thu, 10 Mar 2011 16:09:29 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Ok, simpler.....
Message-Id: <_cWdnd2aBsmE0eTQnZ2dnUVZ_q-dnZ2d@polarcomm.com>

> It's the variable length of the array elements that I can't wrap my head
> around.  I'm thinking what I would need to do is figure out the length
> of the array, and then make the loops react to that.  That has been
> stumping me.

OR, for an array with 4 elements, I would need 4 'foreach' loops.  With 
an array with 7 elements, I would need 7 'foreach' loops.



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

Date: Thu, 10 Mar 2011 16:21:51 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Ok, simpler.....
Message-Id: <slrninijed.77d.tadmc@tadbox.sbcglobal.net>

WhoDare <nobody@nowhere.com> wrote:
>> pot, meet kettle. how in hell would you expect someone to answer a post
>> like that? you didn't even ask a question. you didn't say ANYTHING about
>> input or output. you are the one to blame, i just called you out.


Please provide an attribution when you quote someone.


> here is the perl script I have so far.  It's not 
> written by a 'Professional' perl programmer, just someone trying to learn 
> by picking up bits and pieces:


Let's start by picking up bits and pieces of professional Perl
programming...


> #!/usr/bin/perl

    use strict;
    use warnings;

Those will help find many common mistakes.

You should ask for all the (automated) help you can get by
using them in every Perl program that you develop!


> open (CSVFILE, $infile) || die ("Could not open $infile!");


If that fails, it would be really handy to know _why_ it failed,
so you should include that in your diagnostic message. The reason
will be in the $! special variable:

    open (CSVFILE, $infile) || die ("Could not open $infile! $!");


>   $line =~ s/\"//g;
>   $line =~ s/\r|\n//g;

You can replace both of those lines with the Right Tool for
working with characters:

    $line =~ tr/"\r\n//d; # delete all of those 3 characters


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


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

Date: Thu, 10 Mar 2011 14:31:39 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Ok, simpler.....
Message-Id: <156c0668-0b3d-4125-91b5-f64d8332d5da@r19g2000prm.googlegroups.com>

On Mar 10, 5:05=A0pm, WhoDare <nob...@nowhere.com> wrote:
> It's the variable length of the array elements that I can't wrap my head
> around. =A0I'm thinking what I would need to do is figure out the length =
of
> the array, and then make the loops react to that. =A0That has been stumpi=
ng
> me.

The problem is that your data isn't normalized. Probably the easiest
way to deal with that problem is to make your data structure the size
it need to be to accommodate the longest row (in terms of number of
elements) and initialize the empty elements to some place holder, like
an empty string.

I started to keep just the last element in the @rest array, which
always seems to be an IP address. If you don't need the stuff between
the first four fields and the IP address, you can easily do it that
way. What you CAN'T do is name the elements according to the size of
the array, if the array will contain different elements. (You could do
it with a RE, but unless you had to be really precise, the cost may be
higher than the benefit.)

The big advantage to XML is that it can handle 'messy' data, unlike
RDBMSs. The disadvantage to solving a problem with an algorithm is
that your algorithm needs to be deterministic. You can choose between
jamming round or square pegs into the holes available (my solution) or
by hand crafting the holes to fit the individual pegs.

CC.



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

Date: Thu, 10 Mar 2011 17:54:23 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Ok, simpler.....
Message-Id: <87bp1imvs0.fsf@quad.sysarch.com>

>>>>> "W" == WhoDare  <nobody@nowhere.com> writes:

  >> pot, meet kettle. how in hell would you expect someone to answer a post
  >> like that? you didn't even ask a question. you didn't say ANYTHING about
  >> input or output. you are the one to blame, i just called you out.
  >> 
  >> perl doesn't do xml itself. xml is a text form of a tree. perl stores
  >> trees with references. you use a module to convert a perl tree to xml.
  >> 
  >> you need to learn how to express your problems better before you can get
  >> help. also this is about helping with perl, not writing your programs.
  >> what perl have you attempted for this?
  >> 
  >> uri

  W> Other's have at least simply pointed me into a direction, which is all 
  W> I'm after.  As by the ORIGINAL post I made:

  >> Anyone have any advice?

and your last post wasn't in the same thread as the original. you expect
me (or anyone else) to know this is part of another thread? you have
very strange expectations.

  W> instead of asking 'Can anyone write this for me?'

and again, you didn't say that this time. i don't track your
posts. learn to communicate. most of programming is just very clear
communications.

  W> Per your request, here is the perl script I have so far.  It's not 
  W> written by a 'Professional' perl programmer, just someone trying to learn 
  W> by picking up bits and pieces:

i never said you had to be a professional. but you do have to be civil
and communicate well. you are not doing well in either direction IMNSHO.

  W> #!/usr/bin/perl
  W> use XML::Simple;

  W> my $infile = '/media/Docs/Scripts/Perl/Putty/TEST.csv';

  W> open (CSVFILE, $infile) || die ("Could not open $infile!");

  W> while ($line = <CSVFILE>) {
  W>   $line =~ s/\"//g;
  W>   $line =~ s/\r|\n//g;
  W>   $line =~ s/\\/:/g;
  W>   ($C1,$C2,$C3,$C4) = split ',', $line;
  W>   @array = ($C2,$C1,$C4);
  W>   push @stuff, [ @array ];
  W> }

you should use a csv module for this. simpler and safer. 

  W> $stuffcount = @stuff;

choose better variable names. stuff is meaningless. here are a couple of
rules for you to learn:

code is for people, not computers
code is for other people, not yourself.

code is a written history of your logical decisions made in solving a
problem. your goal is to make them clear to another person. getting the
computer to do what you want is a side effect, not the goal.

  W> for ($i = 0; $i <= $stuffcount-1; $i++) {

for my $i ( 0 .. $#stuffcount ) {

but it is better to loop over the elements directly

	for my $line ( @stuff ) {

  W>   $text = $stuff[$i][0];

	my $text = $line->[0] ;

  W>   @thing = split (':', $text);

you will run out of generic names in a few more variables. thing, stuff,
text are meaningless.

  W>   push @c2array, [ @thing ];    
  W> }

  W> for ($h = 1; $h < $stuffcount; $h++) {
  W>   for (my $i = 0; $i < $#{$c2array[$h]}+1; $i++) {
  W>     push ( @finalt, $c2array[$h][$i] );
  W>   }
  W>   push ( @finalt, $stuff[$h][1] );
  W>   push ( @finalt, $stuff[$h][2] );
  W>   push @final, [ @finalt ];
  W>   @finalt = ();
  W> }

  W> for $i ( 0 .. $#final ) {
  W>   print "[ @{$final[$i]} ]\n";
  W> }

use Data::Dumper to see what you really have. no need to loop over it
yourself.

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: Thu, 10 Mar 2011 16:59:54 +0200
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: Text::DAWG (was Re: Hashes are good, but not good enough.)
Message-Id: <ilaovu$2mj9$1@news.ntua.gr>

I tried module Text::DAWG using sample data generated from the following 
code

my $how_many_numbers = 5_000_000;
my $length_of_number = 14;
for(1..$how_many_numbers){my $n; $n .= int rand 10 for 
(1..$length_of_number); print "$n\n"}

The data size is exactly 80 Mb
I kill the Perl process while its memory was 3.7 Gb
I was forced to kill because all my physical memory was consumed.

Suppossed that the DAWG should be smaller than the actual data.
I tried a blue filter and was able to store all these 80 Mb numbers  to only 
13k with very few false possitives
Apparentrly something does not work very well here ...




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

Date: Thu, 10 Mar 2011 11:50:09 -0600
From: WhoDare <nobody@nowhere.com>
Subject: Re: Variable length array of arrays into tree structure - help
Message-Id: <ZrudnTFZetHMkuTQnZ2dnUVZ_uSdnZ2d@polarcomm.com>

Thanks to everyone for replying.  Please understand that I've never 
really had formal perl scripting training, and that I'm trying to pick 
apart pieces I'm finding online.  I understand a lot of the concepts, but 
not the practical knowledge.  No, this is not a homework assignment!  heh

What I am having a hard time grasping is that there are sometimes going 
to be 5 elements in the array, sometimes more, sometimes less.  This will 
have to be incorporated into the loops.

Also, here is my oversimplified simplistic view of the XML I'm trying to 
create understanding that it's not a true XML.
<Session>
  <NOC-CO>
    <AFC>
      <ADMSND70AFC.01>
        <172.16.22.34>
      </ADMSND70AFC.01>
      <CAVWND48AFC.01>
        <172.16.22.6>
      </CAVWND48AFC.01>
    </AFC>
    <Servers>
      <co-gateway>
        <10.70.64.33>
      </co-gateway>
    </Servers>
  </NOC-CO>
  <NOC-INT>
    <Servers>
      <junk>
        <10.70.64.33>
      </junk>
    </Servers>
    <Routers>
      <Console>
        <PKRV_L>
          <10.10.17.68>
        </PKRV_L>
    </Routers>
  </NOC-INT>
</Session>


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

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


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