?
Solved

ozo - PERL DB, one minor point with notfound

Posted on 1997-10-22
7
Medium Priority
?
246 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

752 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