develooper Front page | perl.perl5.porters | Postings from May 2013

[perl #42253] in place editing of files does not work outside main loop

From:
James E Keenan via RT
Date:
May 26, 2013 17:17
Subject:
[perl #42253] in place editing of files does not work outside main loop
Message ID:
rt-3.6.HEAD-2650-1369588642-1308.42253-15-0@perl.org
On Sat Mar 31 02:29:32 2007, estellnb@yahoo.de wrote:
> This is a bug report for perl from estellnb@yahoo.de,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> In place editing of files with the -i command line switch does work
> inside the main loop only.
> Nevertheless it is also supposed to be usable for prepending and
> appending data to the file being modified.
> i.e. the "select(STDOUT);" to revert IO before termination must not be
> executed before any user command (specified by any -e) including those
> in the END-sections.
> 
> The following perl call should append an inline for /etc/autobash.sh
> to
> the $usrdir/.bashrc if and only if that file is not already inlined by
> $usrdir/.bashrc:
> 
>  perl -ne 'BEGIN{my $hug=0} END{if($hug==0){print ".
> /etc/autobash.sh\n"};} s#auto.sh#autobash.sh#; print $_;
> if(m#^\W*(source|\.)\W+/etc/autobash.sh(;|\W*$)#){$hug++}'
>        -i $usrdir/.bashrc
> 
> or
> 
>  perl  -e 'BEGIN{my $hug=0} END{if($hug==0){print ".
> /etc/autobash.sh\n"};}' \
>       -pe 's#auto.sh#autobash.sh#;
> if(m#^\W*(source|\.)\W+/etc/autobash.sh(;|\W*$)#){$hug++}'
>        -i $usrdir/.bashrc
> 
> A better readable solution to begin/end blocks could even be the usage
> of mere -e blocks at first/last:
> 
>  perl  -e 'my $hug=0' \
>       -pe 's#auto.sh#autobash.sh#;' \
>       -ne 'if(m#^\W*(source|\.)\W+/etc/autobash.sh(;|\W*$)#){$hug++}'
> \
>        -e 'if($hug==0){print ". /etc/autobash.sh\n"}' \
>        -i $usrdir/.bashrc
> 
> Currently the 'print ". /etc/autobash.sh\n"' will be redirected to
> stdout instead of the $usrdir/.bashrc if called directly from the
> command line. Whenever it is called from a bash script the output of
> 'print ". /etc/autobash.sh\n"' is simply lost.
> 

Is there anyone fluent in the command-line use of Perl who could
evaluate the issues raised in this older ticket?

Thank you very much.
Jim Keenan


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=42253



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About