ObiPanda has asked for the wisdom of the Perl Monks concerning the following question:
I very much appreciate the thorough answers I receive here: they have helped me get reacquainted with Perl. The hardest part I still encounter is to understand what the symbols mean, not so much the concepts.
I'm simply asking for a "better" way to accomplish a task I already can do.
An example: I want to know if there's a way to send just one key & value per array/hash - preferably by reference - to a subroutine. In the example code below, I want to send all and only the {Sub_Name}s and their respective values. The code below works and I've come up with two ways to list the Sub_Name. I'm simply wanting to know if there's a better way to do it, so I don't have to make an array or send the entire array of hashes to the subroutine.
#!/usr/bin/env perl #use 5.36.1; use strict; use warnings; use Data::Dumper; use autodie; use File::Find; use File::Copy; use File::Rename; use feature 'fc'; use File::Path qw( make_path ); my $Wait_Time = 10; # Implement Time Delay # Subscription DATA sets my @Subscription = ( { Sub_Name => "Morph", Archive_File => "Morph Archive.txt", }, { Sub_Name => "Analogue", Archive_File => "Analogue Archive.txt", }, { Sub_Name => "Cat", Archive_File => "Cat Archive.txt", }, { Sub_Name => "Zoonotic", Archive_File => "Zoonotic Archive.txt", }, { Sub_Name => "Hydro", Archive_File => "Hydro Archive.txt", }, ); #Subscription of Names my @Subscription_Names_List; for (@Subscription) {push @Subscription_Names_List, $_->{Sub_Name};} List_Subscriptions(\@Subscription_Names_List); for (@Subscription) { Display_Subs(\%$_); } sub Display_Subs { my ($my_Sub) = @_; print "Testing Subscription to: $my_Sub->{Sub_Name}\n"; return $my_Sub; } sub List_Subscriptions { my (@Sub_ARRAY) = @{$_[0]}; # my (@Sub_ARRAY) = @_; print "The Current Subscription List:\n\n"; for (@Sub_ARRAY) { print " \t$_ \n"; } print "\n\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine (updated)
by AnomalousMonk (Archbishop) on Sep 24, 2023 at 23:59 UTC | |
Re: How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine
by choroba (Cardinal) on Sep 24, 2023 at 21:07 UTC | |
Re: How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine
by kcott (Archbishop) on Sep 25, 2023 at 13:03 UTC | |
Re: How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine
by jwkrahn (Abbot) on Sep 24, 2023 at 23:12 UTC | |
Re: How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine
by LanX (Saint) on Sep 24, 2023 at 21:59 UTC |