in reply to Is this logic correct? Maybe can be rewritten better?

This is much better, Nik. You need to learn about placeholders, but your code and your question are better then previous efforts.

However, you are not using strict or, if you are, you are neutering it by having a huge my() or use vars() at the top. Had you been using strict, the bug trammell noticed would have been noticed for you by perl itself. That's why we have been telling you over and over to use it. Warnings would also help find other bugs you have.

As for your UTF-8, the better thing to do would be to create a sample script that only uses ASCII and demonstrates the question you have. Post that, then take the answers given and apply them to your real script.

As for your logic - I don't know what $data does. I also don't know why you're checking the 'select' parameter from your form before caring if the $hostmatch variable is 1 or not 1. Your specifications are unclear.


The Perfect is the Enemy of the Good.

  • Comment on Re: Is this logic correct? Maybe can be rewritten better?

Replies are listed 'Best First'.
Re^2: Is this logic correct? Maybe can be rewritten better?
by Nik (Initiate) on Apr 29, 2005 at 15:24 UTC
    Thank you Dragonchild. I srted to use strict and warnigns as matter of fact that iam using it at this script i posted. Here si thw whole script:

    I decided not to use html::Template although in another post i posted to you how i have done it. It gives me a headache. i will just use cgi.pm as i used too and css as well to help me lessen print formatting inside my perl cgi scripts.

    Iam getting this errors too although i ahve set all my vars with my:
    Global symbol "$hostmatch" requires explicit package name at D:\www\cg +i-bin\index.pl line 61. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 68. Global symbol "$hostmatch" requires explicit package name at D:\www\cg +i-bin\index.pl line 74. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 78. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 86. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 90. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 91. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 92. Global symbol "$data" requires explicit package name at D:\www\cgi-bin +\index.pl line 95. Execution of D:\www\cgi-bin\index.pl aborted due to compilation errors +.
    Please help me rebuild this index.pl in a better more straightforwardway and please point out to me my errors. Thank you.

      When you use my $hostmatch inside the if, you're creating a variable that only exists within the if. Any value you assign to it will disappear along with the variable once outside the if. That means elsif( $hostmatch == 1 ) is using a variable that no longer exists. The solution is:

      my $hostmatch; while( $row = $sth->fetchrow_hashref ) { if( $host eq $row->{host} ) { $hostmatch = 1; } }

      Same goes for $data. Change

      if( param('select') and param('select') !~ /\.\./ ) { my $data = ... ... }

      to

      my $data; if( param('select') and param('select') !~ /\.\./ ) { $data = ... ... }
      A reply falls below the community's threshold of quality. You may see it by logging in.

      Don't roll your own localtime-to-string routine. Use POSIX and strftime, which aside from requiring no extraneous months array and being less code will also respect the date formatting conventions of the current locate.

        So how can i write the following lines iwth the use of strptime:
        my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', +'Sep', 'Oct', 'Nov', 'Dec'); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = loc +altime; my $date = "$mday $months[$mon], $hour:$min";
        I didnt understand cpans explanation on this.