Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Use Perl as Better Shell Script
Search
karupanerura
May 31, 2025
Programming
0
720
Use Perl as Better Shell Script
Houtou.pm #1
karupanerura
May 31, 2025
Tweet
Share
More Decks by karupanerura
See All by karupanerura
GoでParserを書く
karupanerura
4
920
マイ隙間家具OSSたちのご紹介
karupanerura
2
260
Mustache Template 話 2024
karupanerura
0
27
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
2.9k
Javaの実装をPerlでテストする
karupanerura
0
1.2k
Go Generics Overview
karupanerura
0
1.3k
Japan.pm 2021 開催まで至る道
karupanerura
0
2.1k
Perl MongersのためのAWS_CDK入門
karupanerura
0
140
Webシステムのパフォーマンス・チューニング
karupanerura
2
840
Other Decks in Programming
See All in Programming
What's new in AppKit on macOS 26
1024jp
0
150
「次に何を学べばいいか分からない」あなたへ──若手エンジニアのための学習地図
panda_program
1
260
A full stack side project webapp all in Kotlin (KotlinConf 2025)
dankim
0
150
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
21k
可変変数との向き合い方 $$変数名が踊り出す$$ / php conference Variable variables
gunji
0
180
TypeScriptでDXを上げろ! Hono編
yusukebe
3
770
Hack Claude Code with Claude Code
choplin
7
2.6k
SQLアンチパターン第2版 データベースプログラミングで陥りがちな失敗とその対策 / Intro to SQL Antipatterns 2nd
twada
PRO
18
3.5k
状態遷移図を書こう / Sequence Chart vs State Diagram
orgachem
PRO
2
210
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
2
1.1k
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
2
15k
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
16
5.6k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
A Tale of Four Properties
chriscoyier
160
23k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Visualization
eitanlees
146
16k
It's Worth the Effort
3n
185
28k
Adopting Sorbet at Scale
ufuk
77
9.5k
Building an army of robots
kneath
306
45k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Transcript
Use Perl as Better Shell Script @karupanerura Houtou.pm #1
@karupanerura • Perl / Go / Java / TypeScript /etc..
• PAUSE: KARUPA • Software Engineer @ DeNA, Co,. LTD. • Chief Director @ Japan Perl Association
ࢁསͱࢲ • όϯυ • Live @ KAZOO HALL • ٢ా͏ͲΜ
• ͖ • ࢁསେֶϫΠϯ • ͏·͍ https://www.yamanashi.ac.jp/social/3131
None
Shell Script
Shell Script • ShellߏจΛͦͷ··ར༻ͨ͠εΫϦϓτ • ίϚϯυΛॻ͍ͯͦͷ··࣮ߦͰ͖ΔͷͰײత • CLIϕʔεͷૢ࡞ΛࣗಈԽ͢Δͷʹศར • WebܥͷਓͳΒ1ॻ͍ͨ͜ͱ͋Δͣʁ
None
؆୯ʂศརʂ
؆୯……ʁ
Shell Scriptͷ͠͞ • ίϚϯυͷڥࠩҟ • macOSͱLinuxͰsedawkͳͲͰBSD/GNUҧ͍͕͋ΔʢΦϓγϣϯ͕ҟͳΔʣ • ref. https://speakerdeck.com/mackee/perl-for-shell-awk-and-sed-programmers •
࣮ࡍͷίϚϯυͱϏϧτΠϯίϚϯυͱγΣϧߏจ͕ࠞࡏ͢Δ • bashͷtestͱ[ͱ[[ͷҧ͍Λઆ໌Ͱ͖ΔͬͯਓͲΕ͘Β͍͍·͔͢ʁ • ෳࡶͳσʔλߏΛѻ͏ͷ͕ۤख
খωλ: testͱ[ͱ[[ͷҧ͍ bash-5.2$ type [ [ γΣϧΈࠐΈؔͰ͢ bash-5.2$ type test
test γΣϧΈࠐΈؔͰ͢ bash-5.2$ type [[ [[ γΣϧͷ༧ޠͰ͢
খωλ: testͱ[ͱ[[ͷҧ͍ bash-5.2$ type [ [ γΣϧΈࠐΈؔͰ͢ bash-5.2$ type test
test γΣϧΈࠐΈؔͰ͢ bash-5.2$ type [[ [[ γΣϧͷ༧ޠͰ͢ ಉ͡ΈࠐΈؔ(alias) ߏจʢਖ਼نදݱͳͲαϙʔτʣ
ෳࡶͳσʔλߏͬͯͨͱ͑ • HashMap(Dict)ͷதʹ͞ΒʹHashMap(Dict)Λ࣋ͭͱ͔ • {"user1":{"user2":true}} • ͦͷͳ͔ʹ͞ΒʹArrayΛ࣋ͭͱ͔ • {"user1":{"user2":[100,200]}}
ෳࡶͳσʔλߏ in Shell Script $ declare -A data=(["user1"]=(["user2"]=true)) bash: ༧ظ͠ͳ͍τʔΫϯ
`(' पลʹߏจΤϥʔ͕͋Γ·͢
ෳࡶͳσʔλߏ in Shell Script $ declare -A data=(["user1"]=(["user2"]=true)) bash: ༧ظ͠ͳ͍τʔΫϯ
`(' पลʹߏจΤϥʔ͕͋Γ·͢ ʢૉʹʣ Ͱ͖ͳ͍
ෳࡶͳ͜ͱΛ͢Δͷ͍͠
͍͜͠ͱΛ͍ͨ͠ͱ͖……?
ಠஅͱภݟʹΑΓϓϩάϥϛϯάݴޠΛൺֱ • Ruby/Go/JavaScript/PHP: ڥʹΑͬͯೖ͍ͬͯͳ͍ • Python • ͍·Ͱ͍͍ͩͨͷڥʹPython3ܥ͕ೖ͍ͬͯΔ • Shellͱߏจ͕͍ͩͿҧ͏ͷͰॻ͖͕͑ͪΐͬͱखؒ
• Perl • ͍͍ͩͨͷڥʹೖ͍ͬͯΔ͠Shellͱߏจ͍ۙ
PerlͱbashͷߏจΛൺֱ #!/usr/bin/perl use strict; use warnings; # コマンドライン引数の取得 my $arg1
= shift @ARGV; # 配列の宣言 my @array; # コマンドの実行 system 'grep status:500 /var/log/ access.log | ...'; #!/bin/bash set -ue -o pipefail # コマンドライン引数の取得 arg1=$1; shift # 配列の宣言 declare -a array # コマンドの実行 grep status:500 /var/log/access.log | ...
PerlͱbashͷߏจΛൺֱ # ίϚϯυΛ࣮ߦͯ݁͠ՌΛมʹೖΕ͍ͨ my $result = `grep status:500 file`; #
݅ذ if ($x > 0) { ... } # ϧʔϓ while ($x > 0) { ... } # ίϚϯυΛ࣮ߦͯ݁͠ՌΛมʹೖΕ͍ͨ result=`grep status:500 file` # ݅ذ if [[ "$x" -gt 0 ]]; then ... fi # ϧʔϓ while [[ "$x" -gt 0 ]]; do ... done
Perl͡ΌΜ (?)
࣮ྫհͷίʔφʔ
ྫ: json-diff https://github.com/karupanerura/dot fi les/blob/master/bin/json-diff
ྫ: jwt https://github.com/karupanerura/dot fi les/blob/master/bin/jwt
༨ஊ: zxͱ͍͏ͭ͋Δ https://github.com/google/zx ׳ΕͯखʹೃછΊΑ͍͔
·ͱΊ
·ͱΊ • Shell Scriptศར͚ͩͲෳࡶͳ͜ͱΛΖ͏ͱ͢Δͱ͍͠ • ෳࡶͳ͜ͱΛΓ͍ͨͱ͖ϓϩάϥϛϯάݴޠʹஔ͖͑ΔͱΑ͍ • PerlShell Scriptͱߏจ͕͍ۙͷͰҠ২ϋʔυϧ͕͍ʢͱࢥ͏ʣ •
ਖ਼ղ͕͋ΔΘ͚Ͱͳ͍ͷͰɺΓ͍͢ํ๏Λࡧ͠·͠ΐ͏