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

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

Replies are listed 'Best First'.
Re^3: Implicit references? module -> feature -> pragma -> "Perl8" ?
by Tux (Canon) on May 13, 2026 at 14:11 UTC
    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 ... ;-)

        %record sucks if you are processing lots of different data. id is just an example. And yes, 90% of that indead stems (indirectly) from DBI related $sth->fetchrow_hashref ()s, so I likely will have ($tab1, @tab1, %tab1), ($tab2, @tab2, %tab2) etc all eventually combined into the final %rec (or similar).

        Anyway, TIMTOWTDI and I LOVE the possibility to do it like this, cause it is easy to *my* mind. (and being the only perl programmer dealing with the code, I can do whatever I want, and thus I am always right and do not have to argue!)


        Enjoy, Have FUN! H.Merijn