Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Error: search.cgi - Range iterator outside integer

Quote Reply
Error: search.cgi - Range iterator outside integer
Hi,

I've started to get this error from search.cgi, but only with certain words:

Software error:
Range iterator outside integer range at search.cgi line 244.


Anyone know what it means and what could be causing it?

All the best
Shaun

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
How much modification have you done to search.cgi??? <G>

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
Ah, you got me <G>

I've done a bit, but nothing that I can think of recently to the actual search.cgi file.

Here's the code from the area its complaining about:

Code:
sub search_build_linked_title_last {
# --------------------------------------------------------
# Returns a string of the last category
#
my $input = shift;
my (@dirs, $path);

@dirs = split (/\//, $input);

$path = "/" . &build_clean_name( join "/", @dirs[0 .. $_] );
$input = qq|$path/">$dirs[$_]|;

return $input;
}
This is part of a mod I did to link ONLY the last part of the category name in the search results, but its been working fine until recently (or so I thought!)

What I find strange is that it only falls-over with certain words. Works fine for 'internet' but reports the error for 'information'?

All the best
Shaun

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
Rather than $_ what about using $#dirs to indicate the last index of the array?

Length of the array is then $#dirs+1

$input = qq|$path/">$dirs[$_]|;

becomes

$input = qq|$path/">$dirs[$#dirs]|;

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
Thanks pugdog, that little tweak works fine Smile - but I still get the error :(

So far I can only find variations on 'inf' at the beginning of the word that makes it fall-over, which I find really strange.

All the best
Shaun

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
YES ... problem sorted (fingers-crossed!!) Smile

I'd previously played around for hours trying to link just the last part of the category and ended up building an additional sub to link the last directory using (pop @dirs)

After testing a few backup copies I found the problem had been there ever since I did the mod (ooppss ...) I've now removed the sub altogether and used the following changes to achieve it:

Code:
sub search_build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.
#
my $input = shift;
my (@dirs, $dir, $output, $path);

@dirs = split (/\//, $input);


# Builds all but the last directory, without a hyper-link

for (0 .. $#dirs - 1){
$path = "/" . &build_clean_name( join "/", @dirs[0 .. $_] );
$output .= qq| $dirs[$_]  >|;
}


# Builds the last directory, hyper-linked

for ($#dirs){
$path = "/" . &build_clean_name( join "/", @dirs[0 .. $_] );
$output .= qq| <A HREF="$LINKS{build_root_url}$path/">$dirs[$#dirs]</A>|;
}

return $output;
}
Thanks pugdog - your advice about $#dirs gave me the idea to get it working Smile

All the best
Shaun
Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
You're welcome :)

For anyone interested, $#array_name is a special variable that returns the value of the LAST index of the array @array_name. Since arrays are 0 based, the value returned by $#array_name is one less than the number of elements in the array -- or,

$num_array_elements = $#array_name + 1;

Or, the same as scalar(@array_name) or @array_name used in a scalar context such as:

$num_array_elements = @array_name;

It's a really good idea to not use automatic or 'funky' variables, when you have a _real_ variable that can return the value you expect it to every time.

That being said, why do you need to use the $_ variable at all, and why do you need any loops?



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
Something like:

Code:
$path .= &build_clean_name(join "/", @dirs) ; ## this should be the "clean" path.

$output .= join "/", @dirs[0 .. ($#dirs-1)] ; ## print out the first part of the non-linked path.

$output .= '/'; ## add the trailing non-linked slash

$output .= qq|<A HREF="$LINKS{build_root_url}/$path/">|; ## add the hyperlink to the FULL path

$output .= $dirs[$#dirs]|; ## add the _LAST_directory name to be linked

$output .='</A>'; ## close the hyper link.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
Pugdog,

I'm using the first loop because I want the take the names of the 'upper' cats and display them with a '>' in between to show people where the final category originates from, e.g.;

Business > Companies > Construction > Concrete > last one linked Materials

Is that the best way of doing it?

All the best
Shaun

Quote Reply
Re: Error: search.cgi - Range iterator outside integer In reply to
What about:

Code:
$path .= &build_clean_name(join "/", @dirs) ; ## this should be the "clean" path.

$output .= join "/", @dirs[0 .. ($#dirs-1)] ; ## print out the first part of the non-linked path.
$output .= '/'; ## add the trailing non-linked slash
$output =~ s|/| > |g; ## turn '/' into ' > ' for the non-linked path

$output .= qq|<A HREF="$LINKS{build_root_url}/$path/">|; ## add the hyperlink to the FULL path

$output .= $dirs[$#dirs]|; ## add the _LAST_directory name to be linked

$output .='</A>';
http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/