LoginSignup
0
2

More than 5 years have passed since last update.

perltidyのpbpオプションで直接ファイルを書き換える

Last updated at Posted at 2017-04-28
> ls 
test.pl
> perltidy -b -pbp -nst test.pl
> ls
test.pl  test.pl.bak

Perlスクリプトの整形コマンドを使いやすいようにコマンドにしてみた。

bin/pbp
#!/bin/bash
#set -u

# man perltidy
#           In particular, if you want to use both the -b flag and the -pbp
#           (--perl-best-practices) flag, then you must put a -nst flag after the -pbp flag
#           because it contains a -st flag as one of its components, which means that output
#           will go to the standard output stream.

[ -z "$1" ] && echo "not enough arguments" &&  exit 1
[ ! -f $1 ] && echo "No such file or directory" && exit 1

perltidy -b -pbp -nst $1

diff -uprN $1.bak $1

example

> cat test.pl
my $aaa = 2;
if ($aaa == 2) {
    say $aaa . "abc";
}

> pbp test.pl
--- test.pl.bak 2017-04-29 04:03:25.818000000 +0900
+++ test.pl     2017-04-29 04:26:08.224000000 +0900
@@ -1,4 +1,4 @@
 my $aaa = 2;
-if ($aaa == 2) {
+if ( $aaa == 2 ) {
     say $aaa . "abc";
 }

> ls
test.pl  test.pl.bak

参考

PerlTidyでの一括整形コマンド

Linuxエンジニアらしいパッチのつくりかた

Documentation/translations/ja_JP/SubmittingPatches

パッチの作成には「 diff -up 」又は「 diff -uprN 」を使ってください。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2