Sponsored Content
Full Discussion: Reference of hash (Perl)
Top Forums Shell Programming and Scripting Reference of hash (Perl) Post 302759241 by askari on Tuesday 22nd of January 2013 01:31:02 AM
Old 01-22-2013
Reference of hash (Perl)

Hi Perl users,

Could somebody help me to find the solution of my problem below.
Here is my data:
Code:
__DATA__
===================================================
NameOfipaddress                       ippair_1
propertiesx                           y
propertiesy                           x
ipAddress_1                           192.168.200.1
ipAddress_2                           192.168.200.2 
===================================================
NameOfipaddress                       ippair_2
propertiesx                           y
propertiesy                           x
ipAddress_1                           192.168.200.3
ipAddress_2                           192.168.200.4

Here is the expected result of the code:
Code:
__EXPECTED_RESULT__
FIRST_IP_PAIR
NameOfipaddress : ippair_1       
ipAddress_1     : 192.168.200.1  
ipAddress_2     : 192.168.200.2 

SECOND_IP_PAIR
NameOfipaddress : ippair_2
ipAddress_1     : 192.168.200.3
ipAddress_2     : 192.168.200.4

Here is my code and the unexpected result:

Code:
LINE:while (my $line = <FH>){
         chomp ($line);
         if ($line =~ m/^(NameOfipaddress)\s*(.*)/){
           push @{$datalog{'IP'}{$1}}, $2;
           next;
         }
         if ($line =~ m/^(ipAddress_1)\s*(.*)/){
           push @{$datalog{'IP'}{$1}}, $2;
           next;
         }
         if ($line =~ m/^(ipAddress_2)\s*(.*)/){
           push @{$datalog{'IP'}{$1}}, $2;
           redo LINE if ($line =~ m/^(NameOfipaddress)\s*(.*)/);
         }
     }
     
foreach my $key (sort keys %{$datalog{'IP'}}){
   print "$key: @{$datalog{'IP'}{$key}}";
   print "\n";
}     

__UNEXPECTED_RESULT(my code result)__
NameOfipaddress : ippair_1       ippair_2
ipAddress_1     : 192.168.200.1  192.168.200.3
ipAddress_2     : 192.168.200.2  192.168.200.4

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hash in perl

Hi Help me with some good links of Hash with in Hash .(Multidimensional hash).. Regards Harikrishna (1 Reply)
Discussion started by: Harikrishna
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. Shell Programming and Scripting

hash of hashes : how to print reference and its internal structure?

#use perl 5.8.5; my %h1=(a=>'b', c=>'d'); my %h2=(a1=>'b1', c1=>'d1'); my $R1=\%h1; my $R2=\%h2; my %h= {$R1, $R2}; my $href=\%h; # hash of hashes foreach my $key (keys %$href){ print "Z::$$href{$key}\n" } When I am trying to print elements of hash of hashes, it prints HASH... (1 Reply)
Discussion started by: shristi
1 Replies

4. Shell Programming and Scripting

Perl reference

Hi all, I have a reference named $test. it points to the data structure as follows 'test' => }, ... (1 Reply)
Discussion started by: Damon sine
1 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Perl de-reference code reference variable

Guys, May i know how can we de reference the code reference variable.? my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";}; print $a->(4,5); How can we print the whole function ? Please suggest me regarding this. Thanks for your time :) Cheers, Ranga :) (0 Replies)
Discussion started by: rangarasan
0 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

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

10. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies
AGGREGATE-IOS(1)					      General Commands Manual						  AGGREGATE-IOS(1)

NAME
aggregate-ios - optimise a concatenated set of cisco/IOS prefix filters to help make them nice and short. SYNOPSIS
aggregate-ios <source_config >optimised_config DESCRIPTION
Takes cisco IOS configuration on stdin, and optimises any prefix filters found using aggregate(1). Optimised filters are produced on std- out. OPTIONS
None. DIAGNOSTICS
Any diagnostics produced by aggregate(1) are passed through on stderr. EXAMPLES
The following configuration fragment: ip prefix-list AS65530 description Foo, Inc ip prefix-list AS65530 permit 10.1.0.0/16 ip prefix-list AS65530 permit 10.2.0.0/16 ip prefix-list AS65530 permit 10.2.1.0/24 ip prefix-list AS65530 permit 10.3.0.0/16 ip prefix-list AS65531 description Bar.Com ip prefix-list AS65531 seq 5 permit 192.168.1.0/24 ip prefix-list AS65531 seq 10 permit 192.168.2.0/24 ip prefix-list AS65531 seq 15 permit 192.168.0.0/19 is optimised as follows: ip prefix-list AS65530 permit 10.1.0.0/16 le 24 ip prefix-list AS65530 permit 10.2.0.0/15 le 24 ip prefix-list AS65531 permit 192.168.0.0/19 le 24 SEE ALSO
aggregate(1) HISTORY
Aggregate-ios was written by Joe Abley <jabley@mfnx.net>. BUGS
All those in aggregate(1) and then some :) Joe Abley 2000 November 27 AGGREGATE-IOS(1)
All times are GMT -4. The time now is 07:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy