in reply to using pagecount variable in array?

Hi bobafifi,

Something in my syntax isn't working (and I'm not seeing it!)

We're not seeing it either, if you don't show us!  What exactly ARE you getting?  When I added:

use strict; use warnings;

at the top of the program, and assigned a value to $total_recs (since I have no idea what value you are starting with):

my $total_recs = 123;

and changed for $i (@pages) to for my $i (@pages), I got the output:

Page 1 of <a href="http://www.example.com/page1.shtml">http://www.exam +ple.com/pa ge1.shtml</a><br> <a href="http://www.example.com/page2.shtml">http://www.example.com/pa +ge2.shtml< /a><br> <a href="http://www.example.com/page3.shtml">http://www.example.com/pa +ge3.shtml< /a><br> <a href="http://www.example.com/page4.shtml">http://www.example.com/pa +ge4.shtml< /a><br> <a href="http://www.example.com/page5.shtml">http://www.example.com/pa +ge5.shtml< /a><br> <a href="http://www.example.com/page6.shtml">http://www.example.com/pa +ge6.shtml< /a><br> <a href="http://www.example.com/page7.shtml">http://www.example.com/pa +ge7.shtml< /a><br> <a href="http://www.example.com/page8.shtml">http://www.example.com/pa +ge8.shtml< /a><br> <a href="http://www.example.com/page9.shtml">http://www.example.com/pa +ge9.shtml< /a><br> <a href="http://www.example.com/page10.shtml">http://www.example.com/p +age10.shtm l</a><br> <a href="http://www.example.com/page11.shtml">http://www.example.com/p +age11.shtm l</a><br> <a href="http://www.example.com/page12.shtml">http://www.example.com/p +age12.shtm l</a><br>

which looks fine to me.  It's the output for each page from 1 to 12 (as 123 / 10 = 12.3).

Please explain exactly what YOU are getting, and why you think it's wrong.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: using pagecount variable in array?
by bobafifi (Beadle) on Jul 23, 2006 at 14:26 UTC
    Wow! That worked :-)

    Changed for $i (@pages) to for my $i (@pages) and that did the trick.

    You rock!! :-)
    Thanks so much,

    -Bob

      You're mistaking the cause for your error. In fact, the code you posted will run AS-IS if you simply assign a value to $total_recs at the start of the script, and use POSIX qw/ceil/;. Though it's wise beyond words to learn to use strict;, and smart to use lexical variables such as my $i, the change you made by adding my $i to your foreach loop can't be what fixed the code you posted. The code you posted essentially works.

      So what exactly was the error you were getting?


      Dave

            I think that [using "strict"] was much of the point of liverpole's post.

        Yes, that and the fact that we can't know what output a user is "expecting" to get, especially when the output we get is as it should be.

        And as davido points out, the OP's code "essentially works".  So, although it's nice and gratifying that your problem is solved, bobafifi, we're still all scratching our heads here, wondering:  "what was failing for you in the first place?"


        s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
        > "what was failing for you in the first place?"

        I was getting "Internal Server Error" pages:

        Internal Server Error The server encountered an internal error or misconfiguration and was u +nable to complete your request. <snip>
        As soon as I changed for $i (@pages) to for my $i (@pages), the script worked.

        Thanks again,

        -Bob

      Did you also change the top of your script to include use strict;? I think that was much of the point of liverpole's post.

          -Bryan

        > Did you also change the top of your script to include use strict;?

        No, I already was using strict:

        #! /usr/bin/perl -w use strict; use POSIX; use DBI; use CGI qw(:standard); my ($dbh, $sth, $count);
        Thanks,

        -Bob