Logo

Programming-Idioms

History of Idiom 5 > diff from v1 to v2

Edit summary for version 2 by :

Version 1

2015-05-06, 21:04:46

Version 2

2015-07-31, 19:07:58

Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

Code
# For named member access
my $point = { x=>1.5, y=>6.3 };
print "Coordinates: x=$point->{x}, y=$point->{y}\n";

# Or an array using index 0, 1 to hold x, y
my $point = [ 1.5, 6.3 ];
print "Coordinates: x=$point->[0], y=$point->[1]\n";
Comments bubble
For lists, perl uses arrays. For structures (like a 2D point) hashes are more commonly used.