Solved

ozo - PERL DB, one minor point with notfound

Posted on 1997-10-22
7
241 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
  • 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 100 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
USB backup batch file help needed. 9 85
Scripting vs. Programming languages 25 152
Combine DSQuery result into loop script 6 52
Automating a script for user accounts LINUX 14 70
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…
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 …
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)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now