If you run perltidy over it you will also notice that the indentation seems odd - it never returns to the left margin. This is because you are one } short which perl notes as this script does not actually compile.

#!/bin/perl use IO::Socket; use IO::Select; $/ = "\015\012"; $nconnections_new = 0; $login = ""; $maxconn = SOMAXONN; $local = IO::Socket::INET->new( Proto => "tcp", LocalPort => "1234", Listen => $maxconn, Reuse => 1 ) or die "Can't open socket\n"; while ( $client = $local->accept ) { $client->autoflush(1); &start; sub start { print $client "This is a test BBS!\n\r"; print $client "(C)reate new user (L)ogin"; print $client "\n\r"; my $option = <$client>; chomp $option; $option = "\U$option\E"; if ( $option eq "C" ) { print $client "<<<Create new user>>>\n\r"; print $client "Login must be at least 6 characters.\n\r"; &login; } elsif ( $option eq "L" ) { &logon; } else { &start; } sub login { $/ = "\015\012"; print $client "username:"; $login = <$client>; chomp $login; if ( $login eq "" ) { print $client "Must enter a username!\n\r"; &login; } $/ = "\012"; open( FILE1, "users.txt" ) || print "Error occured while opening file"; while (<FILE1>) { ( $first, $second ) = split /:/; print $first; if ( $login eq $first ) { print $client "Sorry this username has been taken, try again!\ +n\r"; &login; } $/ = "\015\012"; } close(FILE1); if ( length($login) > 7 ) { print $client "Your username was longer than 6 charact +ers!\n\r"; &login; } $pass = password(); sub password { print $client "Password:"; $password = <$client>; chomp $password; print $client "\n\rRe-enter password:"; $password2 = <$client>; chomp $password2; if ( $password ne $password2 ) { print $client "Passwords do not match, try again!" +; &password; } return $password; } open( FILE, ">>users.txt" ) || print "Error occured while opening file"; print FILE "$login:$pass\n"; close(FILE); print "File written..\n\r"; exit; } } sub logon { print $client "test"; } close $client;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Variable messes up loops. by tachyon
in thread Variable messes up loops. by thran

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.