Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Alternative to smart match

by LanX (Saint)
on Jan 22, 2022 at 01:12 UTC ( [id://11140693]=note: print w/replies, xml ) Need Help??


in reply to Alternative to smart match

I think you want a %seen hash

push @authority, $full unless $seen{$full}++;

if order doesn't matter you just built up %seen and do @authority = keys %seen at the end.

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

Replies are listed 'Best First'.
Re^2: Alternative to smart match
by Bod (Parson) on Jan 22, 2022 at 11:33 UTC
    I think you want a %seen hash

    I think you right!

    Clearly I was overthinking it and missing the obvious...I don't even need the @authority array as I can build the output string directly from the hash keys

    my $auth_list = join '<br>', keys %seen;
    Thanks Rolf

      Great, your welcome.

      But please keep in mind that hashes are randomized in Perl, hence you can't rely on the order.

      If it's meant for display in HTML you might want to sort them first.

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

        ...please keep in mind that hashes are randomized in Perl...

        Yes, I do realise this but thanks for the reminder.

        In this application, the order doesn't matter. The data is for highways. The array is to store the highway authority(ies) for each route. Given that the length of the highway is very small compared to the geographic jurisdiction of the authority, very very few cross a border. So the vast majority of routes only have one authority. Ordering them doesn't matter for the odd one that does cross a border.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140693]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-03-28 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found