in reply to Functions in Perl

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