in reply to Half Life map randomizer

Fairly good, few questions/problems
1) Why are you making the a "master" file if your goal is to randomize for mapcycle.txt
2) Put your file open/close statements outside of the loop.
3) Strict and warnings, but that's just me

Here's what I'd do:(comments removed)
#!/usr/bin/perl -w #i############################################# # Dave K 1/17/02 # # # # Use this script to randomize a HL map cycle # ############################################### use strict; my (@maps, @files, @reordered, $bsp); my $mapsdir = "/Path/to/HL/maps/directory/"; my $cycle = "/Path/to/mapcycle.txt"; opendir(MAPSDIR, $mapsdir) || die "Can not open $mapsdir: $!\n"; @files = readdir(MAPSDIR); closedir(MAPSDIR); foreach $bsp (@files) { unless ( ($bsp eq ".") || ($bsp eq "..") ) { push @maps, $bsp; } } @reordered = shuffle(@maps); open (MAPCYCLE, ">$cycle") || die "Can not open file $cycle: $!\n"; foreach (@reordered) { print MAPCYCLE $_; } close (MAPCYCLE); sub shuffle { my $array = @_; my $i = scalar (@$array); my $j; my $item; foreach $item (@$array) { --$i; $j = int rand ($i+1); next if $i == $j; @$array [$i,$j] = @$array[$j,$i]; } return @$array; }