Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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!

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(); }
Data:
1:PGH:Pittsburgh
2:PGHW:Pittsburgh West End


In reply to Verify Town Name by PilotinControl

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found