Michael Corgan wrote: > I used the ARGV earlier, but received errors. So this is how the > script looks now: > #! /usr/local/bin/perl -w > use strict; > # > # > # > > $/ = "\n%\n";
It looks like your file contains records separated by a % on its own on a line? There are much better ways of doing this if so. > while (<>) { > my $random = rand(@ARGV); > my $question = $ARGV[$random]; > chomp $question; > print $question; @ARGV is the list of files you specified on your command line, and $ARGV[$random] is one of those files (or 'undef' if the index is out of range). Is this what you wanted? > This is the error I am getting back: > > Use of uninitialized value at /home/mcorgan/bin/flash line 12, <> > chunk 1. Use of uninitialized value at /home/mcorgan/bin/flash line > 13, <> chunk 1. Use of uninitialized value at /home/mcorgan/bin/flash > line 12, <> chunk 2. Use of uninitialized value at > /home/mcorgan/bin/flash line 13, <> chunk 2. > > Aren't I initializing the values with the "my" before the scalar > variables? It's not complaining about an undeclared variable but an 'uninitialized value'. The two lines must be 'chomp' and 'print', which you're calling after you've set $question to an uninitialized value from the array. Your $random must be out of bounds for the size of the array - most likely @ARGV is empty. Note that your loop 'while (<>)' is reading lines from the contents of these files. As it gets to the end of each file and goes on to the next one the name of that file will go from the @ARGV array until it is eventually empty. You certainly didn't mean to do this, and you need to explain what you do intend. What does your command line look like, what are the contents of your files like? What are the things you're trying to select randomly from, and when do you want to terminate that loop? Let us know. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]