emacs - tidy up code
[dotfiles.git] / study-note.org
1 #+TITLE: Study Note
2 #+AUTHOR: Peng Li
3 #+EMAIL: seudut@gmail.com
4 #+DATE: 2016-08-18
5
6 * Programming Languages
7 ** Perl 
8 *** One line command
9 **** perl help
10 #+BEGIN_SRC sh :exports both :results output replace
11   perl --help
12 #+END_SRC
13
14 #+RESULTS:
15 #+begin_example
16
17 Usage: perl [switches] [--] [programfile] [arguments]
18   -0[octal]         specify record separator (\0, if no argument)
19   -a                autosplit mode with -n or -p (splits $_ into @F)
20   -C[number/list]   enables the listed Unicode features
21   -c                check syntax only (runs BEGIN and CHECK blocks)
22   -d[:debugger]     run program under debugger
23   -D[number/list]   set debugging flags (argument is a bit mask or alphabets)
24   -e program        one line of program (several -e's allowed, omit programfile)
25   -E program        like -e, but enables all optional features
26   -f                don't do $sitelib/sitecustomize.pl at startup
27   -F/pattern/       split() pattern for -a switch (//'s are optional)
28   -i[extension]     edit <> files in place (makes backup if extension supplied)
29   -Idirectory       specify @INC/#include directory (several -I's allowed)
30   -l[octal]         enable line ending processing, specifies line terminator
31   -[mM][-]module    execute "use/no module..." before executing program
32   -n                assume "while (<>) { ... }" loop around program
33   -p                assume loop like -n but print line also, like sed
34   -s                enable rudimentary parsing for switches after programfile
35   -S                look for programfile using PATH environment variable
36   -t                enable tainting warnings
37   -T                enable tainting checks
38   -u                dump core after parsing program
39   -U                allow unsafe operations
40   -v                print version, patchlevel and license
41   -V[:variable]     print configuration summary (or a single Config.pm variable)
42   -w                enable many useful warnings
43   -W                enable all warnings
44   -x[directory]     ignore text before #!perl line (optionally cd to directory)
45   -X                disable all warnings
46   
47 Run 'perldoc perl' for more help with Perl.
48
49 #+end_example
50
51 **** Used as =grep=
52 #+BEGIN_SRC sh
53   perl -ne 'print if /expression/' xxx.log;
54 #+END_SRC
55
56 #+BEGIN_SRC perl :results output replace
57   my $tt = "hello";
58   ($tt =~ /h(.*)o/ ) and print $1;
59 #+END_SRC
60
61 #+RESULTS:
62 : ell
63
64 Or 
65 #+BEGIN_SRC sh
66   perl -wnl -e '/keyword/ and print;' xxx.log
67 #+END_SRC
68
69 **** Used as =awk=
70 #+BEGIN_SRC sh
71   perl -ne 'print "$1\n" if /aaa=(\d+)\s.*/' xxx.log;
72 #+END_SRC
73
74 ** gnuplog
75
76 1. normal
77 #+BEGIN_SRC gnuplot :exports code :file ./temp/sin.png
78   reset
79   plot sin(x)/x
80 #+END_SRC
81
82 #+RESULTS:
83 [[file:./temp/sin.png]]
84
85 2. plot with data file
86 #+BEGIN_SRC fundamental :tangle ./temp/plot.dat 
87   # x y
88   1 11
89   2 12
90   3 13
91   4 14
92   5 15
93   6 16
94   7 17
95   8 18
96   9 19
97 #+END_SRC
98
99 #+BEGIN_SRC gnuplot :file ./temp/ll.png
100   reset
101   set xrange [0:10]
102   set yrange [0:20]
103   plot "./temp/plot.dat" using 1:2 with lines
104 #+END_SRC
105
106 #+RESULTS:
107 [[file:./temp/ll.png]]
108