Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
This is a question of style rather than success or failure...
I was recently producing HTML image galleries.
There were thumbnails which linked to pages featuring the full-size images. The full-size-image pages had "next" and "previous" links on them.
I found myself testing for "is this the first page?", "is this the last page?" and "is this neither the first or last page?" (in order to have "< previous | next >" for the middle sections) in what I felt was a rather clumsy way.
I was working from the lines of tab-separated text files, but it's essentially the same problem I've come across in a lot of other situations.
Is there a better way than
if($. != 1){ # we're not on the first page # "make 'previous' link" code } if($. != 1 && $. != $total_number_of_lines){ # we're not on the first or last page # add neat little " | " to separate # my 'next' and 'last' links } if($. != $total_number_of_lines){ # we're not on the last page # "make 'next' link" code }
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing for one of three conditions
by eric256 (Parson) on Apr 26, 2004 at 23:55 UTC | |
by Cody Pendant (Prior) on Apr 27, 2004 at 01:32 UTC | |
by halley (Prior) on Apr 27, 2004 at 13:10 UTC | |
|
Re: Testing for one of three conditions
by matija (Priest) on Apr 26, 2004 at 23:19 UTC | |
|
Re: Testing for one of three conditions
by davido (Cardinal) on Apr 26, 2004 at 23:30 UTC | |
|
Re: Testing for one of three conditions
by dragonchild (Archbishop) on Apr 27, 2004 at 01:16 UTC | |
|
Re: Testing for one of three conditions
by flyingmoose (Priest) on Apr 27, 2004 at 02:07 UTC |