in reply to Implicit references? module -> feature -> pragma -> "Perl8" ?

"Considered bad style" is subjective. I use it *all the time* to indicate that these are coupled very tightly. $id is the current ID from a list of @id that are worked on and the required data for that ID is in $id{$id}. You do not have to agree, but to my brain that works perfect.

Enjoy, Have FUN! H.Merijn
  • Comment on Re: Implicit references? module -> feature -> pragma -> "Perl8" ?

Replies are listed 'Best First'.
Re^2: Implicit references? module -> feature -> pragma -> "Perl8" ?
by LanX (Saint) on May 13, 2026 at 11:25 UTC
    TIMTOWTDI this will still work and nobody is forcing you to use a new pragma

    I personally would have preferred° to have

    for my $id (@ids) { my $data = $datas{$id}; # or $data_of{} ¹ ... }

    or are you planing to later write my $id = $id{$id} when accessing the values?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    °) Actually depending on context I would prefer more specific names than id and data unless the surrounding is very clear and small. Like $person_id and $address{$person_id}

    When reading a large code base again and again it's nice to immediately distinguish the hashes in different subs.

    ¹) using plural for hashes is actually not PBP (IIRC?), not sure how best to solve it.

    %id_data is a bit redundant, but clearer than %data_of or %data4

      foreach my $id (sort { $id{$a}{m_time} <=> $id{$b}{mtime} } @id) { my $value = $id{$id}{value} or next; # ... }
      Or similar. Note that @id by no means means that it is the complete set of keys %id

      Enjoy, Have FUN! H.Merijn
        That's rather cryptic to me°, please exemplify the data-structures.

        Or just use better names! ;)

        I'm pretty sure that in the end %id is a misnomer, and something like %record or just the name of the corresponding DB.TABLE would be far more appropriate ...

        (update)

        ... cause this looks a lot like a DBI->fetchall_hashref()

        Regarding @id, (again) if it's an array use plural @ids .

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        °) I have no ID ... ;-)