Uri,

Thank you SO much for your helpful comments! You didn’t just solve THIS 
problem, you’ve helped me in my future programming!

Rick

> On Jan 19, 2018, at 11:56 AM, Uri Guttman <u...@stemsystems.com> wrote:
> 
> On 01/19/2018 12:44 PM, Rick T wrote:
>> 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
> 
> don't use $&. use () to grab the match and then use $1. also you don't check 
> the regex if it worked or not.
>> 
>>     # 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();
>>         );
> 
> or takes an expression on each side. you have multiple statements inside the 
> () so that is not an expression. change that to a proper block in one of two 
> ways:
> 
> unless( chdir "path" ) {
>    $message = "error" ;
>    report_error() ;
> }
> 
> or change the () to do{} which is an expression which has a block which can 
> contain multiple statements.
> 
> thanx,
> 
> uri
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org 
> <mailto:beginners-unsubscr...@perl.org>
> For additional commands, e-mail: beginners-h...@perl.org 
> <mailto:beginners-h...@perl.org>
> http://learn.perl.org/ <http://learn.perl.org/>

Reply via email to