Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I am "trying" to get this to work, but I can't seem to find an answer in either the cookbook or programming perl. What I would like to do is randomize an entire array of jpgs in a database of about 50, then take 20 or so and print them out to a template page. What happens is that it puts ONE picture on the page, 20 times, instead of 20 thumbnails once each. Could you please help a newkid out ? Here is what I sometimes refer to as my "code".
#!/usr/bin/perl -w print "Content-type: text/html\n\n"; $dir = "/home/usr/public/images/"; $view = "view.html"; $number_to_show = 15; $title = "Your Title Could Go Here"; srand( time() ^ ($$ + ($$ << 15)) ); opendir DIR, "$dir"; my @arr = grep -f, grep /\.jpg$/i, map "$dir/$_", readdir DIR; $n = @arr; foreach (reverse 0..$n) { my $pic = splice(@arr, rand $n, 1); push @arr, $pic; $#arr = $number_to_show; } &print_it(); sub print_it { open (PAGE, "$dir$view") || die ("I am unable to open the template $vi +ew"); while (<PAGE>) { s/%%title%%/$title/g; s/%%images%%/@arr/g; print $_; } close (PAGE); }

In reply to array problem by caciqueman

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-01-25 06:17 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (65 votes). Check out past polls.