http://qs1969.pair.com?node_id=252497


in reply to space saving wanted!

my ($calc1, $calc2, $calc3, $calc4); foreach my $calc ( $calc1, $calc2, $calc3, $calc4 ) { print "$calc\n"; }

---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

Replies are listed 'Best First'.
Re: Re: space saving wanted!
by Anonymous Monk on Apr 23, 2003 at 14:01 UTC
    How could i do this if i wanted to test each $count for being over 0 ?? e.g.
    if ($calc < 0 ) { print "$some_variable\n"; }
      Well demerphq already gave you 99.9% of the code, just test to see if each variable is greater than zero:
      my ($calc1, $calc2, $calc3, $calc4); foreach my $calc ( $calc1, $calc2, $calc3, $calc4 ) { print "$calc\n" if ($calc > 0); }
      -- vek --

        It seems to me that annonymok should review perlsyn. What do you think?


        ---
        demerphq

        <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: Re: space saving wanted!
by smitz (Chaplain) on Apr 23, 2003 at 10:11 UTC
    Why not get rid of that pesky loop?
    my ($calc1, $calc2, $calc3, $calc4, $calc5, $calc6, $calc7); print $calc1; print $calc2; print $calc3; print $calc4; print $calc5; print $calc6; print $calc7;
    Smitz

      Well, lets see. The OP asked for a way to use a loop to reduce his typing. He also is unlikely to want to _only_ print the variables involved. That could lead to serious code duplication. Also if you are being facetious then why not get rid of all those pesky print statements?

      print join($/||"",$calc1, $calc2, $calc3, $calc4, $calc5, $calc6, $cal +c7);

      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...