* Curtis, Jonathan ([EMAIL PROTECTED]) wrote:
> The loop should return a flag ($found =1) and the line number ($eindex) of
> the user's data...
> --

Curtis, 

You would probably help yourself a lot if you hunkered down and
used 'use strict;'  One of the problems with your code is that 
you're using globals ('$ntlogin' and '$eindex').  Use 'my' to 
declare your variables and it will help you keep things straight.

Think of the variables in your main program not know anything about
each other except for the arguments that are passed (the subroutines
interface)

    my ($found,$eindex) = have_we_met('jcurtis');

NEVER have your subroutines use ANY variables that it doen't have
in its immediate scope.  It's just good practice and will help to 
you sane (or as sane as possible) :)

Here is your example with 'use strict' and 'my'

    #!/usr/bin/perl -w
    use strict;

    my ($found,$eindex) = have_we_met('jcurtis');

    sub have_we_met
    {
        my ($ntlogin) = @_;

        # return if you don't pass a login
        return (0) unless $ntlogin; 

        my $eindex;
        open DATA, "data.txt";
        my @data = <DATA>;
        close DATA;
        my $found = 0;
        for (my $i = 0; $i <= $#data; $i++) {
            my @cheese = split /,/, $data[$i];
            if ($cheese[0] eq $ntlogin) {
                $found=1;
                $eindex=$i;
            }
        }
        return ($found,$eindex);
    }

There are much BETTER ways to do this, but I don't want to overwhelm you 
with a simplified example when you're the first stop is programming without
globals.

-biz-

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to