[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Rename me Perl (fwd)



I've tried sending this to Mark directly (wanted to reduce bandwidth on the list) but the mail bounces back to me.

>Date: Fri, 21 Feb 1997 10:34:45 -0500
>To: mark@cheers.jsc.nasa.gov (Mark Manning/Metrica)
>From: Bob Wilkinson <bwilkinson@pindar.co.uk>
>Subject: Re: [MacPerl] Rename me Perl (fwd)
>Cc: 
>Bcc: 
>X-Attachments: :Macintosh HD:12087:main.pl: :Macintosh HD:12087:compact.pl:
>
>>According to Bob Wilkinson:
>>> >#!perl
>>> >
>>> >	&renameME;
>>> >	exit( 0 );
>>> >
>>> >sub renameME
>>> >{
>>> >	rename "myFriend.dat", "myFiend.dat"
>>> >}
>>> >
>>> Hello,
>>>       Which version of Perl are you using? I ran this code and it seemed to
>>> work
>>> as I expected it to (both as a single file, and as a pair of files).
>>> 
>>> I'm using the MacPerl appl version 513r2.
>>> 
>>> My understanding of the semi-colon as terminator is that it is optional in
>>> blocks with single statements (though recommended since you may later add lines
>>> to the block). I'm ready to be corrected (ooh yes please!!), though!
>>
>>I'm using 513r2 also on a PowerPC 603e 200mhz system.  The
>>actual program was a compaction routine for a database
>>which ended with the renaming of the new database to the
>>old database's name after archiving the old database.  So
>>the routine actually did have several lines of code in it
>>(about 40-50).  I can see about posting the entire set of
>>routines if need be.  Nothing fancy about them.  :-)  They
>>basically create a new database, open the old database,
>>read through the old database transferring the records to
>>the new database.  Then they rename the old database to
>>OLD.DBF along with OLD.INDEX and rename the new database to
>>the old database's name (index too).  Actually - here's the
>>code:
>>
>>The program was originally on a Mac and is now on a Unix box.
>>#
>>#   -------------------------------------------------------------------
>>#   Compact the database
>>#   -------------------------------------------------------------------
>>#
>>sub compactCRDB
>>{
>>    local( $curDir ) = @_;
>>
>>    local( $i, $newLine, $recLength, $recNumber, $newIndex );
>>    local( @indexInfo, @theLine, @fileStats );
>>#
>>#   Create the new database and index.
>>#
>>    unlink "$curDir/new.index";
>>    unlink "$curDir/new.dbf";
>>
>>    sysopen( INDEX, "$curDir/new.index", O_RDWR|O_CREAT ) ||
>>        die "Couldn't open the index file - writing\n";
>>    close( INDEX );
>>
>>    sysopen( DBF, "$curDir/new.dbf", O_RDWR|O_CREAT ) ||
>>        die "Couldn't open the dbf file - writing\n";
>>    close( DBF );
>>#
>>#   Get the old database's index information.
>>#
>>    &openCRDB( $curDir );
>>
>>    $recNumber = -1;
>>    for( $i=0; $i<=$#crdbIndex; $i++ ){
>>        @indexInfo = unpack( "LLL", $crdbIndex[$i] );
>>        print "Working on CR #$indexInfo[0]...please wait.\n";
>>
>>        if( $indexInfo[0] > 0 ){
>>            print "Writing CR #$indexInfo[0] to the new file...please wait.\n";
>>            &readCRDB( $curDir, $i );
>>
>>            @theLine = ();
>>            $theLine[++$#theLine] = $theUser;
>>            $theLine[++$#theLine] = $theProgrammer;
>>            $theLine[++$#theLine] = $theAdministrator;
>>            $theLine[++$#theLine] = $theDate;
>>            $theLine[++$#theLine] = $theTitle;
>>            $theLine[++$#theLine] = $crType;
>>            $theLine[++$#theLine] = $theProgram;
>>            $theLine[++$#theLine] = $theComputer;
>>            $theLine[++$#theLine] = $targetDate;
>>            $theLine[++$#theLine] = $targetVersion;
>>            $theLine[++$#theLine] = join( "\002", @thePriorities );
>>            $theLine[++$#theLine] = join( "\002", @theStatuses );
>>            $theLine[++$#theLine] = join( "\002", @theKeywords );
>>            $theLine[++$#theLine] = join( "\002", @origInfo );
>>            $theLine[++$#theLine] = join( "\002", @theDescription );
>>            $theLine[++$#theLine] = join( "\002", @theSolution );
>>            $theLine[++$#theLine] = join( "\002", @theLog );
>>            $newLine = join( "\001", @theLine );
>>
>>            $recNumber++;
>>            @fileStats = stat( "$curDir/new.dbf" );
>>            $recLength = length( $newLine );
>>
>>            $newIndex = pack( "LLL", $indexInfo[0], $fileStats[7], $recLength );
>>            sysopen( INDEX, "$curDir/new.index", O_RDWR ) ||
>>                die "Couldn't open the index file - writing\n";
>>
>>            seek( INDEX, 0, 2 );
>>            syswrite( INDEX, $newIndex, 12 );
>>            close( INDEX );
>>
>>            sysopen( DBF, "$curDir/new.dbf", O_RDWR ) ||
>>                die "Couldn't open the $curDir/new.dbf file - aborting.\n";
>>
>>            seek( DBF, 0, 2 );
>>            syswrite( DBF, $newLine, $recLength );
>>
>>            close( DBF );
>>            }
>>        }
>>
>>    &closeCRDB( $curDir );
>>
>>	rename "$curDir/crdb.dbf", "$curDir/old.dbf";
>>	rename "$curDir/crdb.index", "$curDir/old.index";
>>
>>	rename "$curDir/new.dbf", "$curDir/crdb.dbf";
>>	rename "$curDir/new.index", "$curDir/crdb.index";
>>#
>>#	Added in for Unix so everyone else can access the database.
>>#
>>    system( "chmod 777 crdb.dbf" );
>>    system( "chmod 777 crdb.index" );
>>}
>>
>>Try this without the semicolons and the system commands and
>>see if it gives you the error I encountered.  Be sure to
>>put in a few dummy routines as well since this is like
>>routine #5 or 6 in the file.  Also, there are different
>>error messages generated depending upon whether you place a
>>PACKAGE command around the routines or load them in via the
>>DO command.  :-)
>
>Hello,
>      I've tried running the codes I've appended as attachments. The code still
>works OK - it creates two files, and then renames them. Can you run the codes
>I've supplied to see if you get the same result as me? You'll probably need to
>modify the path in main.pl. It works consistently with "do" and "require", and 
>with the "package" statement uncommented.
>
>      I've not cc.ed this to the list, but when the issue is resolved, we should
>inform the list.
>
>      If there's something I've misinterpreted please inform me. If you want,
>send me your complete codes and I'll see if I can duplicate your error.
>
>      Bob
>
>P.S. I'm running on a Performa 475
>
>
>
>
>

________________________________________________________________
          Bob Wilkinson, Perl Programmer, Pindar plc
Tel: +44 (0)1904 613040    Email: B.Wilkinson@pindar.co.uk
Fax: +44 (0)1904 613110    URL: http://www.connection.co.uk/bob
________________________________________________________________
  I don't speak for my employer - er, they made me say that..
________________________________________________________________