[LON-CAPA-cvs] cvs: loncom /publisher lonpublisher.pm

raeburn raeburn at source.lon-capa.org
Fri Dec 12 13:27:34 EST 2014


raeburn		Fri Dec 12 18:27:34 2014 EDT

  Modified files:              
    /loncom/publisher	lonpublisher.pm 
  Log:
  - Coding style: 
    - keys() sort()
    - for readability eliminate use of $_
  
  
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.293 loncom/publisher/lonpublisher.pm:1.294
--- loncom/publisher/lonpublisher.pm:1.293	Sun Aug  3 14:20:38 2014
+++ loncom/publisher/lonpublisher.pm	Fri Dec 12 18:27:34 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.293 2014/08/03 14:20:38 raeburn Exp $
+# $Id: lonpublisher.pm,v 1.294 2014/12/12 18:27:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -200,12 +200,12 @@
 	    if (defined($token->[2]->{'name'})) { 
 		$unikey.="\0".$token->[2]->{'name'}; 
 	    }
-	    foreach (@{$token->[3]}) {
-		$metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
+	    foreach my $item (@{$token->[3]}) {
+		$metadatafields{$unikey.'.'.$item}=$token->[2]->{$item};
 		if ($metadatakeys{$unikey}) {
-		    $metadatakeys{$unikey}.=','.$_;
+		    $metadatakeys{$unikey}.=','.$item;
 		} else {
-		    $metadatakeys{$unikey}=$_;
+		    $metadatakeys{$unikey}=$item;
 		}
 	    }
 	    my $newentry=$parser->get_text('/'.$entry);
@@ -293,8 +293,8 @@
     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
 				       $aauthor,$regexp);
     my %courses=();
-    foreach (keys %evaldata) {
-	if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
+    foreach my $item (keys(%evaldata)) {
+	if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
 	    $courses{$1}=1;
         }
     }
@@ -382,12 +382,12 @@
     }
     my $selout="\n".&Apache::lonhtmlcommon::row_title($title)
               .'<select name="'.$name.'">';
