perl/コンテキスト〜リストコンテキスト評価をスカラーコンテキスト評価にしたい〜
方法は3つです。
#! usr/bin/perl use strict; use warnings; #リストコンテキストで評価されるものをスカラーコンテキストで評価するようにしたいときはどーするの? print localtime();#出力結果=>48161519710932300=>printはリストコンテキストで評価するから。 print "\n"; print "--------------------------------\n"; #強制的にスカラーコンテキストにする方法 #(1)関数scalarを使用する print scalar(localtime()); print "\n\n"; #(2)スカラー変数に代入する my $sca_localtime=localtime(); print $sca_localtime; print "\n\n"; #(3)文字列連結演算子「.」を利用する print localtime()."\n";