Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Help to improving my code please?

by cciulla (Friar)
on May 30, 2003 at 12:46 UTC ( [id://261832]=note: print w/replies, xml ) Need Help??


in reply to Help to improving my code please?

Doin' thumbnails, eh? How about a control break?

use strict; my @files = <DATA>; my %filehash = (); #put the split data into a hash keyed by the filename foreach (@files) { chomp; my @data = split /:/; $filehash{@data[2]} = [@data]; } my ($key, $last, $temp, $infoline, @value); #sort the hash by key for $key (sort keys %filehash) { #determine the first letter of the key $temp = substr($key, 0, 1); #here's the control break... #if we haven't seen the first letter of the key before, #"break" control, do something special, and carry on... if ($last ne $temp) { $last = $temp; print "\n<H1>$last</H1>\n"; } @value = @{$filehash{$key}}; $infoline = qq(<a href="@value[0]/@value[2]"><img src="images/@val +ue[3]" width="128" height="128" alt="@value[4]"></a><p>); print "\t$infoline\n"; } __DATA__ /path:jpg:mfile.jpg:stuff:stuff /path:jpg:afile.jpg:stuff:stuff /path:jpg:anotherfile.jpg:stuff:stuff /path:jpg:bfile:stuff.jpg:stuff /path:jpg:cfile:stuff.jpg:stuff /path:jpg:nfile:stuff.jpg:stuff /path:jpg:dfile:stuff.jpg:stuff /path:jpg:efile:stuff.jpg:stuff /path:jpg:ffile:stuff.jpg:stuff /path:jpg:gfile:stuff.jpg:stuff /path:jpg:hfile:stuff.jpg:stuff /path:jpg:ofile:stuff.jpg:stuff /path:jpg:stillanotherfile.jpg:stuff:stuff /path:jpg:ifile:stuff.jpg:stuff /path:jpg:jfile:stuff.jpg:stuff /path:jpg:kfile:stuff.jpg:stuff /path:jpg:lfile:stuff.jpg:stuff /path:jpg:pfile:stuff.jpg:stuff /path:jpg:qfile:stuff.jpg:stuff /path:jpg:rfile:stuff.jpg:stuff /path:jpg:sfile:stuff.jpg:stuff

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://261832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found