Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Creating a Multi Level Hash from CSV

by workInProgress12 (Novice)
on May 13, 2021 at 17:15 UTC ( #11132538=note: print w/replies, xml ) Need Help??


in reply to Re: Creating a Multi Level Hash from CSV
in thread Creating a Multi Level Hash from CSV

I'm really sorry about the confusion, fixed the sample output now. I'm supposed to print the CSV file separated with | as the end goal, which I realize could just be done with a simple split and join statement (which I was able to do) but was asked specifically to do with multi level hash, gotta do what the boss asks I guess.
  • Comment on Re^2: Creating a Multi Level Hash from CSV

Replies are listed 'Best First'.
Re^3: Creating a Multi Level Hash from CSV
by AnomalousMonk (Bishop) on May 15, 2021 at 02:24 UTC
    ... fixed the sample output ...

    Further to Marshall's post:

    ... it is good form to preserve the original version ...
    Please see How do I change/delete my post? The bottom line: Please do not destroy context.


    Give a man a fish:  <%-{-{-{-<

Re^3: Creating a Multi Level Hash from CSV
by Marshall (Canon) on May 15, 2021 at 01:55 UTC
    I see your updates. BTW, when you update your post, it is good form to preserve the original version so later readers can figure out what is going on. You can "hide" say a previous section with <readme> <readmore>tags. Note: I made a typo and works out to be a demo of method of updating a post...the <strike> tags!

    I am still confused by this: Important to note that there are repeated values, which is the case for the provided sample output, (ie info 01 = info11, info02 = info12, etc.), but this is not always the case.. As you can see there have been multiple interpretations of your problem statement. My interpretation is shown below which allows for duplicated values in the CSV line(s).

    In general, the more you tell us about your problem, the more helpful the Monks can be. I didn't understand any more about what you are actually doing with this data structure. You may find that is a very awkward thing to work with.

    I would be curious to know how close my "crystal ball" got.

    use strict; use warnings; use Data::Dumper; my %hash; foreach my $line (<DATA>) #simulated simple CSV file { my @cols = (split /,|\n/,$line); my $href = \%hash; while (my $col = shift @cols) { $href->{$col} = {} unless (exists ($href->{$col}) and keys %{$href->{$col}} ); $href = $href->{$col}; } } print Dumper \%hash; =OUTPUT: $VAR1 = { 'x' => { '5' => { '6' => {} } }, 'a' => { 'x' => { 'e' => {}, 'm' => {}, 'c' => {} }, 'b' => { 'c' => {} }, 'y' => { 'h' => {} } } }; =cut __DATA__ a,x,c a,x,e a,y,h a,x,m a,b,c x,5,6
      You can "hide" say a previous section with <readme> tags.

      Maybe you wanted to say <readmore>?

      Greetings,
      -jo

      $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
        Yep, that was a typo. updated my post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132538]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-10-22 01:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?