Sponsored Content
Top Forums Shell Programming and Scripting Separate a hash variable into 2 parts in Perl Post 302948451 by askari on Monday 29th of June 2015 06:47:43 PM
Old 06-29-2015
Separate a hash variable into 2 parts in Perl

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:

Code:
    
 'Perl1' => {
                'scripting' => [
                                'language'
                               ],
                                
            },
 'Perl2' => {
                'scripting' => [
                                'language'
                               ],
              },
 'Perl3' => {
                'scripting' => [
                                'language'
                               ],
              },
 'Perl4' => {
                'scripting' => [
                                'language'
                               ],
             },
 'Perl5' => {
                'scripting' => [
                                'language'
                               ],
             },

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

The result that I want is:

Code:
"Perl1 Perl2 Perl3" -> "perl4 Perl 5 Perl6"
 
language -> scripting -> "Perl1 Perl2 Perl3 Perl4 Perl5 Perl6"

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Pattern Matching a HASH variable

Hi All, I'm trying to test a Hash variable but it's not working. Here is my code - can anyone tell me if the test is valid? for (keys %enabled_yn) { if ($enabled_yn{$1} =~ m/\s+Y/) { $html =~ s/%(\w+)%/\<b\>\<font color\=orange\>$enabled_yn{$1}\<\/font\>\<\/b\>/g; }... (1 Reply)
Discussion started by: pondlife
1 Replies

2. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below. #!/usr/bin/perl use warnings; use Tie::IxHash; use strict; tie (my %programs, "Tie::IxHash"); while (my $line = <DATA>) { chomp $line; my(... (1 Reply)
Discussion started by: jgfcoimbra
1 Replies

3. UNIX for Advanced & Expert Users

Passing Hash variable in to sql query in perl

Hi Everyone, Can anyone help me how do i call hash variable in to sql query in perl. Please see the script below i have defined two Hash %lc and %tab as below $lc{'REFF'}='V_RES_CLASS'; $lc{'CALE'}='V_CAP_CLASS'; $lc{'XRPD'}='V_XFMR_CLASS'; $tab{'V_RES_CLASS'}='V_MFR_SERS';... (6 Replies)
Discussion started by: jam_prasanna
6 Replies

4. Shell Programming and Scripting

perl hash - using a range as a hash key.

Hi, In Perl, is it possible to use a range of numbers with '..' as a key in a hash? Something in like: %hash = ( '768..1536' => '1G', '1537..2560' => '2G' ); That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies

5. Shell Programming and Scripting

Perl: accessing reference to variable inside hash.

Below is hash which contains reference to variables: my %mandatoryFields = ( 1 => \$msgtype, 2 => \$switchtype, 3 => \$card_nbr, 4 => \$natv_tran_type_code, 5 => \$amt_1 ); This... (0 Replies)
Discussion started by: som.nitk
0 Replies

6. Shell Programming and Scripting

Using bash to separate files files based on parts of a filename

Hey guys, Sorry for the basic question but I have a lot of files that I want to separate into groups based on filenames which I can then cat together. Eg I have: (a_b_c.txt) WB34_2_SLA8.txt WB34_1_SLA8.txt WB34_1_DB10.txt WB34_2_DB10.txt WB34_1_SLA8.txt WB34_2_SLA8.txt 77_1_SLA8.txt... (1 Reply)
Discussion started by: Breentax
1 Replies

7. Shell Programming and Scripting

In Perl can i define a hash with value as variable?

Hi, Is it possible in perl to have a hash defined with variables as theirs key values, like: %account = ('username' => 'boy', 'password' => $password); Thanks (1 Reply)
Discussion started by: zing_foru
1 Replies

8. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

9. Shell Programming and Scripting

How to parse parts of 1 column into two separate columns?

I have a shell script that is currently transferring a csv file from a server into a Teradata database table. One of the 30 or so columns is called "destination_url". In that URL there are parameters, and it is possible for those parameters to be repeated because of referring companies copying... (3 Replies)
Discussion started by: craigwg
3 Replies

10. Shell Programming and Scripting

Improve awk code that has three separate parts

I have a very inefficient awk below that I need some help improving. Basically, there are three parts, that ideally, could be combined into one search and one output file. Thank you :). Part 1: Check if the user inputted string contains + or - in it and if it does the input is writting to a... (4 Replies)
Discussion started by: cmccabe
4 Replies
Digest::JHash(3pm)					User Contributed Perl Documentation					Digest::JHash(3pm)

NAME
Digest::JHash - Perl extension for 32 bit Jenkins Hashing Algorithm SYNOPSIS
use Digest::JHash qw(jhash); $digest = jhash($data); # note that calling jhash() directly like this is the fastest way: $digest = Digest::JHash::jhash($data); DESCRIPTION
The "Digest::JHash" module allows you to use the fast JHash hashing algorithm developed by Bob Jenkins from within Perl programs. The algorithm takes as input a message of arbitrary length and produces as output a 32-bit "message digest" of the input in the form of an unsigned long integer. Call it a low calorie version of MD5 if you like. See http://burtleburtle.net/bob/hash/doobs.html for more information. FUNCTIONS
jhash($data) This function will calculate the JHash digest of the "message" in $data and return a 32 bit integer result (an unsigned long in the C) EXPORTS
None by default but you can have the jhash() function if you ask nicely. See below for reasons not to use Exporter (it is slower than a direct call) SPEED NOTE
If speed is a major issue it is roughly twice as fast to do call the jhash() function like Digest::JHash::jhash('message') than it is to import the jhash() method using Exporter so you can call it as simply jhash('message'). There is a short script that demonstrates the speed of different calling methods (direct, OO and Imported) in examples/oo_vs_func.pl AUTHORS
The JHash implementation was written by Bob Jenkins <bob_jenkins [at] burtleburtle [dot] net>. This perl extension was written by Andrew Towers <mariofrog [at] bigpond [dot] com>. A few mods were added by James Freeman <airmedical [at] gmail [dot] com>). SEE ALSO
http://burtleburtle.net/bob/hash/doobs.html LICENSE
This package is free software and is provided "as is" without express or implied warranty. It may be used, redistributed and/or modified under the terms of the Artistic License 2.0. A copy is include in this distribution. perl v5.14.2 2010-07-26 Digest::JHash(3pm)
All times are GMT -4. The time now is 05:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy