[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ozo - PERL DB, one minor point with notfound

Posted on 1997-10-22
7
Medium Priority
?
247 Views
Last Modified: 2013-12-25
hi ozo (or anyone who wants to dive in at the deep end),

I have been trying to get the sub showindexsubstrings to return something other than nothing when it cannot find a chart with a given description (like the chart num and scale routines do) but am having problems.

I assume this is because of the "while" statement but cannot work out why. I have got this sub at the moment:-

 sub showindexsubstrings {
  my ($substr,$myhash,$charthash) = @_;
  my($table,$chart);
>>>>  if( !defined($myhash->{$substr}) ){
>>>>    notfound; return;
>>>>  }
  $substr = lc($substr);
  while( ($table, $chart) = each(%{$myhash}) ){
   if( index(lc($table),$substr) >= 0 ){
  # print html("$table = chart $chart"),"<BR>\n";
    printcharts($chart,$charthash) if( defined($charthash) );
   }
  }
 }

Now to me it looks like it should work, indeed exactly the same extra lines (see marked lines) works with showindex (except I 've changed the $ names obviously) but not here.

Any thoughts?  At the moment if I leave the check lines out then a search with a valid name is found but one with a non valid name displays blank. If I put the check lines in then both valid and non-valid names are returned as not found.

BTW notfound is a sub routine which simply displays a polite sorry message which I have added in.  Here it is:-

# Sub for returning a polite sorry message when term cannot be found
#
 sub notfound{
  my($searchkey);
  if ( $cmd eq "desc" ){
      $searchkey = "description";
      }
      else{
           $searchkey = $cmd;
           }
  print "<TR><TD COLSPAN=4 ALIGN=center>Sorry, $searchkey<B> $data </B>is not in the database</TD></TR>";
 }

If you could help me I would be most grateful, or anyone else if they fancy a go.
0
Comment
Question by:Trevor013097
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1830986
Well, if it returns whenever $myhash->{'plymouth'} is undefined,
you may never get to see that $myhash->{'Plymouth Sound'} was defined.
You might try:

my $found=0;
while( ($table, $chart) = each(%{$myhash}) ){
  next if( index(lc($table),$substr) < 0 );
  $found++
  if( defined($charthash) ){
              printcharts($chart,$charthash);
  }else{
              print html("$table = chart $chart"),"<BR>\n";  
  }
}
&notfound unless $found;

(also, if $data happens to contain characters like '<'
<B> $data </B>
may not print very nicely, which is what the html() function was for:
print "<TR><TD COLSPAN=4 ALIGN=center>Sorry,",
html($searchkey),"<B> ",html($data)," <B>is not in the
database</TD></TR>";
In case you care)

0
 
LVL 5

Author Comment

by:Trevor013097
ID: 1830987
Thanks ozo,

My PERL isn't that hot (in case you hadn't noticed) and that notfound for descriptions has had me puzzled since monday. Thanks for solving it so quickly.

Also thanks for reminding me about the sub html.  I hadn't meant to omit it just forgot.

One small point, you forgot the ';' off of the end of the line:-

$found++

without it the script was producing garbage.  Just thought you'd like to know ;-)

Post this as an answer adn I'll grade it pronto.

Cheers,

    Trevor

0
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 1830988
my $found=0;
while( ($table,$chart) = each(%{$myhash}) ){
  next if( index(lc($table),$substr) < 0 );
  ++$found; #(I'm glad you're learning how to debug perl code :-)
  print html("$table = chart $chart"),"<BR>\n";
}
&notfound unless $found;
0
Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
LVL 5

Author Comment

by:Trevor013097
ID: 1830989
ozo,

You couldn't do me a favour could you...

Go to:

http://www.pcmaritime.co.uk/arcs/charts/arcfind.htm

and do a search on '0' that's the number 0 (zero) and tell me what you get and any thoughts.


0
 
LVL 5

Author Comment

by:Trevor013097
ID: 1830990
Doesn't have the problem with 00 or with 000 just with a single 0.

What it does is prompt you to save file to disk, like a download but only when you enter in a 0.


0
 
LVL 84

Expert Comment

by:ozo
ID: 1830991
When I tried to go to
http://www.pcmaritime.co.uk/arcs/charts/arcfind.htm 
I get:
The requested URL /arcs/charts/arcfind.htm was not found on this server.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1830992
Ok, I think I found it in http://www.pcmaritime.co.uk/charts/arcs/arcfind.htm
and since '0' is false,
local $data = $form{data} or error("missing data in query");
would be giving an error
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question