Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Apr 2007 19:38:56 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Olivier Regnier <oregnier@steelbox.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: script perl with sed command
Message-ID:  <20070408163856.GB1484@kobe.laptop>
In-Reply-To: <4618B887.4030709@steelbox.org>
References:  <4617B954.7010507@steelbox.org> <20070407171120.GA70957@kobe.laptop> <4618B887.4030709@steelbox.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2007-04-08 11:40, Olivier Regnier <oregnier@steelbox.org> 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 = <SUP>)) {
> >|         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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070408163856.GB1484>