[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Wed, 18 Feb 2009 06:54:22 -0000


raeburn		Wed Feb 18 06:54:22 2009 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Allow lonnet::delenv() to treat $delthis string passed to it as a regexp, by adding second arg ($regexp - if evaluated to true do not use \Q escape).
  - Default (second arg false) is to use \Q escape to avoid interpolating special characters in $delthis in regular expression (rev 1.981 behavior). All but one &lonnet::delenv() call use this default.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.986 loncom/lonnet/perl/lonnet.pm:1.987
--- loncom/lonnet/perl/lonnet.pm:1.986	Tue Feb 10 11:15:16 2009
+++ loncom/lonnet/perl/lonnet.pm	Wed Feb 18 06:54:22 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.986 2009/02/10 11:15:16 foxr Exp $
+# $Id: lonnet.pm,v 1.987 2009/02/18 06:54:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -528,7 +528,7 @@
 # ----------------------------------------------------- Delete from Environment
 
 sub delenv {
-    my $delthis=shift;
+    my ($delthis,$regexp) = @_;
     if (($delthis=~/user\.role/) || ($delthis=~/user\.priv/)) {
         &logthis("<font color=\"blue\">WARNING: ".
                 "Attempt to delete from environment ".$delthis);
@@ -541,10 +541,17 @@
 	tie(my %disk_env,'GDBM_File',$env{'user.environment'},
 	    (&GDBM_WRITER()|&GDBM_NOLOCK()),0640)) {
 	foreach my $key (keys(%disk_env)) {
-	    if ($key=~/^\Q$delthis\E/) { 
-		delete($env{$key});
-		delete($disk_env{$key});
-	    }
+	    if ($regexp) {
+                if ($key=~/^$delthis/) {
+                    delete($env{$key});
+                    delete($disk_env{$key});
+                } 
+            } else {
+                if ($key=~/^\Q$delthis\E/) {
+		    delete($env{$key});
+		    delete($disk_env{$key});
+	        }
+            }
 	}
 	untie(%disk_env);
     }
@@ -9308,9 +9315,11 @@
 
 =item *
 X<delenv()>
-B<delenv($regexp)>: removes all items from the session
-environment file that matches the regular expression in $regexp. The
-values are also delted from the current processes %env.
+B<delenv($delthis,$regexp)>: removes all items from the session
+environment file that begin with $delthis. If the 
+optional second arg - $regexp - is true, $delthis is treated as a 
+regular expression, otherwise \Q$delthis\E is used. 
+The values are also deleted from the current processes %env.
 
 =item * get_env_multiple($name)