PHPでの空白文字の取り扱い

ヒアドキュメント

http://d.hatena.ne.jp/mofc/20081109/1226215328
・内部でタブを用いてはならない
・閉じ括弧の後ろに半角スペースもダメ

これははまりそうで怖い。

変数の式展開

<?php
$product = "鉛筆";
print "{$product}を販売しています。<br/>\n"; //式展開の基本形
print "$product を販売しています。<br/>\n"; //これはOK(ダブルクオーテーションでは中括弧省略可)
print "$productを販売しています。<br/>\n"; //これはダメ(変数の後ろにスペースが必要)
print '$product を販売しています。<br/>\n'; //これもダメ(シングルクォーテーションでは式展開されない) 
?>

XAMPP for Macのインストール

PerをやるためにXAMPPをインストール。
http://www.zubapita.jp/2008/05/02/mac%E3%81%A7web%E9%96%8B%E7%99%BA-1-xampp-for-mac%E3%81%AE%E7%92%B0%E5%A2%83%E8%A8%AD%E7%BD%AE/
ここを参考に。

MySQLの設定は、

[@ ~]$/Applications/XAMPP/xamppfiles/bin/mysqladmin -u root -p password '********'

すると、

Enter password: 
/Applications/XAMPP/xamppfiles/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' exists!

xamppfiles/etc/my.cnfのsocketをコメントアウトしてみたらMySQLは動いた。
ただし、これだとphpMyAdminがエラーを起こす。

Error
MySQL said: 

#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured) 

xamppfiles/phpmyadmin/config.inc.phpを編集してみる。
http://zourbuth.com/2002-the-server-is-not-responding-or-the-local-mysql-servers-socket-is-not-correctly-configured/

$cfg['Servers'][$i]['connect_type'] = 'tcp';

にしてみたけどダメ。
そこでMySQLソケットの位置を確認する。
http://d.hatena.ne.jp/milk1000cc/20090303/1236049208

[@ ~]$mysql_config --socket
/tmp/mysql.sock

これをもとにmy.cnfとconfig.inc.phpに指定するも動かない。
phpMyAdminは保留。

次にセキュリティ設定を行う。
httpd.confを編集する。

<Directory "(hogehoge)/xamppfiles/htdocs">
    ...
    Order deny, allow
    Deny from All
    Allow from localhost 127.0.0.1
</Directory>

あとcgi-binのフォルダも同じように設定

次に、

[@ etc]$/Applications/XAMPP/xamppfiles/xampp security

を実行。

You need to be root to perform this action.
[@ etc]$sudo /Applications/XAMPP/xamppfiles/xampp security
XAMPP:  Quick security check...
XAMPP:  Your XAMPP pages are NOT secured by a password. 
XAMPP: Do you want to set a password? [ja] 
XAMPP: Password: 
XAMPP: Password (again): 
XAMPP:  Password protection active. Please use 'xampp' as user name!
XAMPP:  MySQL is accessable via network. 
XAMPP: Normaly [ja] 
XAMPP:  Turned off.
XAMPP: Stopping MySQL...ok.
XAMPP: Starting MySQL...ok.
XAMPP:  MySQL has to run before I can check the security.
XAMPP:  MySQL has to run before I can check the security.
XAMPP:  MySQL has a root passwort set. Fine! :)
XAMPP:  ProFTPD has a new FTP password. Great!
XAMPP: Do you want to change the password anyway? [nein] 
XAMPP:  Done.

"xampp"をユーザ名に使うのがデフォルト設定らしい。
これでlocalhostにアクセスするとBASIC認証のダイアログが出るようになる。

※XAMPP ControlからMySQL起動した時と、普通にターミナルから起動した時でデータベースが異なっている。
おそらくMAMPから起動するとまた別のデータベース群になると思われる。

OSX lionにperlbrewをインストール

http://blog.kiftwi.net/2011/08/02/os-x-lion%E3%81%ABperlbrew%E3%81%A8cpanm%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%97%E3%81%A6perl%E7%92%B0%E5%A2%83%E3%82%92%E6%95%B4%E3%81%88%E3%82%8B/

CPANが使えない件、バグかも。
http://www.gossamer-threads.com/lists/perl/porters/260169

/System/Library/Perl/5.12/Net/FTP/dataconn.pm
line 54. あたりを編集

sub _close 
{ 
my $data = shift; 
my $ftp = ${*$data}{'net_ftp_cmd'}; 

$data->SUPER::close(); 

return if !defined $ftp;   #Here is added code

delete ${*$ftp}{'net_ftp_dataconn'} 
if exists ${*$ftp}{'net_ftp_dataconn'} && 
$data == ${*$ftp}{'net_ftp_dataconn'}; 
} 

sub close 
{ 
my $data = shift; 
my $ftp = ${*$data}{'net_ftp_cmd'}; 

if(exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net_ftp_eof'}) { 
my $junk; 
$data->read($junk,1,0); 
return $data->abort unless ${*$data}{'net_ftp_eof'}; 
} 

$data->_close; 

return if !defined $ftp; #Here is added code

$ftp->response() == CMD_OK && 
$ftp->message =~ /unique file name:\s*(\S*)\s*\)/ && 
(${*$ftp}{'net_ftp_unique'} = $1); 
$ftp->status == CMD_OK; 
} 

bitbucketの登録とMercurialのインストール

http://d.hatena.ne.jp/paraches/20101228

