Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in place editing of files does not work outside main loop #8857

Open
p5pRT opened this issue Mar 31, 2007 · 3 comments
Open

in place editing of files does not work outside main loop #8857

p5pRT opened this issue Mar 31, 2007 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 31, 2007

Migrated from rt.perl.org#42253 (status was 'open')

Searchable as RT42253$

@p5pRT
Copy link
Author

p5pRT commented Mar 31, 2007

From estellnb@yahoo.de

Created by estellnb@yahoo.de

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.

Perl Info

Flags:
    category=core
    severity=low

This perlbug was built using Perl v5.8.8 - Sun Apr 23 00:25:53 UTC 2006
It is being executed now by  Perl v5.8.8 - Sun Apr 23 00:20:53 UTC 2006.

Site configuration information for perl v5.8.8:

Configured by abuild at Sun Apr 23 00:20:53 UTC 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.16, archname=i586-linux-thread-multi
    uname='linux tait 2.6.16 #1 smp tue mar 14 18:04:33 utc 2006 i686
i686 i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr
-Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm
-Duseshrplib=true -Doptimize=-O2 -march=i586 -mtune=i686
-fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall
-D_FORTIFY_SOURCE=2 -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING
-fno-strict-aliasing -pipe -Wdeclaration-after-statement'
    ccversion='', gccversion='4.1.0 (SUSE Linux)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.4.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-rpath,/usr/lib/perl5/5.8.8/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'

Locally applied patches:
    


@INC for perl v5.8.8:
    /usr/lib/perl5/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/5.8.8
    /usr/lib/perl5/site_perl/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl
    .


Environment for perl v5.8.8:
    HOME=/home/elm
    LANG=de_DE.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
   
PATH=./:/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/opt/kde3/bin:/usr/lib/qt3/bin/:/opt/gnome/bin:/etc/init.d:/sbin:/usr/local/sbin:/usr/sbin:/opt/kde3/sbin:/opt/gnome/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @jkeenan

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

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants