pointer in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pointer in perl
# 1  
Old 07-05-2010
pointer in perl

Hi all,
using Data:: Dumper to display the content which a pointer point to .
$config is a pointer
using Dumper($config) to display the content as follows
Code:
$VAR1 = {
          'Jack' => {
                    'priority' => '0',
                    'remotepasswd' => 'shroot',
                    'remoteaddress' => '10.33.42.44',
                    'logdir' => '/jack/ocsta/log/',
                    'remoteuser' => 'root',
                    'timeout' => '200',
                    'scriptroot' => '/jack/ocsta/testscripts/',
                  },
          'Damon' => {
                     'priority' => '0',
                     'remotepasswd' => 'shroot',
                     'remoteaddress' => '10.33.42.76',
                     'logdir' => '/eweiquu/ocsta/log/',
                     'remoteuser' => 'root',
                     'timeout' => '300',
                     'scriptroot' => '/eweiquu/ocsta/testscripts/',
        };

how can i traverse this hash using the pointer?

N.B:if we want to get the value of Jack. we can use the statement as follows:

Code:
$config-> {"Jack"}->{"timeout"};

Thanks
Damon

Last edited by pludi; 07-05-2010 at 12:31 PM.. Reason: code tags, please...
# 2  
Old 07-05-2010
Perl has no pointers, but references. And you can traverse a hash of hashes (as in your example) the same way as a regular hash:
Code:
foreach my $name ( sort keys %{$config} ) {
    foreach my $option (sort keys %{$config->{$name}} ) {
        print "$name -> $option -> ", $config->{$name}->{$option}, "\n";
    }
}


Last edited by pludi; 07-05-2010 at 01:03 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Pointer to pointers

Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It. Can someone help? #include <stdio.h> #include <stdlib.h> #include <assert.h> int f1(char **str_); int main(int argc, char **argv) { char *str = NULL; f1(&str); ... (3 Replies)
Discussion started by: pharaoh
3 Replies

2. Programming

Pointer Arithmetic In C

I have a fundamental question on C pointer arithmetry.. Suppose i have a c string pointer already pointing to a valid location, Can I just do a charptr = charptr +1; to get to the next location, irregardless if my program is 32 or 64 bits? or should i do it this way: charptr =... (1 Reply)
Discussion started by: Leion
1 Replies

3. Programming

C dynamic pointer

Hi, Can anyone tell me how i can declare and allocate dynamically an array of pointers to structured type?? Is declaration something like this:? struct_name ** array; (1 Reply)
Discussion started by: littleboyblu
1 Replies

4. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

5. Shell Programming and Scripting

Perl how to move pointer to previous line in a txt file?

I have a text file that has blocks of text. Each block starts with ### and ends with End_###. I wrote a perl script to search a string from line 2 (ignore any line starts with ###) of each block if matched, need to print that whole block. According to the input file in below, it will print... (5 Replies)
Discussion started by: tqlam
5 Replies

6. Programming

far pointer

what is far pointer in C (1 Reply)
Discussion started by: useless79
1 Replies

7. Programming

Regarding char Pointer

Hi, char *s="yamaha"; cout<<s<<endl; int *p; int i=10; p=&i; cout<<p<<endl; 1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s. 2) But for integer "cout<<p" we are getting the "address only". Please clarify how we are... (2 Replies)
Discussion started by: sweta
2 Replies

8. Programming

file pointer

what is the difference between a file pointer and a file descriptor. (1 Reply)
Discussion started by: bankpro
1 Replies

9. Programming

file pointer

hi all: bankpro again, i want to open a file and close it after an hour (i.e open and close the file ptr) In the mean time i will be executing my jobs using the shell (CommandInterpreter). plz help... :cool: (3 Replies)
Discussion started by: bankpro
3 Replies

10. Programming

pointer

void main() { int a={1,2,3,4,5,6,7,8,9,10}; int *p=a; int *q=&a; cout<<q-p+1<<endl; } The output is 10, how? if we give cout<<q it will print the address, value won't print.... if we give cout<<p it will print the address, value won't print.... p has the base addr; q... (1 Reply)
Discussion started by: sarwan
1 Replies
Login or Register to Ask a Question