#!/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 ) # prune { push @queue, <$path/*>; } } @playList{ sample $numOfRandFiles, @audioFiles } = 1 .. $numOfRandFiles; use Data::Dump 'dd'; dd \%playList;