Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] if syntax problem?

Expand Messages
  • Gordon Stewart
    ... Try :- if ($monthflag == 1){$day2test = 2002%d%d , $nextmonth, $day2;} #This is line 57 $monthflag=1 is telling the computer to replace the value with
    Message 1 of 6 , Sep 4, 2002
    • 0 Attachment
      At 11:04 4/09/02 +0200, you wrote:
      >@months = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      >$temp2 = $months[$date];
      >$temp3 = $temp2 + 1;
      >if ($lastdate > $temp2){$monthflag = 1; $nextmonth = $date + 1;}
      >
      >#build day1
      >$day1 = $firstdate;
      >$day1test = "2002%d%d", $date, $day1;
      >
      >#build day2
      >$temp = ($temp2 + $lastdate -4);
      >if ($temp > $temp3){$temp = $temp - $temp3;}
      >$day2 = $temp;
      >if ($monthflag = 1){$day2test = "2002%d%d", $nextmonth, $day2;} #This is
      >line 57
      >else {$day2test = "2002%d%d", $date, $day2;}


      Try :-
      if ($monthflag == 1){$day2test = "2002%d%d", $nextmonth, $day2;} #This
      is line 57


      $monthflag=1 is telling the computer to replace the value with 1,

      G.

      ----------


      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.384 / Virus Database: 216 - Release Date: 21/08/02


      [Non-text portions of this message have been removed]
    • Charles K. Clarkson
      ... Jim, There are many of ways of testing a conditional in perl. For example, there is a statement modifier: $temp -= $temp3 if $temp $temp3; is (almost)
      Message 2 of 6 , Sep 4, 2002
      • 0 Attachment
        Evan Dembskey [mailto:evan@...] wrote:
        :
        : What is wrong with my syntax here? I keep getting a "Useless
        : use of a variable in void context at lotfix.pl line 57." error.
        :
        : $monthflag = 0;
        : $nextmonth = 0;
        : @months = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        : $temp2 = $months[$date]; $temp3 = $temp2 + 1; if ($lastdate >
        : $temp2){$monthflag = 1; $nextmonth = $date + 1;}
        :
        : #build day1
        : $day1 = $firstdate;
        : $day1test = "2002%d%d", $date, $day1;
        :
        : #build day2
        : $temp = ($temp2 + $lastdate -4);
        : if ($temp > $temp3){$temp = $temp - $temp3;}
        : $day2 = $temp;
        : if ($monthflag = 1){$day2test = "2002%d%d", $nextmonth,
        : $day2;} #This is line 57
        : else {$day2test = "2002%d%d", $date, $day2;}



        Jim,

        There are many of ways of testing a conditional in
        perl. For example, there is a statement modifier:

        $temp -= $temp3 if $temp > $temp3;

        is (almost) the same as:

        if ($temp > $temp3){$temp -= $temp3;}


        Another construct is the ?: operator. It is
        like a single statement if/else:

        if ( $monthflag == 1 ) {
        $day2test = sprintf "2002%d%d", $nextmonth, $day2;
        } else {
        $day2test = sprintf "2002%d%d", $date, $day2;
        }

        Becomes:

        $monthflag == 1
        ? $day2test = sprintf "2002%d%d", $nextmonth, $day2
        : $day2test = sprintf "2002%d%d", $date, $day2;

        Or:

        $day2test = $monthflag == 1
        ? sprintf "2002%d%d", $nextmonth, $day2
        : sprintf "2002%d%d", $date, $day2;



        With that in mind, (and eliminating those 'temp'
        variables), how about this:

        my @month_days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

        my $day1 = $firstdate;
        my $day1test = "2002%d%d", $date, $firstdate;

        my $day2 = $month_days[$date] + $lastdate - 4;
        $day2 -= $month_days[$date] + 1 if $day2 > $month_days[$date] + 1;

        my $day2test = $lastdate > $month_days[$date]
        ? sprintf "2002%d%d", $date + 1, $day2
        : sprintf "2002%d%d", $date, $day2;


        Whenever I am about to use a flag variable, I try
        to re-write my algorithm. They are rarely needed.



        HTH,

        Charles K. Clarkson
        --
        Head Bottle Washer,
        Clarkson Energy Homes, Inc.
        Small commercial and residential rehabilitation specialists.
        254 968-8328

        CJ Web Work - Solutions for Real Estate Investors.
        972 216-4952

        CJ Web Hosting - Lookout; We have one whole paying customer!
        254 968-8328
      • Gordon Stewart
        Hi there... I ve *ALMOST* figured out what is wrong with my script... Ive got a Premature end of script header problem (Or words to those effect..) Ive
        Message 3 of 6 , Sep 4, 2002
        • 0 Attachment
          Hi there... I've *ALMOST* figured out what is wrong with my script...


          Ive got a "Premature end of script header" problem (Or words to those effect..)

          Ive figured out :-

          -------------
          print header(-cookie=>[$cookie1,$cookie2]);

          my $adside=$test;
          my $adtop=$testtop;

          print "<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0
          Transitional\/\/EN\">\n";
          print "<!-- saved from
          url=(0064)http:\/\/n-zealand.hypermart.net\/cgi-bin\/mylinks\/view.cgi?search=3
          -->\n";
          print "<HTML>\n";
          print "<HEAD>\n";
          print "<META content=\"text\/html; charset=windows-1252\"
          http-equiv=Content-Type>\n";
          print "<META content=\"MSHTML 5.00.2614.3500\" name=GENERATOR>\n";
          print "<META content=\"KWISTER!! New Zealand and Australias searchable
          website directory.\" name=DESCRIPTION>\n";
          print "<META content=\"KWISTER!\" name=NAME>\n";

          print "<link rel=\"stylesheet\" href=\"/intranet_styles.css\"
          type=\"text/css\">\n";

          print "<\/HEAD>\n";
          print "<BODY>\n";

          exit;
          -------------

          at this point, ive Done all my cookies, & Ive displayed the HTML headers -
          as above..

          & it exits at that point.

          If I run the script 10, 20 , 50 times - Everything is perfectly fine - I
          look in the source code, & see the correct HTMl (I'll "assume" the headers
          are them as well ??)

          AS SOON as I take the "exit" command out - & run the script - I get a
          "prematire end of script header " message (or similar message).

          The ISP/Host is running Apache..

          Q. What could be causing this "premature end of script headers" AFTER the
          HTML has been printed ?

          Ive checked & re-checked - No HTML (or other) is printed prior to this
          point - I'll re-check again

          G.


          ----------


          ---
          Outgoing mail is certified Virus Free.
          Checked by AVG anti-virus system (http://www.grisoft.com).
          Version: 6.0.384 / Virus Database: 216 - Release Date: 21/08/02


          [Non-text portions of this message have been removed]
        • Dragon
          Sorry, I haven t been following this thread particularly closely, so I may be missing something from one of the previous posts. The error is Undefined
          Message 4 of 6 , Sep 4, 2002
          • 0 Attachment
            Sorry, I haven't been following this thread
            particularly closely, so I may be missing something
            from one of the previous posts.

            The error is "Undefined subroutine &main::header
            called at " the first line of code you listed:
            > print header(-cookie=>[$cookie1,$cookie2]);

            It thinks you're calling a subroutine named
            "header()", and it can't find that subroutine.


            --- Gordon Stewart <gordon@...> wrote:
            >
            > Hi there... I've *ALMOST* figured out what is wrong
            > with my script...
            >
            >
            > Ive got a "Premature end of script header" problem
            > (Or words to those effect..)
            >
            > Ive figured out :-
            >
            > -------------
            > print header(-cookie=>[$cookie1,$cookie2]);
            >
            > my $adside=$test;
            > my $adtop=$testtop;
            >
            > print "<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML
            > 4.0
            > Transitional\/\/EN\">\n";
            > print "<!-- saved from
            >
            url=(0064)http:\/\/n-zealand.hypermart.net\/cgi-bin\/mylinks\/view.cgi?search=3
            >
            > -->\n";
            > print "<HTML>\n";
            > print "<HEAD>\n";
            > print "<META content=\"text\/html;
            > charset=windows-1252\"
            > http-equiv=Content-Type>\n";
            > print "<META content=\"MSHTML 5.00.2614.3500\"
            > name=GENERATOR>\n";
            > print "<META content=\"KWISTER!! New Zealand and
            > Australias searchable
            > website directory.\" name=DESCRIPTION>\n";
            > print "<META content=\"KWISTER!\" name=NAME>\n";
            >
            > print "<link rel=\"stylesheet\"
            > href=\"/intranet_styles.css\"
            > type=\"text/css\">\n";
            >
            > print "<\/HEAD>\n";
            > print "<BODY>\n";
            >
            > exit;
            > -------------



            __________________________________________________
            Do You Yahoo!?
            Yahoo! Finance - Get real-time stock quotes
            http://finance.yahoo.com
          • Nathan.Jeffrey@dhs.vic.gov.au
            I think that... if ($monthflag = 1){$day2test = 2002%d%d , $nextmonth, $day2;} ...should read... $day2test = sprintf( 2002%d%d , $nextmonth, $day2) if
            Message 5 of 6 , Sep 4, 2002
            • 0 Attachment
              I think that...

              if ($monthflag = 1){$day2test = "2002%d%d", $nextmonth, $day2;}

              ...should read...

              $day2test = sprintf("2002%d%d", $nextmonth, $day2) if monthflag == 1;

              Two things - comparisons are '==' or 'eq' (for strings), not '='. And
              sprintf is the function to put C-style printf into strings :-)

              N






              "Evan Dembskey" <evan@...>
              04/09/2002 07:04 PM
              Please respond to perl-beginner


              To: "Perl-Beginner" <perl-beginner@yahoogroups.com>
              cc:
              Subject: [PBML] if syntax problem?


              Hi,


              What is wrong with my syntax here? I keep getting a "Useless use of a
              variable in void context at lotfix.pl line 57." error.



              $monthflag = 0;
              $nextmonth = 0;
              @months = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
              $temp2 = $months[$date];
              $temp3 = $temp2 + 1;
              if ($lastdate > $temp2){$monthflag = 1; $nextmonth = $date + 1;}

              #build day1
              $day1 = $firstdate;
              $day1test = "2002%d%d", $date, $day1;

              #build day2
              $temp = ($temp2 + $lastdate -4);
              if ($temp > $temp3){$temp = $temp - $temp3;}
              $day2 = $temp;
              if ($monthflag = 1){$day2test = "2002%d%d", $nextmonth, $day2;} #This
              is
              line 57
              else {$day2test = "2002%d%d", $date, $day2;}


              Regards,

              Jim



              Unsubscribing info is here:
              http://help.yahoo.com/help/us/groups/groups-32.html

              Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/







              _________________________________________________________________________________

              This email contains confidential information intended only for the person named above and may be subject to legal privilege. If you are not the intended recipient, any disclosure, copying or use of this information is prohibited. The Department provides no guarantee that this communication is free of virus or that it has not been intercepted or interfered with. If you have received this email in error or have any other concerns regarding its transmission, please notify Postmaster@...
              _________________________________________________________________________________
            Your message has been successfully submitted and would be delivered to recipients shortly.