ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/SCRAMUtils.pm
Revision: 1.4
Committed: Tue Mar 23 13:47:27 1999 UTC (26 years, 1 month ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_8, V0_7, V0_6, V0_5, V0_4, V0_3, V0_2, V0_1
Changes since 1.3: +4 -2 lines
Log Message:
Cut out duplication of a line in the key field

File Contents

# User Rev Content
1 williamc 1.1 #
2     # Utility Routines for the SCRAM tools
3     #
4    
5     package SCRAMUtils;
6 williamc 1.2 require 5.001;
7 williamc 1.1 require Exporter;
8     @ISA = qw(Exporter);
9     @EXPORT = qw(checkfile updatelookup);
10     use Carp;
11    
12 williamc 1.3 sub checkfile {
13 williamc 1.1 my $filename=shift;
14     my $thisfile="";
15     $thifile=$ENV{LOCALTOP}."/".$filename;
16     return $thisfile, if ( -e $thisfile );
17     $thifile=$ENV{RELEASETOP}."/".$filename;
18     return $thisfile, if ( -e $thisfile );
19     return "";
20     }
21    
22     #
23     # Replace or add an entry in a hashing file
24     #
25     sub updatelookup {
26     my $filename=shift;
27     my $key=shift;
28     my $rest=shift;
29     my $update=0;
30     use File::Copy;
31    
32     open ( SCRAMWORK, ">$filename.wk" ) or
33     croak "Unable to open $filename.wk ".$!."\n";
34     open ( SCRAMUPDATEFILE, $filename );
35 williamc 1.4 print "Searching for ".$key."\n";
36 williamc 1.1 while ( <SCRAMUPDATEFILE> ) {
37     if ( $_=~/^\Q$key\E/o ) {
38     $update=1;
39     print SCRAMWORK $key.$rest."\n";
40     }
41 williamc 1.4 else {
42     print SCRAMWORK $_;
43     }
44 williamc 1.1 }
45     close SCRAMUPDATEFILE;
46     if ( $update==0 ) {
47     print SCRAMWORK $key.$rest."\n";
48     }
49     close SCRAMWORK;
50     copy "$filename.wk", $filename or croak "Unable to update file "
51     ."$filename $!\n";
52    
53     }