[LON-CAPA-cvs] cvs: loncom /interface londocs.pm
raeburn
raeburn@source.lon-capa.org
Sat, 13 Dec 2008 00:19:08 -0000
This is a MIME encoded message
--raeburn1229127548
Content-Type: text/plain
raeburn Sat Dec 13 00:19:08 2008 EDT
Modified files:
/loncom/interface londocs.pm
Log:
- Style
- eliminate $_
- push() sort() keys() split() grep().
--raeburn1229127548
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20081213001908.txt"
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.319 loncom/interface/londocs.pm:1.320
--- loncom/interface/londocs.pm:1.319 Thu Dec 11 14:55:15 2008
+++ loncom/interface/londocs.pm Sat Dec 13 00:19:07 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.319 2008/12/11 14:55:15 bisitz Exp $
+# $Id: londocs.pm,v 1.320 2008/12/13 00:19:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -84,14 +84,14 @@
my %outhash=();
my $home=0;
my $other=0;
- foreach (keys %env) {
- if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
my $role=$1;
my $realm=$2;
- my ($start,$end)=split(/\./,$env{$_});
+ my ($start,$end)=split(/\./,$env{$key});
if (($start) && ($start>time)) { next; }
if (($end) && (time>$end)) { next; }
- my $ca; my $cd;
+ my ($ca,$cd);
if ($1 eq 'au') {
$ca=$env{'user.name'};
$cd=$env{'user.domain'};
@@ -159,15 +159,15 @@
my $title=$env{'form.authorfolder'};
$title=&clean($title);
my %replacehash=();
- foreach (keys %env) {
- if ($_=~/^form\.namefor\_(.+)/) {
- $replacehash{$1}=$env{$_};
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.namefor\_(.+)/) {
+ $replacehash{$1}=$env{$key};
}
}
my $crs='/uploaded/'.$env{'request.course.id'}.'/';
$crs=~s/\_/\//g;
- foreach (keys %replacehash) {
- my $newfilename=$title.'/'.$replacehash{$_};
+ foreach my $item (keys(%replacehash)) {
+ my $newfilename=$title.'/'.$replacehash{$item};
$newfilename=~s/\.(\w+)$//;
my $ext=$1;
$newfilename=&clean($newfilename);
@@ -182,16 +182,16 @@
unless(mkdir($makepath,0777)) { $fail=1; }
}
}
- $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
+ $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
- if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
+ if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
print $fh &Apache::lonclonecourse::rewritefile(
- &Apache::lonclonecourse::readfile($env{'request.course.id'},$_),
+ &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
(%replacehash,$crs => '')
);
} else {
print $fh
- &Apache::lonclonecourse::readfile($env{'request.course.id'},$_);
+ &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
}
$fh->close();
} else {
@@ -209,8 +209,8 @@
$r->print(
'<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
}
- foreach (sort keys %outhash) {
- if ($_=~/^home_(.+)$/) {
+ foreach my $key (sort(keys(%outhash))) {
+ if ($key=~/^home_(.+)$/) {
if ($home==1) {
$r->print(
'<input type="hidden" name="authorspace" value="'.$1.'" />');
@@ -236,22 +236,22 @@
.'<th>'.&mt('Title').'</th>'
.'<th>'.&mt('Save as ...').'</th>'
.&Apache::loncommon::end_data_table_header_row());
- foreach (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
+ foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
$r->print(&Apache::loncommon::start_data_table_row()
- .'<td>'.$_.'</td>');
- my ($ext)=($_=~/\.(\w+)$/);
+ .'<td>'.$file.'</td>');
+ my ($ext)=($file=~/\.(\w+)$/);
my $title=$hash{'title_'.$hash{
- 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
+ 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
$r->print('<td>'.($title?$title:' ').'</td>');
if (!$title) {
- $title=$_;
+ $title=$file;
} else {
$title=~s|/|_|g;
}
$title=~s/\.(\w+)$//;
$title=&clean($title);
$title.='.'.$ext;
- $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td>"
+ $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
.&Apache::loncommon::end_data_table_row());
}
$r->print(&Apache::loncommon::end_data_table());
@@ -278,7 +278,7 @@
my $type = &Apache::loncommon::course_type();
my %discussiontime = &Apache::lonnet::dump('discussiontimes',
$env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
- my $numdisc = keys %discussiontime;
+ my $numdisc = keys(%discussiontime);
my $navmap = Apache::lonnavmaps::navmap->new();
my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
my $curRes;
@@ -448,8 +448,8 @@
}
|;
- foreach my $container (sort { $a <=> $b } keys %children) {
- my @contents = split/:/,$children{$container};
+ foreach my $container (sort { $a <=> $b } (keys(%children))) {
+ my @contents = split(/:/,$children{$container});
for (my $i=0; $i<@contents; $i ++) {
$scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
}
@@ -557,7 +557,7 @@
if ($curRes->is_sequence() || $curRes->is_page()) {
$lastcontainer = $count;
}
- if (grep/^$count$/,@$exportitems) {
+ if (grep(/^$count$/,@$exportitems)) {
&get_dependencies($exportitems,\%parent,$depth,\@dependencies);
}
}
@@ -581,7 +581,7 @@
if (ref($curRes)) {
$count ++;
- if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
+ if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
my $symb = $curRes->symb();
my $isvisible = 'true';
my $resourceref;
@@ -615,11 +615,11 @@
' <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
'" type="webcontent" href="'.$content_file.'">'."\n".
' <file href="'.$content_file.'" />'."\n";
- foreach (@hrefs) {
+ foreach my $item (@hrefs) {
$imsresources .=
- ' <file href="'.$_.'" />'."\n";
+ ' <file href="'.$item.'" />'."\n";
}
- if (grep/^$count$/,@$discussions) {
+ if (grep(/^$count$/,@$discussions)) {
my $ressymb = $symb;
my $mode;
if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
@@ -660,8 +660,8 @@
sub get_dependencies {
my ($exportitems,$parent,$depth,$dependencies) = @_;
if ($depth > 1) {
- if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
- push @$dependencies, $$parent{$depth};
+ if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
+ push(@{$dependencies},$$parent{$depth});
if ($depth > 2) {
&get_dependencies($exportitems,$parent,$depth-1,$dependencies);
}
@@ -867,7 +867,7 @@
my $copiedfile;
if ($copiedfile = Apache::File->new('>'.$destination)) {
print $copiedfile $embed_content;
- push @{$href}, 'resources/'.$count.'/res/'.$filename;
+ push(@{$href},'resources/'.$count.'/res/'.$filename);
my $attrib_regexp = '';
if (@{$allfiles{$embed_file}} > 1) {
$attrib_regexp = join('|',@{$allfiles{$embed_file}});
@@ -1046,7 +1046,7 @@
'currentfolder' => $env{'form.folder'});
if ($parmidx) {
$storehash{'parameter_res'}=$oldresources[$parmidx];
- foreach my $parm (keys %parmaction) {
+ foreach my $parm (keys(%parmaction)) {
$storehash{'parameter_action_'.$parm}=$parmaction{$parm};
$storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
}
@@ -1458,10 +1458,10 @@
# Group import/search
if ($env{'form.importdetail'}) {
my @imports;
- foreach (split(/\&/,$env{'form.importdetail'})) {
- if (defined($_)) {
+ foreach my $item (split(/\&/,$env{'form.importdetail'})) {
+ if (defined($item)) {
my ($name,$url,$residx)=
- map {&unescape($_)} split(/\=/,$_);
+ map {&unescape($_)} split(/\=/,$item);
push(@imports, [$name, $url, $residx]);
}
}
@@ -1738,8 +1738,8 @@
# no copy for published maps
$nocopy = 1;
} else {
- foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
- my ($title,$url,$ext,$type)=split(/\:/,$_);
+ foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
+ my ($title,$url,$ext,$type)=split(/\:/,$item);
if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
$nocopy=1;
last;
@@ -2049,9 +2049,9 @@
}
my $dependencies=
&Apache::lonnet::metadata($url,'dependencies');
- foreach (split(/\,/,$dependencies)) {
- if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
- &checkonthis($r,$_,$level+1);
+ foreach my $dep (split(/\,/,$dependencies)) {
+ if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
+ &checkonthis($r,$dep,$level+1);
}
}
} elsif ($result eq 'unavailable') {
@@ -2106,17 +2106,17 @@
undef %alreadyseen;
%alreadyseen=();
&tiehash();
- foreach (keys %hash) {
- if ($hash{$_}=~/\.(page|sequence)$/) {
- if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
+ foreach my $key (keys(%hash)) {
+ if ($hash{$key}=~/\.(page|sequence)$/) {
+ if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
$r->print('<hr /><span class="LC_error">'.
&mt('The following sequence or page is included more than once in your '.$type.': ').
- &unescape($hash{$_}).'</span><br />'.
+ &unescape($hash{$key}).'</span><br />'.
&mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
}
}
- if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
- &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
+ if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
}
}
&untiehash();
@@ -2154,16 +2154,16 @@
my %newsetversions=();
if ($env{'form.setmostrecent'}) {
$haschanged=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
$newsetversions{$1}='mostrecent';
&devalidateversioncache($1);
}
}
} elsif ($env{'form.setcurrent'}) {
$haschanged=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
my $getvers=&Apache::lonnet::getversion($1);
if ($getvers>0) {
$newsetversions{$1}=$getvers;
@@ -2173,11 +2173,11 @@
}
} elsif ($env{'form.setversions'}) {
$haschanged=1;
- foreach (keys %env) {
- if ($_=~/^form\.set_version_(.+)$/) {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.set_version_(.+)$/) {
my $src=$1;
- if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
- $newsetversions{$src}=$env{$_};
+ if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$key};
&devalidateversioncache($src);
}
}
@@ -2198,8 +2198,8 @@
# show all documents
$header=&mt('All Documents in '.$type);
$allsel=1;
- foreach (keys %hash) {
- if ($_=~/^ids\_(\/res\/.+)$/) {
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
my $src=$1;
$changes{$src}=1;
}
@@ -2209,7 +2209,7 @@
%changes=&Apache::lonnet::dump
('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
- my $firstkey=(keys %changes)[0];
+ my $firstkey=(keys(%changes))[0];
unless ($firstkey=~/^error\:/) {
unless ($env{'form.timerange'}) {
$env{'form.timerange'}=604800;
@@ -2273,14 +2273,14 @@
<input type="submit" name="setversions" value="$lt{'sv'}" />
<table border="0">
ENDHEADERS
- foreach (sort keys %changes) {
- if ($changes{$_}>$starttime) {
- my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
- my $currentversion=&Apache::lonnet::getversion($_);
+ foreach my $key (sort(keys(%changes))) {
+ if ($changes{$key}>$starttime) {
+ my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
+ my $currentversion=&Apache::lonnet::getversion($key);
if ($currentversion<0) {
$currentversion=&mt('Could not be determined.');
}
- my $linkurl=&Apache::lonnet::clutter($_);
+ my $linkurl=&Apache::lonnet::clutter($key);
$r->print(
'<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
&Apache::lonnet::gettitle($linkurl).
@@ -2453,13 +2453,13 @@
my $type = &Apache::loncommon::course_type();
# --------------------------------------------- Initialize help topics for this
- foreach ('Adding_Course_Doc','Main_Course_Documents',
- 'Adding_External_Resource','Navigate_Content',
- 'Adding_Folders','Docs_Overview', 'Load_Map',
- 'Supplemental','Score_Upload_Form','Adding_Pages',
- 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
- 'Check_Resource_Versions','Verify_Content') {
- $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
+ foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
+ 'Adding_External_Resource','Navigate_Content',
+ 'Adding_Folders','Docs_Overview', 'Load_Map',
+ 'Supplemental','Score_Upload_Form','Adding_Pages',
+ 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
+ 'Check_Resource_Versions','Verify_Content') {
+ $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
}
# Composite help files
$help{'Syllabus'} = &Apache::loncommon::help_open_topic(
@@ -2619,12 +2619,12 @@
}
my @attributes = ();
if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
- @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
+ @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
} else {
@attributes = ($env{'form.embedded_attrib_'.$i});
}
- foreach (@attributes) {
- push(@{$attribs{$i}},&unescape($_));
+ foreach my $attr (@attributes) {
+ push(@{$attribs{$i}},&unescape($attr));
}
if ($javacodebase) {
$codebase{$i} = $javacodebase;
@@ -2642,7 +2642,7 @@
my $updateflag = 0;
my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
if ($getstatus eq 'ok') {
- foreach my $item (keys %newname) {
+ foreach my $item (keys(%newname)) {
if ($newname{$item} ne $origname{$item}) {
my $attrib_regexp = '';
if (@{$attribs{$item}} > 1) {
@@ -2795,7 +2795,7 @@
$r->print('<p><span class="LC_error">'.$error.'</span></p>');
}
if ($hadchanges) {
- &mark_hash_old()
+ &mark_hash_old();
}
&changewarning($r,$postexec);
my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
--raeburn1229127548--