 |
|
Home:
Perl Programming Help:
Beginner:
Re: [tbone587] Taking input multiples times and storing into array:
Edit Log
|
|

Karazam
User
Mar 9, 2011, 12:27 AM
Views: 1329
|
|
Re: [tbone587] Taking input multiples times and storing into array
|
|
|
I couldn't readily see what's wrong with your code, but if you dont mind I'd like to suggest a somewhat different approach. Not thoroughly tested, but it seems to work.
#!/usr/bin/perl use strict; use warnings; print "Enter nr of users: "; my $nr = <>; my @a; for (1 .. $nr) { print "Enter name of user nr $_\n"; my $name = <>; chomp $name; push @a, $name; } # pieces of the MAC regex my $d = "[0-9A-Fa-f]"; my $dd = "$d$d"; my $max_tries = 3; for my $i ( 0 .. $#a ) { my $tries = 0; LOOP: { print "Enter MAC address for user $a[$i]\n"; my $mac = <>; chomp $mac; if ( $mac =~ /^$dd([:;-])$dd(\1$dd){4}$/ ) { print "$a[$i] has MAC $mac\n"; } else { $tries++; if ( $tries < $max_tries ) { print "False MAC, try again.\n"; redo LOOP; } else { print "Too many false tries. Bye.\n"; exit; } } } } Hope this helps.
(This post was edited by Karazam on Mar 9, 2011, 1:43 AM)
|
|
|
Edit Log:
|
|
Post edited by Karazam
(User) on Mar 9, 2011, 1:33 AM
|
|
Post edited by Karazam
(User) on Mar 9, 2011, 1:41 AM
|
|
Post edited by Karazam
(User) on Mar 9, 2011, 1:43 AM
|
|
|  |