Mercurialのインストール。

$ sudo easy_install Mercurial

gitに対応するコマンドはfg。

Gitと連動できる?みたい。
http://d.hatena.ne.jp/crosshope/20110510/git_bitbucket

GD::GraphのCPANからのインストールに向けて

できない。

# sudo perl -MCPAN -e shell
# install GD::Graph

すると、FTPが失敗する。
Can't use an undefined value as a symbol reference at /System/Library/Perl/5.12/Net/FTP/dataconn.pm line 54.
フォーラム読んでソースを修正してみたけど動かず。

仕方ないからCPANMに切り替えるも

[@ GD-2.46]$sudo cpanm libgd
! Finding libgd on cpanmetadb failed.
! Finding libgd on search.cpan.org failed.
! Finding libgd () on mirror http://search.cpan.org/CPAN failed.
! Couldn't find module or a distribution libgd ()
[@aoki-mba GD-2.46]$cpan GD::Graph
Going to read '/Users/shohei/.cpan/Metadata'
  Database was generated on Sun, 22 May 2011 13:37:59 GMT
Warning: You are not allowed to write into directory "/Users/shohei/.cpan/sources/authors".
    I'll continue, but if you encounter problems, they may be due
    to insufficient permissions.
Fetching with LWP:
ftp://ftp.u-aizu.ac.jp/pub/CPAN/authors/01mailrc.txt.gz
LWP failed with code[500] message[Can't use an undefined value as a symbol reference]
Fetching with Net::FTP:
ftp://ftp.u-aizu.ac.jp/pub/CPAN/authors/01mailrc.txt.gz
Can't use an undefined value as a symbol reference at /System/Library/Perl/5.12/Net/FTP/dataconn.pm line 54.

よく覚えてないけど

  • libgd-configが見つからない
  • libgd 2.0.28 or higherをダウンロードしろ

というエラーも出ている。

ソースからgdのインストールを試みる。
http://kempwire.com/tips/installing-gd-graphics-library-on-mac-os-x.html

などをインストールしておく。

肝心のgdは開発中止なのか知らないけどどこにもない。
bitbucketに上がってるのをcloneする(要Mercurialのインストール)
※ちなみにここ(http://www.dmxzone.com/go?6824)を参考にして、



http://www.boutell.com/gd/http/gd-2.0.28.tar.gz


って手打ちしたらソースが落ちてきた。とっていいのかは知らん。

んでGDのインストール。
できたっぽい。

そこで再度cpanmを試みるも、

[@ GD-2.46]$sudo cpanm GD::Graph
--> Working on GD::Graph
Fetching http://search.cpan.org/CPAN/authors/id/B/BW/BWARFIELD/GDGraph-1.44.tar.gz ... OK
Configuring GDGraph-1.44 ... OK
==> Found dependencies: GD::Text
--> Working on GD::Text
Fetching http://search.cpan.org/CPAN/authors/id/M/MV/MVERB/GDTextUtil-0.86.tar.gz ... OK
Configuring GDTextUtil-0.86 ... OK
Building and testing GDTextUtil-0.86 ... FAIL
! Installing GD::Text failed. See /Users/shohei/.cpanm/build.log for details.
! Bailing out the installation for GDGraph-1.44. Retry with --prompt or --force.

/Users//.cpanm/build.log ファイルの中身


Test Summary Report$
 90 -------------------$
 91 t/align.t (Wstat: 512 Tests: 0 Failed: 0)$
 92   Non-zero exit status: 2$
 93   Parse errors: Bad plan.  You planned 21 tests but ran 0.$
 94 t/text.t (Wstat: 512 Tests: 0 Failed: 0)$
 95   Non-zero exit status: 2$
 96   Parse errors: Bad plan.  You planned 20 tests but ran 0.$
 97 t/wrap.t (Wstat: 512 Tests: 0 Failed: 0)$
 98   Non-zero exit status: 2$
 99   Parse errors: Bad plan.  You planned 14 tests but ran 0.$
100 Files=3, Tests=0,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.17 cusr  0    .03 csys =  0.24 CPU)$
101 Result: FAIL$
102 Failed 3/3 test programs. 0/0 subtests failed.$
103 make: *** [test_dynamic] Error 2$
104 -> FAIL Installing GD::Text failed. See /Users/shohei/.cpanm/build.log f    or details.$
105 -> FAIL Bailing out the installation for GDGraph-1.44. Retry with --prom    pt or --force.$

まとめると、自分の環境では、
・cpanmを使う(CPANシェルがNet::FTPで引っかかる)
・GDは知らん

ということで。

CPANでインストールできない理由が判明。諸悪の根源FTP

FTPのパッシブモードにここ最近常にやられている。

# perl -MCPAN -e shell
# o conf init

最初にnoを入力する。
以下のftp_passiveまでデフォルト値でOK。

 <ftp_passive>
Shall we always set the FTP_PASSIVE environment variable when dealing
with ftp download (yes/no)? [yes] #FTPパッシブモードを使わない→Noにする!

CPAN.pm changes the current working directory often and needs to
determine its own current working directory. Per default it uses
Cwd::cwd but if this doesn't work on your system for some reason,
alternatives can be configured according to the following table:

    cwd         Cwd::cwd
    getcwd      Cwd::getcwd
    fastcwd     Cwd::fastcwd
    backtickcwd external command cad

FTP Passiveモードを使わないのでNoを入力したらうまくいった。