Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 682191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:34:05+00:00 2026-05-14T01:34:05+00:00

In Perl, when you have a nested data structure, it is permissible to omit

  • 0

In Perl, when you have a nested data structure, it is permissible to omit de-referencing arrows to 2d and more level of nesting. In other words, the following two syntaxes are identical:

my $hash_ref = { 1 => [ 11, 12, 13 ], 3 => [31, 32] };

my $elem1 = $hash_ref->{1}->[1]; 
my $elem2 = $hash_ref->{1}[1]; # exactly the same as above

Now, my question is, is there a good reason to choose one style over the other?

It seems to be a popular bone of stylistic contention (Just on SO, I accidentally bumped into this and this in the space of 5 minutes).

So far, almost none of the usual suspects says anything definitive:

  • perldoc merely says “you are free to omit the pointer dereferencing arrow”.
  • Conway’s “Perl Best Practices” says “whenever possible, dereference with arrows”, but it appears to only apply to the context of dereferencing the main reference, not optional arrows on 2d level of nested data structures.
  • “Mastering Perl for Bioinfirmatics” author James Tisdall doesn’t give very solid preference either:

    “The sharp-witted reader may have
    noticed that we seem to be omitting
    arrow operators between array
    subscripts. (After all, these are
    anonymous arrays of anonymous arrays
    of anonymous arrays, etc., so
    shouldn’t they be written
    [$array->[$i]->[$j]->[$k]?) Perl
    allows this; only the arrow operator
    between the variable name and the
    first array subscript is required. It
    make things easier on the eyes and
    helps avoid carpal tunnel syndrome. On
    the other hand, you may prefer to keep
    the dereferencing arrows in place, to
    make it clear you are dealing with
    references. Your choice.”

  • UPDATED “Intermediate Perl”, as per its co-author brian d foy, recommends omitting the arrows. See brian’s full answer below.

Personally, I’m on the side of “always put arrows in, since it’s more readable and obvious they’re dealing with a reference”.

UPDATE To be more specific re: readability, in case of a multi-nested expression where subscripts themselves are expressions, the arrows help to “visually tokenize” the expressions by more obviously separating subscripts from one another.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:34:06+00:00Added an answer on May 14, 2026 at 1:34 am

    Unless you really enjoy typing or excessively long lines, don’t use the arrows when you don’t need them. Subscripts next to subscripts imply references, so the competent programmer doesn’t need extra clues to figure that out.

    I disagree that it’s more readable to have extra arrows. It’s definitely unconventional to have them moving the interesting parts of the term further away from each other.

    In Intermediate Perl, where we actually teach references, we tell you to omit the unnecessary arrows.

    Also, remember there is no such thing as "readability". There is only what you (and others) have trained your eyes to recognize as patterns. You don’t read things character-by-character then figure out what they mean. You see groups of things that you’ve seen before and recognize them. At the base syntax level that you are talking about, your "readability" is just your ability to recognize patterns. It’s easier to recognize patterns the more you use it, so it’s not surprising that what you do now is more "readable" to you. New styles seem odd at first, but eventually become more recognizable, and thus more "readable".

    The example you give in your comments isn’t hard to read because it lacks arrows. It’s still hard to read with arrows:

     $expr1->[$sub1{$x}]{$sub2[$y]-33*$x3}{24456+myFunct($abc)}
     $expr1->[$sub1{$x}]->{$sub2[$y]-33*$x3}->{24456+myFunct($abc)}
    

    I write that sort of code like this, using these sorts of variable names to remind the next coder about the sort of container each level is:

    my $index = $sub1{$x};
    my $key1  = $sub2[$y]-33*$x3;
    my $key2  = 24456+myFunct($abc);
    
    $expr1->[ $index ]{ $key1 }{ $key2 };
    

    To make that even better, hide the details in a subroutine (that’s what they are there for 🙂 so you never have to play with that mess of a data structure directly. This is more readable that any of them:

      my $value = get_value( $index, $key1, $key2 );
    
      my $value = get_value(
          $sub1{$x},
          $sub2[$y] - 33*$x3,
          24456 + myFunct($abc)
          );
         
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, it seems more simply that your PDF is using… May 14, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer In fact, the behaviour of __import__() is entirely because of… May 14, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer You can use the OnSelecting event of your datasource and… May 14, 2026 at 4:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.