Shlomi Fish  committed 386b9fc

Add the several synchronised arrays bad element.

  • Participants
  • Parent commits 085b244
  • Branches default

Comments (0)

Files changed (1)

File src/tutorials/bad-elements/perl-elements-to-avoid.xml-grammar-vered.xml

+<item xml:id="several_synchronised_arrays">
+<title>Several synchronised arrays.</title>
+Related to “varvarname” is the desire of some beginners to use several
+different arrays with synchronised content, so the same index at every array
+will contain a different piece of data for the same record:
+<bad_code syntax="perl">
+my @names;
+my @addresses;
+my @ages;
+my @phone_numbers;
+push @names, 'Isaac Newton';
+push @addresses, '10 Downing St.';
+push @ages, 25;
+push @phone_numbers, '123456789';
+These arrays will become hard to synchronise, and this is error prone. A
+better idea would be to use an array (or a different data structure) of
+hash references or objects:
+<code_blk syntax="perl">
+my @people;
+push @people, Person->new(
+    {
+        name => 'Isaac Newton',
+        address => '10 Downing St.',
+        age => 25,
+        phone_number => '123456789',
+    },
 <item xml:id="leading_underscores">
 <title>Use Leading Underscores ('_') for Internal Methods and Functions</title>