PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:
Hello Fellow Monks!
I have a perplexing issue with my code below. I am trying to verify a town name located in a file using it as a check and balance before moving on to the next user input. However no matter what is inputted it moves on with out giving notice stating the town name has not been found. Thanks in advance!
Data:sub addind { open(MYINPUTFILE, "townsdata.txt"); # OPEN FOR INPUT $| = 1; my @lines = <MYINPUTFILE>; # READ FILE INTO LIST print "INDUSTRY TOWN\n"; my $indtwn = <STDIN>; $indtwn = <STDIN> until defined $indtwn; chomp $indtwn; cls(); my $found = 0; foreach my $townverify (@lines) { my @field = split(':',$townverify); if ($field[0] =~ m/^#/) { next; } if ($field[1] =~ /(?<![\w-])$indtwn(?![\w-])/i) { cls(); $found = 1; } else { cls(); print "TOWN RECORD NOT FOUND\n"; sleep 3; cls(); addind(); } # END FOREACH FILE LOOP my $output="inddata.txt"; open(DAT,"+<$output") || die("Cannot Open File"); my $indline; $indline = <DAT> until eof DAT; my ($indid) = $indline =~ m/\A(\d+):/; print DAT (++$indid); print DAT (":"); print DAT ($indtwn); print DAT ("\n"); close (DAT); print "INDUSTRY SUCCESSFULLY ADDED!!\n"; sleep 3; cls(); industry(); }
1:PGH:Pittsburgh
2:PGHW:Pittsburgh West End
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Verify Town Name
by Discipulus (Canon) on Nov 30, 2021 at 07:47 UTC | |
by davido (Cardinal) on Dec 01, 2021 at 00:01 UTC | |
by LanX (Saint) on Dec 01, 2021 at 01:00 UTC | |
by PilotinControl (Pilgrim) on Dec 02, 2021 at 22:29 UTC | |
Re: Verify Town Name
by Anonymous Monk on Nov 30, 2021 at 07:47 UTC | |
Re: Verify Town Name
by cavac (Parson) on Nov 30, 2021 at 13:31 UTC | |
Re: Verify Town Name
by vincent_veyron (Sexton) on Dec 04, 2021 at 23:07 UTC |
Back to
Seekers of Perl Wisdom