in reply to subroutine recurse vs goto LABEL
In the goto example, you've basically written a while loop, which is how most people would do it.
I'd remove the duplicate code from the end of each if/else statement, and write it as such:
There's more than one way to do it.#!/usr/bin/perl -w use strict; # &subname can have unpleasant side effects a(); sub a { my $a; while (lc($a) ne 'q') { chomp($a = <STDIN>); last unless $a; if ($a =~ /\D/) { print "Not an integer!\n"; } else { print "You typed: ->$a<-\n"; } } }
|
|---|