On Wed, Feb 27, 2008 at 9:27 PM, Nobody Imparticular
<[EMAIL PROTECTED]> wrote:
> Hi any and all;
>
>  I am having a heck of time getting my head around a
>  little problem I have run into; I got this question
>  during an interview recently and, well, failed
>  miserably.  Now I am crazy to figure out the answer
>  since the answer seems like it would be easy, but
>  isn't (to me).
>

Your real problem here is lack of specicifity. There is no way,
abstractly, to convert one data format to another. There are lots of
way, however, to convert specific formats to to other specific
formats. Help us help you. You have (apparently) a file with some
columnar data and you want to convert it to...what? XML, a hash of
hashes? A hash of arrays? YAML? What?


>  I need to massage the data and print it out (to the
>  screen or file) as follows:
>
>     A
>       B C D
>             E F
>                 G
>                 H
>                 I J
>             K L
>             M N
>             O P
>             Q R
>       S
>         T
>         U
>

Again, what is the data, and what is this format? What are you using
it for? If it is a popular data format or output from a popular
program, there is probably a module out there already that will do it
for you. But we need a little more to go on. So far, it looks like
Data::Dumper would go a long way toward getting you what you need. I'm
not clear, though, as to what the relationship between DEFGHI is,
though. What rule forces 'IJ', for instance, to be interpreted as a
single token and printed on a single line?

Again, we need a little more to go on.

Based on what you've shown so far, though, something like the
following should work:


my $tree = {};
while (<DATA>) {
    chomp;
        my @line = split;
    my $this = $tree;
    foreach (@line) {
        $this->{$_} = {} unless exists $this->{$_};
        $this = $this->{$_};
    }
}


Printing the structure out is up to you, but Data::Dumper would be a
good place to start.


HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to