Professional Web Applications Themes

alternating loop - PERL Beginners

Hello, been trying to come up with a way, while going through a loop to alternate a table cell color <td></td>.... IE. while (..) { # To alternate a td cell color for each loop cycle so I end up # with something like this: # 1st loop <td height="15">&nbsp;</td> # 2nd loop. <td height="15" bgcolor="#CCCCCC">&nbsp;</td> # 3rd loop.. <td height="15">&nbsp;</td> # 4th loop. <td height="15" bgcolor="#CCCCCC">&nbsp;</td> # and so on till the entire loop is completed } hope this make sense :) TIA. -- Mike<mickalo>Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! [url]http://www.thunder-rain.com[/url] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=...

  1. #1

    Default alternating loop

    Hello,

    been trying to come up with a way, while going through a loop to alternate a
    table cell color <td></td>....

    IE.
    while (..) {
    # To alternate a td cell color for each loop cycle so I end up
    # with something like this:
    # 1st loop
    <td height="15">&nbsp;</td>
    # 2nd loop.
    <td height="15" bgcolor="#CCCCCC">&nbsp;</td>
    # 3rd loop..
    <td height="15">&nbsp;</td>
    # 4th loop.
    <td height="15" bgcolor="#CCCCCC">&nbsp;</td>
    # and so on till the entire loop is completed
    }

    hope this make sense :)

    TIA.

    --
    Mike<mickalo>Blezien
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Thunder Rain Internet Publishing
    Providing Internet Solutions that work!
    [url]http://www.thunder-rain.com[/url]
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    Mike Blezien Guest

  2. #2

    Default Re: alternating loop

    On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote:
    > Hello,
    >
    > been trying to come up with a way, while going through a loop to
    > alternate a table cell color <td></td>....
    See if this gets you thinking along the right lines:

    my $odd = 1;
    while (<>) { # some kind of loop...
    if ($odd) {
    # do something
    $odd = 0;
    }
    else {
    # do something else
    $odd = 1;
    }
    }

    __END__

    James

    James Edward Gray II Guest

  3. #3

    Default Re: alternating loop

    On 12/18/2003 7:00 PM, James Edward Gray II wrote:
    > On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote:
    >
    >> Hello,
    >>
    >> been trying to come up with a way, while going through a loop to
    >> alternate a table cell color <td></td>....
    >
    >
    > See if this gets you thinking along the right lines:
    >
    > my $odd = 1;
    > while (<>) { # some kind of loop...
    > if ($odd) {
    > # do something
    > $odd = 0;
    > }
    > else {
    > # do something else
    > $odd = 1;
    > }
    > }
    >
    or

    my $alt;
    while (<>) { # some kind of loop...
    if ($alt = !$alt) {
    # do something
    }
    else {
    # do something else
    }
    }

    Randy W. Sims Guest

  4. #4

    Default Re: alternating loop

    On Thu, Dec 18, 2003 at 07:26:03PM -0500, Randy W. Sims wrote:
    > On 12/18/2003 7:00 PM, James Edward Gray II wrote:
    > >On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote:
    > >
    > >>Hello,
    > >>
    > >>been trying to come up with a way, while going through a loop to
    > >>alternate a table cell color <td></td>....
    > >
    > >
    > >See if this gets you thinking along the right lines:
    > >
    > >my $odd = 1;
    > >while (<>) { # some kind of loop...
    > > if ($odd) {
    > > # do something
    > > $odd = 0;
    > > }
    > > else {
    > > # do something else
    > > $odd = 1;
    > > }
    > >}
    > >
    >
    > or
    >
    > my $alt;
    > while (<>) { # some kind of loop...
    > if ($alt = !$alt) {
    > # do something
    > }
    > else {
    > # do something else
    > }
    > }
    or

    while (<>) {
    if ($|--) {
    # do something
    }
    else {
    # do something else
    }
    }

    Oh, no. Hold on. On second thoughts ...

    --
    Paul Johnson - [email]paulpjcj.net[/email]
    [url]http://www.pjcj.net[/url]
    Paul Johnson Guest

  5. #5

    Default Re: alternating loop

    Paul Johnson <paulpjcj.net> wrote:
    > On Thu, Dec 18, 2003 at 07:26:03PM -0500, Randy W. Sims wrote:
    > > On 12/18/2003 7:00 PM, James Edward Gray II wrote:
    > > >On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote:
    > > >
    > > >>Hello,
    > > >>
    > > >>been trying to come up with a way, while going through a loop to
    > > >>alternate a table cell color <td></td>....
    > > >
    > > >
    > > >See if this gets you thinking along the right lines:
    > > >
    > > >my $odd = 1;
    > > >while (<>) { # some kind of loop...
    > > > if ($odd) {
    > > > # do something
    > > > $odd = 0;
    > > > }
    > > > else {
    > > > # do something else
    > > > $odd = 1;
    > > > }
    > > >}
    > > >
    > >
    > > or
    > >
    > > my $alt;
    > > while (<>) { # some kind of loop...
    > > if ($alt = !$alt) {
    > > # do something
    > > }
    > > else {
    > > # do something else
    > > }
    > > }
    >
    > or
    >
    > while (<>) {
    > if ($|--) {
    > # do something
    HUH?????? Why are you decrementing the $OUTPUT_AUTOFLUSH variable as an
    'alternate' for loop???!

    Sorry, I don't follow you here.........


    -JW


    > }
    > else {
    > # do something else
    > }
    > }
    >
    > Oh, no. Hold on. On second thoughts ...
    >
    > --
    > Paul Johnson - [email]paulpjcj.net[/email]
    > [url]http://www.pjcj.net[/url]

    __________________________________
    Do you Yahoo!?
    New Yahoo! Photos - easier uploading and sharing.
    [url]http://photos./[/url]
    Jeff Westman Guest

  6. #6

    Default Re: alternating loop

    Thx's James.... worked fine,... the simplest way is usually the most obvious
    over-looked way :)

    Mike<mickalo>Blezien
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Thunder Rain Internet Publishing
    Providing Internet Solutions that work!
    [url]http://www.thunder-rain.com[/url]


    James Edward Gray II wrote:
    > On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote:
    >
    >> Hello,
    >>
    >> been trying to come up with a way, while going through a loop to
    >> alternate a table cell color <td></td>....
    >
    >
    > See if this gets you thinking along the right lines:
    >
    > my $odd = 1;
    > while (<>) { # some kind of loop...
    > if ($odd) {
    > # do something
    > $odd = 0;
    > }
    > else {
    > # do something else
    > $odd = 1;
    > }
    > }
    >
    > __END__
    >
    > James
    Mike Blezien Guest

  7. #7

    Default Re: alternating loop

    * Mike Blezien <mickalofrontiernet.net> [2003-12-18T18:48:23]
    > been trying to come up with a way, while going through a loop to
    > alternate a table cell color <td></td>....
    I always do something more like:

    my $i;
    while (<>) {
    print "<tr class='r", ($i++%2), "'> ... </tr>\n"
    }

    The benefit here is that someday I can replace the 2 with 3 and have
    three behaviors. Yes, that's a minor benefit.

    --
    rjbs

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.0.7 (GNU/Linux)

    iD8DBQE/4mhV5IEwYcR13KMRAiE7AJ0bON0Y23weQZed5tppiXbeGLkwgA CgibKP
    XI1/S0o0c+yqZTDSr4KfM3Q=
    =Qwrx
    -----END PGP SIGNATURE-----

    Ricardo Signes Guest

  8. #8

    Default Re: alternating loop

    On Dec 18, 2003, at 8:54 PM, Ricardo SIGNES wrote:
    > * Mike Blezien <mickalofrontiernet.net> [2003-12-18T18:48:23]
    >> been trying to come up with a way, while going through a loop to
    >> alternate a table cell color <td></td>....
    >
    > I always do something more like:
    >
    > my $i;
    > while (<>) {
    > print "<tr class='r", ($i++%2), "'> ... </tr>\n"
    > }
    >
    > The benefit here is that someday I can replace the 2 with 3 and have
    > three behaviors. Yes, that's a minor benefit.
    The minus is of course readability. ;) You could accomplish something
    similar with the ternary operator, to do it as Mike was, without
    stylesheets.

    Ironically, this was my first thought, but I changed my mind while I
    was typing it. I don't think an extra line or two is a bad price to
    pay for understanding what's going on. Of course, I'm pretty dumb and
    need all the visual clues I can get.

    James

    James Edward Gray II Guest

Similar Threads

  1. alternating colours in gridItems
    By dougk in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: August 11th, 03:30 PM
  2. Alternating between calling webservice in Java and in .Net.
    By eric in forum ASP.NET Web Services
    Replies: 1
    Last Post: January 24th, 02:33 PM
  3. Alternating Sound Files
    By ravenlynx9 in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: March 2nd, 05:43 AM
  4. extract strings between alternating text
    By Lydia Shawn in forum PERL Miscellaneous
    Replies: 5
    Last Post: August 10th, 01:42 PM
  5. Alternating Wired & Wireless
    By Timo Voipio in forum Linux Setup, Configuration & Administration
    Replies: 2
    Last Post: July 29th, 11:27 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139