in reply to Re: Turning a hash into a line of links
in thread Turning a hash into a line of links
my $numps = ($homes =~ tr{|}{});
and then find the "middle" one's position by using index in a loop
my $middle = int($numps / 2) + 1; my $pos = -1; my $found = 0; while (1) { $pos = index $homes, q{|}, $pos; last if ++ $found == $middle; $pos ++; } substr $homes, $pos, 1, q{<BR>};
As you say, it is fun trying these things out. As for checking return values, I should perhaps check that index doesn't return -1 and that substr does return the pipe that I think I'm replacing; if this was production code I probably would :)
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Turning a hash into a line of links
by OfficeLinebacker (Chaplain) on Dec 13, 2006 at 17:43 UTC | |
by johngg (Canon) on Dec 13, 2006 at 20:45 UTC | |
by OfficeLinebacker (Chaplain) on Dec 14, 2006 at 01:39 UTC |