PERL One Liners
Just enough PERL to do almost anything. Except help me debug this script:
$random_file =
"random_image.dat";
# contains a list of image urls, just a plain text file
open (FILE, $random_file);
@LINES=; close(FILE);
srand;
print "Location: [int rand(@LINES)]";
I thought I understood this to be opening the file of image urls, and then [int rand(@LINES)] picked one line to print out as a Location http header. Well, I found this page while I was googling my problem, and thought it looked like it was worth saving, since PERL is an eternal mystery to me.
This is actually pretty straightforward but it took me a few minutes to figure it out. This was to check if a dog was 6 months old or so… I padded it a bit, becasue if the dog was “too old,” it would prevent a user from continuing. I figured give them a bit more than 6 months, hence 195 days.
Notes:
DateDiff is a function that returns the difference between two dates.
Dogs.birthday is a date, Dogs.name is text, from a db query (duh, huh?).
<cfoutput query="dogs">
#Dogs.name#
<CFIF ( DateDiff("d", Now(), Dogs.birthday ) ) GT 195 >
Older than 6 months ( #DateDiff("d", Now(), Dogs.birthday )# days)
<CFELSE>
Younger than 6 months ( #DateDiff("d", Now(), Dogs.birthday )# days)
</CFIF><BR />
</cfoutput>
More info on DateDiff