This incorporates a bit from the others and a bit of my own. :) Normaly I would shove the prompt into a sub of its own and use it as the condition for the while loop, but here i went with the simpler way! I came from C too although I started with ++ so I had streams for input output instead of printf.

use strict; use warnings; my @phrases = (); my $i = 1; print "Please enter phrase number " . $i++ . " (or 'stop'): "; while (<STDIN>) { chomp; last if /^stop$/; #only if they put just the word stop print "Please enter phrase number " . $i++ . " (or 'stop'): "; push @phrases, $_; } printphrases(@phrases); sub printphrases { my $i = 1; print $i++ . ") $_\n" foreach @_; } __DATA__ C:\test>perl input.pl Please enter phrase number 1 (or 'stop'): hello world Please enter phrase number 2 (or 'stop'): this is fun Please enter phrase number 3 (or 'stop'): cool Please enter phrase number 4 (or 'stop'): dude! Please enter phrase number 5 (or 'stop'): stop 1) hello world 2) this is fun 3) cool 4) dude!

___________
Eric Hodges

In reply to Re: Functions in Perl by eric256
in thread Functions in Perl by bluethundr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.