develooper Front page | perl.beginners | Postings from January 2018

obstinate syntax errors

Thread Next
From:
Rick T
Date:
January 19, 2018 17:51
Subject:
obstinate syntax errors
Message ID:
515D8F7E-6015-41DF-84B9-6250B4D6B63E@reason.net
The subroutine below produces the following syntax errors:

syntax error at /big/dom/xexploringmyself/cgi-bin/register.cgi line 71, near ""Can't change directory to $progress_hash{student_id}: $!";"
syntax error at /big/dom/xexploringmyself/cgi-bin/register.cgi line 73, near ")"

I've tried adding and removing semicolons and even changing the parentheses to braces. But the only way I've been able to eliminate errors has been to comment out the 5 lines that begin with chdir.

I'm new to this (still struggle with the Learning Perl book), but after quite a few hours of no progress, I humbly ask for help!

sub get_student_data{
    # Extract student number to build student_info file name
    $progress_hash{student_id} =~ /\d+$/; # Match trailing digits
    my $student_number = $&; # Save matching portion

    # Tie to student_info file to get more params
    my $student_info_file = 'student_info-' . $student_number . '.db';

    chdir "/big/dom/x$server/data/students/$progress_hash{student_id}/"
        or (
            $message = "Can't change directory to $progress_hash{student_id}: $!";
            report_error();
        );

    tie %student_info_hash, 'DB_File', $student_info_file, O_RDONLY
        or die "Can't tie student_hash to $student_info_file: $!\n";

    # Get student's full name
    $progress_hash{name_full} = $student_info_hash{name_full};
}

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About