Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Add a fixed number of unique elements to hash

by tybalt89 (Monsignor)
on Mar 07, 2023 at 10:28 UTC ( [id://11150819]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Add a fixed number of unique elements to hash
in thread Add a fixed number of unique elements to hash

Simplifying a little

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11150757 #use warnings; # uncomment for newer perls 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 @stack = $target; while( my $path = pop @stack ) { grep $path =~ /\/\Q$_\E\z/, @exclude and next; push @audioFiles, grep -f, <$path/*.mp3>; push @stack, grep -d, <$path/*>; } $playList{ splice @audioFiles, rand @audioFiles, 1 or last } = $_ for 1 .. $numOfRandFiles; printf "%3d %s\n", $playList{$_}, $_ for sort keys %playList;

Log In?
Username:
Password:

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

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

    No recent polls found