in reply to Add a fixed number of unique elements to hash
Define "very large number".
Anyways, here's one way I'd do it (who needs recursion?).
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11150757 use warnings; use List::AllUtils qw( sample none ); my $target = "/home/zsolti/Temp"; $target = '../mnt/home/old'; # FIXME for testing on my system my @exclude = ( #'2023_02_21_Szentendre_Pilis_EK_oldal' 'webftp' ,'x' ); my (@audioFiles, %playList); my $numOfRandFiles = 10; my @queue = $target; while( defined( my $path = pop @queue ) ) { if( -f $path and $path =~ /\.mp3$/i ) { push @audioFiles, $path; } elsif( -d $path and none { $path =~ m{/\Q$_\E\z} } @exclude ) # prun +e { push @queue, <$path/*>; } } @playList{ sample $numOfRandFiles, @audioFiles } = 1 .. $numOfRandFile +s; use Data::Dump 'dd'; dd \%playList;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Add a fixed number of unique elements to hash
by tybalt89 (Monsignor) on Mar 06, 2023 at 01:51 UTC | |
by kcott (Archbishop) on Mar 06, 2023 at 02:44 UTC | |
by tybalt89 (Monsignor) on Mar 07, 2023 at 10:28 UTC |