> My output should look something like this:
> 
> a-\
>   |-b
>   | | 
>   | \-c
>   |   |
>   |   \-d
>   |   | |
>   |   | \-g
>   |   |
>   |   \-e
>   |
>   |-f
>   | |
>   | \-h
>   | |
>   | \-I
>   |   |
>   |   \-j
>   |   |
>   |   \-k
>   |     |
>   |     \-l
>   |
>   \-m
> 
> 
> My data file has at least these two columns:
> 
> Col1    Col2
>  a       
>  b       a
>  c       b
>  d       c
>  e       c
>  f       a
>  g       d
>  h       f
>  I       f
>  j       i
>  k       i
>  l       k
>  m       a
> 
> What is the best way to do this?

Hi,

For the benefit of everyone else... Tim is trying to create a
graph, where first column of the input specfies the new vertex (node)
name, and the second column is the existing vertex to connect to.
>From the way this is shown, it looks rather like a directed graph.

As Tim didn't provide any context at all, it is difficult to suggest
the appropriate approach to take.  A simple first run from textual
input into a datastructure *could* be:

# Input
while (<DATA>) {
    my ($first, $second) =
        /^             # Start of line,
           \s*         #   with zero or more whitespace.
           (\w+)       #   Capture word.
           (?:         #   Optionally also match:
               \s+     #     One or more whitespace characters.
               (\w+)   #     Capture word.
           )?          #   End optional match,
           \s*         #   with zero or more whitespace.
        $              # End of line.
        /x;
    next unless defined $first;
    push @map, [$first, $second];
}

# Output
foreach my $pair (@map) {
    my ($first, $second) = @{ $pair };
    $second = "Undefined" unless defined $second;
    print $first . " : " . $second . "\n";
}


__DATA__

a
b       a
c       b
d       c
e       c
f       a
g       d
h       f
I       f
j       i
k       i
l       k
m       a

__END__

The datastructure used, an array of arrays, has limited
use depending on how you wish to navigate the data.
The Graph module from CPAN might do the trick... although
documentation seems confusing for doing traversals.  Some
sort of Graphing module is the correct way to go.

http://search.cpan.org/author/JHI/Graph-0.20101/

***
* The correct place to go for further help is *
* [EMAIL PROTECTED]                          *
                                            ***

Take care,

Jonathan Paton

=====
s''! v+v+v+v+  J r e P    h+h+h+h+ !s`\x21`~`g,s`^ . | ~.*``mg,$v=q.
 P ! v-v-v-v-  u l r e r  h-h-h-   !12.,@.=m`.`g;do{$.=$2.$1,$.=~s`h
 E !   v+v+v+  s     k e  h+h+     !`2`x,$.=~s`v`31`,print$.[$v+=$.]
 R !     v-v-  t H a c h  h-       !}while/([hv])([+-])/g;print"\xA"
 L !             A n o t           !';$..=$1while/([^!]*)$/mg;eval$.

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Reply via email to