From owner-freebsd-questions@FreeBSD.ORG Sun Apr 8 16:39:39 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 64ECC16A406 for ; Sun, 8 Apr 2007 16:39:39 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id B167D13C4D5 for ; Sun, 8 Apr 2007 16:39:38 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (dialup26.ach.sch.gr [81.186.70.26]) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-3) with ESMTP id l38Gd0W3026355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 8 Apr 2007 19:39:09 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.13.8/8.13.8) with ESMTP id l38Gcw7Q001681; Sun, 8 Apr 2007 19:38:59 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.13.8/8.13.8/Submit) id l38Gcuus001680; Sun, 8 Apr 2007 19:38:56 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Sun, 8 Apr 2007 19:38:56 +0300 From: Giorgos Keramidas To: Olivier Regnier Message-ID: <20070408163856.GB1484@kobe.laptop> References: <4617B954.7010507@steelbox.org> <20070407171120.GA70957@kobe.laptop> <4618B887.4030709@steelbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4618B887.4030709@steelbox.org> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.688, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.51, BAYES_00 -2.60, DNS_FROM_RFC_ABUSE 0.20) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-questions@freebsd.org Subject: Re: script perl with sed command X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Apr 2007 16:39:39 -0000 On 2007-04-08 11:40, Olivier Regnier wrote: > Giorgos Keramidas a ?crit : > >Try using Perl only, instead of forking sed(1), like this: > > > >,----------------------------------------------------------------------- > >| > >| #!/usr/bin/perl -Tw > >| > >| use strict; > >| > >| # > >| # supfile_set_default_host($supfile, $newhost) > >| # Set the default host used by the supfile $supfile to the > >| # host name supplied as $newhost. > >| # > >| > >| sub supfile_set_default_host($$); > >| sub supfile_set_default_host($$) > >| { > >| my $tmpsupfile; > >| my $supfile = shift; > >| my $newhost = shift; > >| > >| if (!defined($supfile) || !defined($newhost)) { > >| return undef; > >| } > >| > >| $tmpsupfile = "tmp-" . $supfile; > >| open(SUP, "$supfile") or die "$!"; > >| open(TMP, "> $tmpsupfile") or die "$!"; > >| > >| my $line; > >| while (defined($line = )) { > >| chomp $line; > >| $line =~ s/^(\*[ \t]*default[ \t][ \t]*host[ \t]*=).*/$1${newhost}/; > >| print TMP "$line\n"; > >| } > >| close(TMP) or die "$!"; > >| close(SUP) or die "$!"; > >| rename("$tmpsupfile", "$supfile") or die "$!"; > >| return 1; > >| } > >| > >| supfile_set_default_host('standard-supfile', 'cvsup.example.net'); > >| > >`----------------------------------------------------------------------- > [...] > > Hello and thanks for this perl script. I'm new in perl and when i test > him, i have an error that says: > > No such file or directory at myscript.pl line 18 > > line 18 = open(TMP, "> $tmpsupfile") or die "$!"; Line 18 is not an open command, so something odd is happenning when you copy/paste the script from your mailer. Try downloading a copy of teh script from: http://people.freebsd.org/~keramida/files/supfile.perl