perl explain syntax !!!


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users perl explain syntax !!!
# 1  
Old 05-08-2009
perl explain syntax !!!

hi all
i was going through some perl code i came across this line and i am not getting what is exactly going on ..

Code:
$$this{localtion} = GetName->GetVarName("EXE_DIR") ;

what is the red part doing in above code
# 2  
Old 05-08-2009
From the hash 'this', get the value associated with the key 'localtion', and treat it as a reference to a scalar.
# 3  
Old 05-12-2009
Quote:
Originally Posted by pludi
From the hash 'this', get the value associated with the key 'localtion', and treat it as a reference to a scalar.
This is not really correct.

$this is a hash reference. That is, a reference to a hash. $$this{'location'} dereferences $this to access the value associated with the "location" key.

Another way to write this is $this->{'location'} = 'xxxxxxx';

You may easily confirm this by using Data::Dumper to inspect complex data structure.

Code:
C:\Users\bernardchan>perl -MData::Dumper -e "$$this{'location'}='xxxx'; print Dumper($this)"
$VAR1 = {
          'location' => 'xxxx'
        };

C:\Users\bernardchan>perl -MData::Dumper -e "$this->{'location'}='xxxx'; print Dumper($this)"
$VAR1 = {
          'location' => 'xxxx'
        };

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Perl/Array Sorting : Can someone please explain below code $h{$_}++

sub uniq { my %h; return grep { !$h{$_}++ } @_ } The above code is to remove duplicates from array. I am having hard time understanding below things (basically around highlighted code in bold)- when was the value inserted in hash? and are we only adding a key in Hash not... (1 Reply)
Discussion started by: Tanu
1 Replies

2. UNIX for Dummies Questions & Answers

Perl syntax

Query with perl syntax Aim: is to change a perl script to use a new file I was required to replace - entries \"$entries\" with -lib <full_path_to_filename> So in the code detector.pm sub rundetector { my $class = shift; mkdir($resultDirectory); my... (3 Replies)
Discussion started by: sa@@
3 Replies

3. Shell Programming and Scripting

Perl syntax

I'm a newbie to perl scripting. Can someone please explain the syntax below. Specifically what does -> and => do? $tz->site( => $site); (10 Replies)
Discussion started by: scj2012
10 Replies

4. Shell Programming and Scripting

can you explain this perl command?

I am using this line of perl code to change the file format and remove ^M at the end of each line in files: perl -i -pe's/\r$//;' <name of file here> Can you explain to me what this code does, and translate it into bash/awk/sed? (2 Replies)
Discussion started by: locoroco
2 Replies

5. UNIX for Dummies Questions & Answers

Explain perl formatting commands

Could you please tell the meaning of Below mentioned perl script lines: format OWNER_TOTAL = @< Owner Code @<<<<<<total: @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @#######.## @###### #.## $prev_cust_type, $prev_owner_code,... (2 Replies)
Discussion started by: vinothrajan55
2 Replies

6. Shell Programming and Scripting

Can someone please explain what tr#A-Za-z0-9+/# -_#; means in perl?

Can someone please explain what tr#A-Za-z0-9+/# -_#; means in perl? (4 Replies)
Discussion started by: 3junior
4 Replies

7. Shell Programming and Scripting

perl syntax help

Im new at scripting and im trying to write a script using perl that will make sure there are 2 command line integer arguments and then check if the 2nd argument is greater than the first. i believe im close but still receive my error message even when i have 2 arguments and the second part gives me... (6 Replies)
Discussion started by: livewire06
6 Replies

8. Shell Programming and Scripting

Explain following sed syntax please

Thanks to this forum I have managed to work out a solution to my problem and actually understand most of it, but one thing is confusing me and I am sure someone here can explain. I need to insert a piece of txt into a file. This txt is awk '{ sub(/$/,"\r"); print }' $JCL_WBB50103_EFTOUT >... (2 Replies)
Discussion started by: hukcjv
2 Replies

9. Shell Programming and Scripting

perl: Please explain this for me: $hexdigit = (0 .. 9, 'a' .. 'f')[$num & 15];

This is taken from perlop. I can't understand what's going on, please can someone explain this for me? $hexdigit = (0 .. 9, 'a' .. 'f'); to get a hexadecimal digit (2 Replies)
Discussion started by: ksheller
2 Replies

10. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question