Compound data type: Difference between revisions

Content added Content deleted
(added factor example)
(Perl 5: Slightly reformatted. Perl 6: Added.)
Line 479: Line 479:


=={{header|Perl}}==
=={{header|Perl}}==

{{works with|Perl|5.x}}
===Built-in Hash===
===Array===
<lang perl>my @point = (3, 8);</lang>
This is a hash (associative array), but accomplishes the task.

===Hash===
<lang perl>my %point = (
<lang perl>my %point = (
x => 3,
x => 3,
Line 487: Line 489:
);</lang>
);</lang>


===Built-in Array===
===Class instance===
<lang perl>my $point = [3, 8];</lang>

===Class===
<lang perl>package Point;
<lang perl>package Point;


Line 498: Line 497:
y => '$',
y => '$',
;
;

1;


my $point = Point->new(x => 3, y => 8);</lang>
my $point = Point->new(x => 3, y => 8);</lang>

=={{header|Perl 6}}==
{{works with|Rakudo|#24 "Seoul"}}

===Array===
<lang perl6>my @point = 3, 8;</lang>

===Hash===
<lang perl6>my %point = x => 3, y => 8;</lang>

===Class instance===
<lang perl6>class Point { has $.x is rw; has $.y is rw; }
my Point $point .= new(x => 3, y => 8);</lang>


=={{header|PHP}}==
=={{header|PHP}}==