Perl reference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl reference
# 1  
Old 07-13-2010
Error Perl reference

Hi all,

I have a reference named $test. it points to the data structure as follows

Code:
                                                                'test' => [
                                                                         {
                                                                           'argument' => [
                                                                                         '10.42.33.0',
                                                                                         '255.255.255.0',
                                                                                         '10.42.33.1',
                                                                                         'athtem.eei.ericsson.se',
                                                                                         '159.107.163.3'
                                                                                       ]
                                                                         },
                                                                         {
                                                                           'argument' => [
                                                                                         '10.10.10.0',
                                                                                         '255.255.255.0',
                                                                                         '10.10.10.1',
                                                                                         'athtem.eei.ericsson.se',
                                                                                         '159.107.163.3'
                                                                                       ]
                                                                         },
                                                                         {
                                                                           'argument' => [
                                                                                         '192.168.1.0',
                                                                                         '255.255.255.0',
                                                                                         '192.168.1.1',
                                                                                         'athtem.eei.ericsson.se',
                                                                                         '159.107.163.3'
                                                                                       ]
                                                                         }
                                                                       ]


or

Code:
                                                                'test' => {
                                                                         'argument' => [
                                                                                       'RBS15_SITE1',
                                                                                       'eRBS15_SITE1'
                                                                                     ]
                                                                       }

$test may be the reference of a hash or array.
I want to get the value of the argument
using
Code:
my @arguments=@{$tests->[$i]->{'argument'}};

or
Code:
my @arguments=@{$tests->{'argument'}};

how can i judge that the $test is the reference of a array or a hash?
Code:
print Scalar::Util::reftype(\$tests)

I use this method to decide.
But it seems that the output always REF
What can i do??

Thanks
Damon
# 2  
Old 07-13-2010
What's the problem with using ref:

Code:
% perl -le'
$test = {
  argument => [
    'RBS15_SITE1',
    'eRBS15_SITE1'
     ]
 };

print ref
  for $test, $test->{argument};
  ' 
HASH
ARRAY


Last edited by radoulov; 07-13-2010 at 09:48 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get last reference date

Hi, Could you please help me to get last reference date in Unix, in Unix we maintain SAS7BDAT files. Is there any command or script to get the info, Thank you. (2 Replies)
Discussion started by: subbarao12
2 Replies

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

3. Shell Programming and Scripting

Reference of hash (Perl)

Hi Perl users, Could somebody help me to find the solution of my problem below. Here is my data: __DATA__ =================================================== NameOfipaddress ippair_1 propertiesx y propertiesy x... (1 Reply)
Discussion started by: askari
1 Replies

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

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. UNIX for Dummies Questions & Answers

Book reference

hello I am looking for book reference far Linux books that have information that is up to date. Example: Running Linux, O`Reilly, year 1995. Or Linux Administration, A beginners guide, 5`th ed, Mc Graw Hill Osbourn, year 2009. Thank you (2 Replies)
Discussion started by: cowLips
2 Replies

7. Shell Programming and Scripting

Symbol reference

Hi, test -d .ssh || mkdir .ssh && chmod 700 .ssh The command has couple of symbols, could someone redirect me to the link, where i can understand their significance. Thanks, John (1 Reply)
Discussion started by: john_prince
1 Replies

8. Shell Programming and Scripting

Perl: Getting back reference from s modifier

My input text has the following pattens: func_a(3, 4, 5); I want to replace it with this: func_b(3, 4, 5, 6); I'm trying the following expression, but it does not work: perl -p -e "s/func_a\((.*)?\);/func_b(\1,\n6)/s" <... (8 Replies)
Discussion started by: cooldude
8 Replies

9. Shell Programming and Scripting

Reference two dimensional array in Perl sub

I am trying to reference a two dimensional array in a subroutine and can't seem to figure this one out in Perl. Does anybody know? Please enlighten me. #!/usr/bin/perl -w use constant DIM => 4; sub Shift_elements_right{ my (@Input, @Output) = @_; for ($i = 0 ; $i <= DIM ;... (5 Replies)
Discussion started by: photon
5 Replies
Login or Register to Ask a Question