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

obstinate syntax errors

Thread Next
Rick T
January 19, 2018 17:51
obstinate syntax errors
Message ID:
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}: $!";

    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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About