From: Mike G. v. a. <we...@ma...> - 2009-07-13 00:07:31
|
Log Message: ----------- defined not_blank() subroutine to check that string exists and is not blank. Modified Files: -------------- webwork2/lib/WeBWorK: Utils.pm Revision Data ------------- Index: Utils.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/Utils.pm,v retrieving revision 1.82 retrieving revision 1.83 diff -Llib/WeBWorK/Utils.pm -Llib/WeBWorK/Utils.pm -u -r1.82 -r1.83 --- lib/WeBWorK/Utils.pm +++ lib/WeBWorK/Utils.pm @@ -62,11 +62,13 @@ encodeAnswers fisher_yates_shuffle formatDateTime + has_aux_files intDateTime list2hash listFilesRecursive makeTempDirectory max + not_blank parseDateTime path_is_subdir pretty_print_rh @@ -895,6 +897,7 @@ map { defined $_ ? $_ : $_[0] } @_[1..$#_]; } + # shuffle an array in place # Perl Cookbook, Recipe 4.17. Randomizing an Array sub fisher_yates_shuffle { @@ -1000,6 +1003,30 @@ return map{$itemsByIndex{$_}} @sKeys; } +################################################################################ +# Validate strings and labels +################################################################################ +sub not_blank ($) { # check that a string exists and is not blank + my $str = shift; + return( defined($str) and $str =~/\S/ ); +} + +########################################################### + # If things have worked so far determine if the file might be accompanied by auxiliary files + + # +sub has_aux_files ($) { # determine whether a question has auxiliary files + # a path ending in foo/foo.pg is assumed to contain auxilliary files + my $path = shift; + if ( not_blank($path) ) { + my ($dir, $prob) = $path =~ m|([^/]+)/([^/]+)\.pg$|; # must be a problem file ending in .pg + return 1 if (defined($dir) and defined ($prob) and $dir eq $prob); + } else { + warn "This subroutine cannot handle empty paths: |$path|",caller(); + } + return 0; # no aux files with this .pg file + +} 1; |