CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Tie::File bug?

 



KevinR
Veteran


Nov 23, 2003, 12:52 AM

Post #1 of 1 (410 views)
Tie::File bug? Can't Post

I have been using this code snippet to pull a random word out of a text file:


Code
tie @DATA, 'Tie::File', $path_words, recsep => ' ', mode => O_RDWR || die "Can't Find/Open $path_words: $!\n"; 
print h1('There are no words. Please upload the words.dat file') unless @DATA;
my $word = $DATA[int(rand @DATA)];
$word = lc $word;
untie(@DATA);


the file is along these lines:

dog cat fish table apple

its a continous line, there is only one line in the file with about 2,000 words all in lower case separated by a space, hence the recsep => ' ' option to split the file at the spaces instead of the default newline record separator.

I had to add the:

$word = lc $word;

line because even though all the words are lower case letters, about 1 in 3 invocations of the script would produce a word with the first letter in upper case! There appears to be no rhyme or reason for this, is this a bug in the Tie::File module or am I missing something?
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives