develooper Front page | perl.beginners | Postings from February 2012

Re: Introduction and Perl 5 References

Thread Previous
From:
Parag Kalra
Date:
February 27, 2012 17:27
Subject:
Re: Introduction and Perl 5 References
Message ID:
CADSDpOD=ZTzs80L8-dTGdVTNYQ82iGjc_e1pt=bp-yCr5Dx+oQ@mail.gmail.com
On Mon, Feb 27, 2012 at 5:02 PM, Mike <ekimdunaway@gmail.com> wrote:

> Hello everyone.


Hi


> I just wanted to introduce myself to the list. Been following for a little
> while, first time posting. My name is Mike Dunaway and I am 25 years old. I
> was curious if there were any other members in the 804 area?


Do you mean, phone area code of 804?. See if this helps

http://www.pm.org/groups/united_states_of_america.html



> Would anyone mind explaining references to me like I was five years old?


 References are like pointers in C. References can be created to different
data structures like scalars, arrays, hashes, subroutines etc.

And they can be created using a back-slash (\)

EG:

my $var = 'FooBar';
my @arr = ('Hello', 'World');

So if you wanted to create a reference to $var or @arr, you can do it in
following way:

my $ref_to_scalar = \$var;
or
my $ref_to_array = \@arr;

Now if you want to print the data structures through references, one of the
way is:

print "Value of scalar: ${$ref_to_scalar}\n";
print "Elements of array: @{$ref_to_array}\n";

I read about them in Beginning Perl, but I can't quite grasp them very
> well. Thanks!


I would strongly recommend to read it again. My advice - Do not advance to
next chapter till you understand the current chapter.

It's one of the best books on Perl and highly recommended for beginners.

HTH

Cheers,
Parag


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About