[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 23 Sep 2005 20:39:38 -0000


albertel		Fri Sep 23 16:39:38 2005 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
   - BUG#4347 
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.302 loncom/homework/structuretags.pm:1.303
--- loncom/homework/structuretags.pm:1.302	Fri Sep 23 16:16:50 2005
+++ loncom/homework/structuretags.pm	Fri Sep 23 16:39:35 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.302 2005/09/23 20:16:50 albertel Exp $
+# $Id: structuretags.pm,v 1.303 2005/09/23 20:39:35 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1078,17 +1078,19 @@
 	    #  print "<b>END-TAG $b_tok->[1]</b><br />";
 	    # }
 	}
-	my @idx_arr = (0 .. $#randomlist);
-	&Apache::structuretags::shuffle(\@idx_arr);
-	my $bodytext = '';
-	my $show=$#randomlist;
-	my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
-	$showarg--;
-	if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
-	for(0 .. $show) {
-	    $bodytext .= "$randomlist[ $idx_arr[$_] ]";
+	if (@randomlist) {
+	    my @idx_arr = (0 .. $#randomlist);
+	    &Apache::structuretags::shuffle(\@idx_arr);
+	    my $bodytext = '';
+	    my $show=$#randomlist;
+	    my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
+	    $showarg--;
+	    if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
+	    for(0 .. $show) {
+		$bodytext .= "$randomlist[ $idx_arr[$_] ]";
+	    }
+	    &Apache::lonxml::newparser($parser,\$bodytext);
 	}
-	&Apache::lonxml::newparser($parser,\$bodytext);
     } elsif ($target eq 'edit' ) {
 	$result .=&Apache::edit::tag_start($target,$token);
 	$result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
@@ -1105,7 +1107,7 @@
 sub shuffle {
     my $a=shift;
     my $i;
-    if (defined(@$a)) {
+    if (ref($a) eq 'ARRAY' && @$a) {
 	&Apache::response::pushrandomnumber();
 	for($i=@$a;--$i;) {
 	    my $j=int(&Math::Random::random_uniform() * ($i+1));