Aye, input I can give. In order to display every line of the file, you're gonna need the whole file sucked in to an array if you want to output the lines randomly. If I'm reading your request right, you want to output all these banners in random order. If that's the case, try something like this:
#!/usr/bin/perl -wT use strict; my $adfile = 'banners.dat'; open FILE, "< $adfile" or die "Can't open $file: $!\n"; my @lines; splice(@lines, rand $., 0, $_) while <FILE>; close FILE; chomp @lines; print "Content-Type: text/html\n\n"; for my $line (@lines) { my @parts = split '\|', $line; print <<__End__; <font face="arial" size="2"> <a href="$part[0]" ... . . . </font> __End__ }
I should mention a slight problem with your syntax: @part[0] should really be $part[0] (although in truth, it'll still work, but might cause trouble down the road with context issues). Also, the code is untested, so if there's any problems, /msg me and I'll try to help you out. And ++ to MeowChow for giving me the idea for the randomization.
Update: As tilly mentions below, there are more efficent methods of randomizing your output, and if that's a concern, you'd do well to check out the links he provides. But it's probably nothing to worry about until you get a large number of ads in your .dat file.
His Royal Cheeziness
In reply to Re: How can I print all lines instead of 1 random?
by CheeseLord
in thread How can I print all lines instead of 1 random?
by ginocapelli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |