in reply to for mistake with shift

The equivalent of article_title2
sub article_title3 { local $_ = shift(@text); # left in for side effect while (defined ($_ = shift @text)) { print "# TEXT-1 = '$_'\n"; unshift(@text, $_), last if /^$/; # put empty line back } print "# TEXT-2 = '$_'\n" for @text; }

Replies are listed 'Best First'.
Re: Re: for mistake with shift
by hsmyers (Canon) on Dec 31, 2003 at 15:00 UTC

    Yes! I like that version, it does exactly what I want without the overhead of the duplicate array. I wonder if while (shift(@text)) { wouldn't work as well? Thanks!

    --hsm

    "Never try to teach a pig to sing...it wastes your time and it annoys the pig."

      To answer my own less than bright question, Yes, but then the unshift would have to be outside of the loop. Something like:

      while(shift @text) { # do whatever... } unshift(@text,'') if @text;
      I Think I like the while (defined (shift @text)) { better.

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."