-    foreach (@idlist) {
-        $selout.='<option value="'.$_.'"';
-        if ($_ eq $value) {
+    foreach my $id (@idlist) {
+        $selout.='<option value="'.$id.'"';
+        if ($id eq $value) {
 	    $selout.=' selected="selected"';
         }
-        $selout.='>'.&{$functionref}($_).'</option>';
+        $selout.='>'.&{$functionref}($id).'</option>';
     }
     $selout.='</select>'.&Apache::lonhtmlcommon::row_closure();
     return $selout;
@@ -787,12 +787,12 @@
 		}
 		my $newparmstring='';
 		my $endtag='';
-		foreach (keys %parms) {
-		    if ($_ eq '/') {
+		foreach my $parkey (keys(%parms)) {
+		    if ($parkey eq '/') {
 			$endtag=' /';
 		    } else { 
-			my $quote=($parms{$_}=~/\"/?"'":'"');
-			$newparmstring.=' '.$_.'='.$quote.$parms{$_}.$quote;
+			my $quote=($parms{$parkey}=~/\"/?"'":'"');
+			$newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
 		    }
 		}
 		if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
@@ -1197,9 +1197,9 @@
 
 # ------------------- Clear out parameters and stores (there should not be any)
 
-        foreach (keys %metadatafields) {
-	    if (($_=~/^parameter/) || ($_=~/^stores/)) {
-		delete $metadatafields{$_};
+        foreach my $field (keys(%metadatafields)) {
+	    if (($field=~/^parameter/) || ($field=~/^stores/)) {
+		delete $metadatafields{$field};
             }
         }
 
@@ -1208,23 +1208,21 @@
 
         $scrout.=&metaread($logfile,$source.'.meta');
 
-        foreach (keys %metadatafields) {
-	    if (($_=~/^parameter/) || ($_=~/^stores/)) {
-                $oldparmstores{$_}=1;
-		delete $metadatafields{$_};
+        foreach my $field (keys(%metadatafields)) {
+	    if (($field=~/^parameter/) || ($field=~/^stores/)) {
+                $oldparmstores{$field}=1;
+		delete $metadatafields{$field};
             }
         }
 # ------------------------------------------------------------- Save some stuff
         my %savemeta=();
-        foreach ('title') {
-            if ($metadatafields{$_}) { $savemeta{$_}=$metadatafields{$_}; }
-	}
+        if ($metadatafields{'title'}) { $savemeta{'title'}=$metadatafields{'title'}; }
 # ------------------------------------------ See if anything new in file itself
  
 	$allmeta=&parseformeta($source,$style);
 # ----------------------------------------------------------- Restore the stuff
-        foreach (keys %savemeta) {
-	    $metadatafields{$_}=$savemeta{$_};
+        foreach my $item (keys(%savemeta)) {
+	    $metadatafields{$item}=$savemeta{$item};
 	}
    }
 
@@ -1232,11 +1230,11 @@
 # ---------------- Find and document discrepancies in the parameters and stores
 
     my $chparms='';
-    foreach (sort keys %metadatafields) {
-	if (($_=~/^parameter/) || ($_=~/^stores/)) {
-	    unless ($_=~/\.\w+$/) { 
-		unless ($oldparmstores{$_}) {
-		    my $disp_key = $_;
+    foreach my $field (sort(keys(%metadatafields))) {
+	if (($field=~/^parameter/) || ($field=~/^stores/)) {
+	    unless ($field=~/\.\w+$/) {
+		unless ($oldparmstores{$field}) {
+		    my $disp_key = $field;
 		    $disp_key =~ tr/\0/_/;
 		    print $logfile ('New: '.$disp_key."\n");
 		    $chparms .= $disp_key.' ';
@@ -1250,11 +1248,11 @@
     }
 
     $chparms='';
-    foreach (sort keys %oldparmstores) {
-	if (($_=~/^parameter/) || ($_=~/^stores/)) {
-	    unless (($metadatafields{$_.'.name'}) ||
-		    ($metadatafields{$_.'.package'}) || ($_=~/\.\w+$/)) {
-		my $disp_key = $_;
+    foreach my $olditem (sort(keys(%oldparmstores))) {
+	if (($olditem=~/^parameter/) || ($olditem=~/^stores/)) {
+	    unless (($metadatafields{$olditem.'.name'}) ||
+		    ($metadatafields{$olditem.'.package'}) || ($olditem=~/\.\w+$/)) {
+		my $disp_key = $olditem;
 		$disp_key =~ tr/\0/_/;
 		print $logfile ('Obsolete: '.$disp_key."\n");
 		$chparms.=$disp_key.' ';
@@ -1331,7 +1329,7 @@
 	&hiddenfield('phase','two').
 	&hiddenfield('filename',$env{'form.filename'}).
 	&hiddenfield('allmeta',&escape($allmeta)).
-	&hiddenfield('dependencies',join(',',keys %allow));
+	&hiddenfield('dependencies',join(',',keys(%allow)));
     unless ($env{'form.makeobsolete'}) {
        $intr_scrout.=
 	&textfield('Title','title',$metadatafields{'title'}).
@@ -1692,17 +1690,17 @@
 		'</span>');
 	    return 0;
         }
-        foreach (sort keys %metadatafields) {
-            unless ($_=~/\./) {
-                my $unikey=$_;
+        foreach my $field (sort(keys(%metadatafields))) {
+            unless ($field=~/\./) {
+                my $unikey=$field;
                 $unikey=~/^([A-Za-z]+)/;
                 my $tag=$1;
                 $tag=~tr/A-Z/a-z/;
                 print $mfh "\n\<$tag";
-                foreach (split(/\,/,$metadatakeys{$unikey})) {
-                    my $value=$metadatafields{$unikey.'.'.$_};
+                foreach my $item (split(/\,/,$metadatakeys{$unikey})) {
+                    my $value=$metadatafields{$unikey.'.'.$item};
                     $value=~s/\"/\'\'/g;
-                    print $mfh ' '.$_.'="'.$value.'"';
+                    print $mfh ' '.$item.'="'.$value.'"';
                 }
                 print $mfh '>'.
                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
@@ -1908,9 +1906,9 @@
 # --------------------------------------------------- Notify subscribed courses
 	my %courses=&coursedependencies($target);
 	my $now=time;
-	foreach (keys %courses) {
-	    print $logfile "\nNotifying course ".$_.':';
-	    my ($cdom,$cname)=split(/\_/,$_);
+	foreach my $course (keys(%courses)) {
+	    print $logfile "\nNotifying course ".$course.':';
+	    my ($cdom,$cname)=split(/\_/,$course);
 	    my $reply=&Apache::lonnet::cput
 		('versionupdate',{$target => $now},$cdom,$cname);
 	    print $logfile $reply;




More information about the LON-CAPA-cvs mailing list