Re: Data file from one format to another.



On Wed, Feb 27, 2008 at 9:27 PM, Nobody Imparticular
<forcrimanysakes@xxxxxxxxx> 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!


Relevant Pages

  • Re: data types
    ... > binary.However when I am porting this to perl,I need to worry about ... > the exact data format in the file. ... > In my pl/1 program I am manipulating the bitstrings only to compute ...
    (comp.lang.perl.misc)
  • Re: [Full-disclosure] Using domain whois information for fun and profit
    ... The question is one of data format. ... many major operating systems come with a text-based whois client and that whois client is meant to process plaintext data. ...
    (Full-Disclosure)
  • Re: Will the CD-Audio soon be pushed from the market by another kind of media?
    ... pro and con-arguments to this topic in order to ... My "opinion" will be: Yes, the consumer claims to have new ... The underlying digital data format will span media content ...
    (rec.audio.pro)
  • Re: data types
    ... >> the exact data format in the file. ... > it in Perl, or, if I can't, how should I re-format it so that I can. ...
    (comp.lang.perl.misc)
  • Re: Printing large format trees
    ... I would really like to be able to format this to a large ... Is FTM capable of formatting an ALL-in-One tree to this size? ... Tools to get the big charts I've taken to family reunions in the past. ...
    (soc.genealogy.computing)