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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.