# File: fileWriteDie.pl # Title: Roll a die $N times and write in file= dice.txt # Author: Mihaela Malita # Here is the file dice.txt: # 5 # 6 # 2... use strict; # all variables have to be declared with my use warnings; # gives warnings (same as >perl -w file3.pl ) my $filename; my $die; # value will be 1-6 my $N = 10; # roll dice 10 times print "Name of the file (dice.txt)? "; $filename = ; chop($filename); #read from keyboard open(OUT,">$filename"); #check if the file exists for (1..$N) { #reads line by line the text file until End Of File (EOF) $die = int rand 6 + 1 ; # 0-5 + 1 generates 1-6 print OUT "$die\n"; # Jump to next line } print "Check file $filename"; close OUT; exit;