Perl debug

#!/usr/bin/perl --

use strict;
use warnings;

my $message = 'Hello';
my @nums = (1, 2, 3);
my %scores = (math => 80, english => 77);

my $twice = twice(5);

$DB::single = 1;

for my $num (@nums){
	if ($num == 2) { $DB::single = 1}
	print "$num\n";
}

sub twice {
	my $num = shift;

	return $num * 2;
}

[vagrant@localhost cgi-bin]$ perl -d app.cgi

Loading DB routines from perl5db.pl version 1.32
Editor support available.

Enter h or `h h’ for help, or `man perldebug’ for more help.

main::(app.cgi:6): my $message = ‘Hello’;
DB<1> q

-dオプションでデバッガの起動ということだが、うむ、イマイチよくわからん。
q でデバック終了。
n でシングルステップ

違う例で見てみる。

#!/usr/bin/perl —

use strict;
use warnings;

my $num = 3;
for(my $i=1;$i<=3;$i++){ print $num*$i."\n"; } [/perl]

[vagrant@localhost cgi-bin]$ perl app.cgi
3
6
9
[vagrant@localhost cgi-bin]$ perl -d app.cgi

Loading DB routines from perl5db.pl version 1.32
Editor support available.

Enter h or `h h’ for help, or `man perldebug’ for more help.

main::(app.cgi:6):      my $num = 3;
  DB<1> n
main::(app.cgi:9):      }
  DB<1> n
main::(app.cgi:7):      for(my $i=1;$i<=3;$i++){
  DB<1> n
main::(app.cgi:8):              print $num*$i.”\n”;
  DB<1> n
3
main::(app.cgi:8):              print $num*$i.”\n”;
  DB<1> n
6
main::(app.cgi:8):              print $num*$i.”\n”;
  DB<1> n
9
Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
  DB<1> q

なるほど、1行ずつ見ていくのね。

.swf

.sft is an extension attached to a video file created by the animation creation software for the Web “Flash” sold by Macromedia.
In order to play .swf format files, playback software called “Flash Player” is required.

セッション作成とセッションインスタンス取得

session_start();
$_SESSION['key']="orange";
echo $_SESSION['key'];

うん、ここらへんは基本ですね。

セッション削除はunset

session_start();
$_SESSION['key']="orange";
echo $_SESSION['key'];

unset($_SESSION['key']);
echo $_SESSION['key'];

[Mon Apr 22 23:18:28 2019] PHP Notice: Undefined index: key in /home/vagrant/local/app/test/index.php on line 8

まあ、この辺の応用でしょうね。

session

A session is a sequence of action taken by accessing a Web site.
One session from accessing the website to leaving the site or closing the browser.

The web server has a unique ID for each session, even if it is a Web system that spans multiple pages by using this.
It is possible to save and keep information for each user.

The most typical way to use this session is a web page. The most commonly used function is login/logout.

Think of one session from logging in to logging out. In the meantime, save status such as user ID and password.

5chまとめサイト

5chまとめサイトを分析していきます。

アルファモザイク
http://alfalfalfa.com/
– レフトメニューに人気の記事、コメントの多い記事、最近コメントされた記事など

痛いニュース
http://blog.livedoor.jp/dqnplus/
– 最新記事が写真とタイトルで一覧表示
– サイドメニューは広告

ニュー速クオリティ
http://news4vip.livedoor.biz/

ついんてーる速報
http://twintailsokuhou.blog.jp/
– トップがWPのブログっぽい

VIPPERな俺
http://blog.livedoor.jp/news23vip/
– アニメが多いな

キニ速
http://blog.livedoor.jp/kinisoku/
– ファーストビューにテキスト表示されるのはいいですね。

おる速
http://orusoku.com/
– テキストが青で見にくい

ゴールデンタイムズ
http://blog.livedoor.jp/goldennews/
– RSS表示
– やっぱり画像は必須か。

というか、まとめサイト多すぎるな。。

戻り値

A function can pass a value using an argument when it is called, but as a result of processing in the function, it can return a value from the function to the caller this time.
For example, functions that perform numerical calculations can return the calculation results to the caller, and functions that process strings can return the processed results.

Use the return statement to return a value from a function.

function mul($num1, $num2){
	$sum = $num1 * $num2;
	return $sum;
}

$sum = mul(10, 9);
print "乗算の結果は". $sum . "です。<br>";

print "乗算2の結果は". mul(7, 14)."です。";

乗算の結果は90です。
乗算2の結果は98です。

なるほど、returnで返しているのが戻り値と言えそうですね。

関数の引数とは?

function outputName($name){
	echo "私の名前は".$name. "です。<br>";
}
outputName("坂本");
outputName("五十嵐");
outputName("熊田");

私の名前は坂本です。
私の名前は五十嵐です。
私の名前は熊田です。

関数で引数を取る。
引数は複数も可。

function outputName($last_name, $first_name, $area){
	echo "私の名前は".$last_name.$first_name. $area ."出身です。<br>";
}
outputName("坂本","幸子","沖縄");
outputName("五十嵐","義男","山口");
outputName("熊田","ひろむ","長野");

私の名前は坂本幸子沖縄出身です。
私の名前は五十嵐義男山口出身です。
私の名前は熊田ひろむ長野出身です。

rm 複数ファイル

あれ? これって、単純にコマンドラインで複数書いていけばいいだけ!?

[vagrant@localhost test]$ ls
a.csv  a.txt  index.php  sample.jpg  sample.json
[vagrant@localhost test]$ rm a.csv a.txt sample.jpg sample.json
[vagrant@localhost test]$ ls
index.php

なんじゃーこりゃーーーーーーーーーー