View Single Post
Old 2005-08-18, 02:01 PM   #1
2ndChance
Aw, Dad, you've done a lot of great things, but you're a very old man, and old people are useless
 
2ndChance's Avatar
 
Join Date: Aug 2005
Posts: 20
Would any body know of a PERL equivalent to this PHP code?

Would any body know of a PERL equivalent to this php code that pulls a single line of data radomly from a txt file

Code:
<?
    $delim = "\n";
	$quotefile = "quotes.txt";
    // okay, let's get going. 
    $fp = fopen($quotefile, "r");
    $contents = fread($fp, filesize($quotefile)); 
    $quote_arr = explode($delim,$contents); 
    fclose($fp); 
    // initiate randomness
    srand((double)microtime()*1000000); 
    // generate random quote index 
    $quote_index = (rand(1, sizeof($quote_arr)) - 1); 
    // get quote at $quote_index and return it 
    $herequote = $quote_arr[$quote_index]; 
    echo $herequote; 
?>
Although this is a nice bit of randomness for php I need to impliment it in a perl script I have and well ... My brain isn't up to snuff to figure it out.

Thanks for at least taking the time to read this
2ndChance is offline   Reply With Quote