From owner-freebsd-questions Fri Feb 1 10:26:52 2002 Delivered-To: freebsd-questions@freebsd.org Received: from smtp.bcn.isoco.net (ldap.isoco.net [212.9.90.11]) by hub.freebsd.org (Postfix) with ESMTP id 237E537B402 for ; Fri, 1 Feb 2002 10:26:45 -0800 (PST) Received: from fxn.bcn.isoco.net (fxn.bcn.isoco.net [172.16.1.50]) by smtp.bcn.isoco.net (Postfix) with SMTP id 6F37ACD2B5; Fri, 1 Feb 2002 19:26:43 +0100 (CET) Date: Fri, 1 Feb 2002 19:26:21 +0100 From: F.Xavier Noria To: z thompson Cc: freebsd-questions@freebsd.org Subject: Re: Perl question... Message-Id: <20020201192621.348fcfe4.fxn@isoco.com> In-Reply-To: <20020201095025.A79152@titus.lastamericanempire.com> References: <20020201095025.A79152@titus.lastamericanempire.com> X-Mailer: Sylpheed version 0.7.0 (GTK+ 1.2.10; i386--freebsd4.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, 1 Feb 2002 09:50:25 -0700 z thompson wrote: : * Eric Six [020201 09:00]: : > I have about 400 primary and 300 secondary DNS records that I have migrated : > from a bind4 server. I need to add a '$TTL value;' to the first line of all : > my zone files... : > : > I have found ways to append lines to the file, but not to create a new one : > at the very beginning. Also, any ideas on how to automate doing this to all : > the files in each dir? : > : : With temporary files... : : my $old_file = 'some_file'; # original file : my $tmp_file = '>some_file.tmp'; # a temp file : my $new_line = '$TTL value;'; # stuff to add to file Recursion in a directory tree is somewhat tricky. It is generally accepted that the best (and portable) way to accomplish that kind of work in Perl is to delegate the recursion to the standard module File::Find like this: # untested use File::Find; my $header = 'append this header to the top'; find(\&callback, '/root/dir/one', '/root/dir/two'); sub callback { return unless /some filter regexp/; open FILE, $_ or die $!; my $contents; {local $/; $contents = ;} close FILE; open FILE, ">$_" or die $!; print FILE $header, "\n"; print FILE $contents; close FILE; } -- fxn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message