Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Location
    Omaha, Ne originally from Glasgow,SCotland
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Sub routine problem

    Thanks for all the replies, I'll use the strict and warning commands.
    Basically I made a copy of the sub routine and changed the code to just print the 2 submit buttons, the original sub routine was being called in 4 different locations
    so I changed one of the locations based on the logic to use the new copied sub-routine.
    Also I realised that variable wasn't being recognized in the sub routine as I had defined it at a lower place in the control.

    Thanks Everybody




    Newbie to PERL/CGI - the people who wrote this are long gone, only
    have o'reilly-Learing Perl and Elizabeth Castro perl & the CGI 2nd ed

    I have altered a sub routine in a CGI script to add a submit button on data displayed in table format, see attachment.
    This new button(CONTRACT) should only be displayed after the 1st 2 buttons(MODIFY and DELETE). However it appears after the 2nd set of submit
    buttons also.
    I have tried passing additional variables to the sub routine and they are always blank, there are 2 things that I don't understand(probably more, but don't know enough) Here is the code for the sub routine.

    1) On line 238 it references a sub routine in a library what does this do, I have included this sub routine also.

    2) On line 250 it references a variable $prtupd, it never passes this to the sub routine yet it contains the value it sets in the main module, when I
    try to pass a variable by adding it to line 236 and in the line in the main module it is always empty(lines 247 and 248 confirms this for me)

    Code:
       230
       231  sub PrintSal
       232  {
       233  ##print "<BR><BR></center>\n";
       234  ##print "<P><font> COLOR=CC0000 size=2><B>Pcontr: <I> $prntcontracts</font><P>\n";
       235  #Try not to use this thing any more -- I want to wax it but we use it in too many places to do that!
       236  ($type,$record,@stuff) = @_;
       237  $counter = 0;
       238  print "<!--html-lib.pl::PrintRow-->\n";
       239  foreach $cell (@stuff)
       240          {
       241          if($cell eq "") { $cell = "&nbsp\;"; }
       242          print "<td bgcolor=\"$color\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">$cell</td>\n";
       243  #       print "<td bgcolor=\"$color\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">$stuff[$counter]</td>\n";
       244  #       $counter++;
       245          }
       246
       247  print JKM "start of trail\n";
       248  print JKM "$type, $record, CONTRACTs is  $printcontracts, $prtupd\n";
       249
       250  if($prtupd == 1)
       251  {
       252  print<<END_OF_TWOBUTTONS;
       253  <form method="post" action="/cgi-bin/mbm/ModifySetup.cgi"><input type="hidden" name="type" value="$type">
       254  <input type="hidden" name="recordid" value="$record">
       255  <td bgcolor="$color"><input type="submit" value="Modify"></td>
       256  </FORM>
       257  <form method="post" action="/cgi-bin/mbm/DeleteConfirm.cgi"><input type="hidden" name="type" value="$type">
       258  <input type="hidden" name="recordid" value="$record">
       259  <td bgcolor="$color"><input type="submit" value="Delete"></td>
       260  </FORM>
       261  END_OF_TWOBUTTONS
       262    }
       263  else
       264     {
       265          print "<td bgcolor=$color></td>";
       266          print "<td bgcolor=$color></td>";
       267     }
       268
       269  if (($prntcontracts == "YES") && ($prtupd == 1))
       270  {
       271  print<<END_OF_THIRD;
       272  <form method="post" action="/ContractLetter.php"><input type="hidden" name="type" value="$type">
       273  <input type="hidden" name="recordid" value="$record">
       274  <td bgcolor="$color"><input type="submit" value="Contract"></td>
       275  </FORM>
       276  END_OF_THIRD
       277  }
       278  else
       279  {
       280          print "<td bgcolor=$color></td>";
       281  }
       282
       283
       284  return 1;
       285  }
    Here is the code for the sub routine in the library.
    Any help would be greatly apreciated.

    Code:
    1212:sub PrintRow
    1213-{
    1214-
    1215-#Try not to use this thing any more -- I want to wax it but we use it in too many places to do that!
    1216-($type,$record,@stuff) = @_;
    1217-$counter = 0;
    1218:print "<!--html-lib.pl::PrintRow-->\n<tr>\n";
    1219-foreach $cell (@stuff)
    1220-   {
    1221-   if($cell eq "") { $cell = "&nbsp\;"; }
    1222-   print "<td bgcolor=\"$color\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">$cell</td>\n";
    1223-#  print "<td bgcolor=\"$color\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">$stuff[$counter]</td>\n";
    1224-#  $counter++;
    1225-   }
    1226-print<<END_OF_CRAP;
    1227-<form method="post" action="/cgi-bin/mbm/ModifySetup.cgi"><input type="hidden" name="type" value="$type">
    1228-<input type="hidden" name="recordid" value="$record">
    1229-<td bgcolor="$color"><input type="submit" value="Modify"></td>
    1230-</FORM>
    1231-<form method="post" action="/cgi-bin/mbm/DeleteConfirm.cgi"><input type="hidden" name="type" value="$type">
    1232-<input type="hidden" name="recordid" value="$record">
    1233-<td bgcolor="$color"><input type="submit" value="Delete"></td>
    1234-</FORM>
    1235-</tr>
    1236-END_OF_CRAP
    1237-return 1;
    1238-}
    1239-
    Here is the code for the call to the sub routine;

    Code:
    202  &PrintSal("contractrpt",$rowno,$salyrs,$contr_type,$salary,$base,$va,$incentive_pay,$est_fpc_pay,$est_fpc_from_date,$est_fpc_to_date,$guar_fpcpay,$guar_datefrom,$guar_dateto);
       203          $prtupd=0;
       204          $prntcontracts = "NO";
       205          &PrintSal("salrptsuppl",$row_no,$psuppltype,$psupplamt,$psuppldesc);
       206          print "</tr>";
       207          $prtupd=1;
       208          $ticker++;
    Attached Files Attached Files
    Last edited by jkmglasgow; 04-28-2009 at 08:44 PM. Reason: Problem solved except for minor HTML glitch.

  • #2
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    this is wrong and is probably the reason the button is printed twice:

    Code:
    if (($prntcontracts == "YES") && ($prtupd == 1))
    "==" is a numeric operator, but you are checking a string value "YES" so you want to use "eq" instead of "==":

    Code:
    if (($prntcontracts eq "YES") && ($prtupd == 1))
    change that and see if it resolves the two button problem.

  • #3
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    this is just an html comment:

    Code:
    print "<!--html-lib.pl::PrintRow-->\n";
    it does nothing as far as the program is concerned. Not sure why it is there in the html code output. The code you posted is calling the PrintSal subroutine, not the PrintRow subroutine. Which is what the html comment above is indicating for some unknown reason.

    Judging by thte code you posted, the author was not a good perl programmer. The code indicates a fundamental lack of writing good perl programs. It might work but is a potential can of worms.
    Last edited by KevinADC; 04-27-2009 at 09:13 PM.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by KevinADC View Post
    this is just an html comment:

    Code:
    print "<!--html-lib.pl::PrintRow-->\n";
    it does nothing as far as the program is concerned. Not sure why it is there in the html code output.
    I guess it use SSI,

    best regards

  • Users who have thanked oesxyl for this post:

    jkmglasgow (04-28-2009)

  • #5
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    Quote Originally Posted by oesxyl View Post
    I guess it use SSI,

    best regards
    that is not a valid SSI tag and while it is possible to use SSI and script generated output its something you rarely see. Maybe there is something else going on that we are unaware of.

  • #6
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Can I chip in first (FishMonger). lol

    You really need to make sure that your script starts with the strict pragma.

    Code:
    use strict;
    Your sub, in the second code section doesn;t declare the vars as it should.

    also, make sure you have warnings outputted to the browser or your server error logs.

    Code:
    use warnings; # at top of script
    But, also, you might want to read up on the CGI module since it could make your script shorter and easier to use.

    hth

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #7
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,840
    Thanks
    2
    Thanked 160 Times in 155 Posts
    Quote Originally Posted by bazz View Post
    make sure you have warnings outputted to the browser or your server error logs.

    Code:
    use warnings; # at top of script
    You forgot something.
    Code:
    use warnings;
    use CGI::Carp qw<fatalsToBrowser warningsToBrowser>; # this outputs the errors to the browser, but the warnings needs 1 more step.
    After outputing the html header, you add this line which will output the warnings as html comments.
    Code:
    warningsToBrowser(1);
    The script is using depreciated html code which would be better handled with the use of css.

    Rather than outputting raw html, I'd use HTML::Template. http://search.cpan.org/~samtregar/HT....9/Template.pm


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •