K
kj
I want to turn this "one-liner" (broken up for clarity)
perl -i.bak -pe ' \
BEGIN { $T = 8 } \
1 while s{^( *)\t} \
{$1 . (" " x ($T-((length $1)%$T)))}ex' \
some_file
into a script, but leaving the -i option (whether it is used or
not, and if so, what argument, if any, to give it) entirely up to
the user.
The simplest thing to do would be to set up the file:
BEGIN { $ = 8 }
# replace a tab-containing prefix with a prefix containing only
# spaces and producing the same level of indentation
1 while s{^( *)\t}
{$1 . (' ' x ($T-((length $1)%$T)))}ex
__END__
....making the script executable. The problem with this is that I
lose the -i option. And if I invoke the script like this
perl -p -i.bak my_script.pl some_file
....I end up having to repeat the mandatory "perl -p" part every time.
What's the best way to do what I'm trying to do here? (In case it
matters, I'm using bash under Linux, and portability is not a
concern.)
TIA,
kj
P.S. BTW, is there a way to achieve the same effect with a single
s/// (or maybe s///g), without requiring a while loop?
perl -i.bak -pe ' \
BEGIN { $T = 8 } \
1 while s{^( *)\t} \
{$1 . (" " x ($T-((length $1)%$T)))}ex' \
some_file
into a script, but leaving the -i option (whether it is used or
not, and if so, what argument, if any, to give it) entirely up to
the user.
The simplest thing to do would be to set up the file:
BEGIN { $ = 8 }
# replace a tab-containing prefix with a prefix containing only
# spaces and producing the same level of indentation
1 while s{^( *)\t}
{$1 . (' ' x ($T-((length $1)%$T)))}ex
__END__
....making the script executable. The problem with this is that I
lose the -i option. And if I invoke the script like this
perl -p -i.bak my_script.pl some_file
....I end up having to repeat the mandatory "perl -p" part every time.
What's the best way to do what I'm trying to do here? (In case it
matters, I'm using bash under Linux, and portability is not a
concern.)
TIA,
kj
P.S. BTW, is there a way to achieve the same effect with a single
s/// (or maybe s///g), without requiring a while loop?