# Separate a hash variable into 2 parts in Perl

**URL:** <https://community.unix.com/t/separate-a-hash-variable-into-2-parts-in-perl/353686>\
**Category:** Shell Programming and Scripting\
**Created:** [June 29, 2015, 6:47pm UTC](https://community.unix.com/t/separate-a-hash-variable-into-2-parts-in-perl/353686 "2015-06-29T18:47:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![askari](https://community.unix.com/letter_avatar/askari/32/5_5575768a8748004e209b776fc1b2916d.png) [@askari](https://community.unix.com/u/askari)\
**Post date:** [June 29, 2015, 6:47pm UTC](https://community.unix.com/t/separate-a-hash-variable-into-2-parts-in-perl/353686/1 "2015-06-29T18:47:43Z")

</div>

Dear Perl users/experts,

Could somebody help me how to solve my problem, I have a hash variable that I want to convert into dot file (graphviz).  
I know how to convert it to dot file but I need some modification on the output of the hash variable before convert it to dot file.

Eeach key of hash variable (Perl1, Perl2, ....Perl6) will be divided into 2 parts.

The hash variable as below:

```nohighlight
    
 'Perl1' => {
                'scripting' => [
                                'language'
                               ],
                                
            },
 'Perl2' => {
                'scripting' => [
                                'language'
                               ],
              },
 'Perl3' => {
                'scripting' => [
                                'language'
                               ],
              },
 'Perl4' => {
                'scripting' => [
                                'language'
                               ],
             },
 'Perl5' => {
                'scripting' => [
                                'language'
                               ],
             },

 'Perl6' => {
                'scripting' => [
                                'language'
                               ],
            },                   
  }       
  

```

The result that I want is:

```nohighlight
"Perl1 Perl2 Perl3" -> "perl4 Perl 5 Perl6"
 
language -> scripting -> "Perl1 Perl2 Perl3 Perl4 Perl5 Perl6"

```

---

<div class="post-metadata">

**Author:** ![derekludwig](https://community.unix.com/letter_avatar/derekludwig/32/5_5575768a8748004e209b776fc1b2916d.png) [@derekludwig](https://community.unix.com/u/derekludwig)\
**Post date:** [August 11, 2015, 7:05am UTC](https://community.unix.com/t/separate-a-hash-variable-into-2-parts-in-perl/353686/2 "2015-08-11T07:05:37Z")

</div>

Can you post what you have tried? And a less-simplistic data sample?

The leaf node (under scripting) is a list containing one element (language). What is the desired output if/when this list contains more than one element?

How was `"Perl1 Perl2 Perl3" -> "Perl4 Perl 5 Perl6"` derived? Where is the dependency?

Did you want the PerlNs combined into a single node?

- D

And
