1行づつ読み込むPerl

雛形
1行づつ読み込んでは出力する。

while ( $line = <> ){

print $line;


}




行区切りを無効にする。字下げのある改行だけを本当の改行として認識してそれ以外の改行は無視する


undef $/;

while ( $line = <> ){


$line =~ s/\n /xxxxxx/g;
$line =~ s/\n //g;
$line =~ s/xxxxxx/\n/g;

print $line;


}





パスワードを解析する
あらかじめパスワードとして使用していそうな単語をファイルに1行に一つづつ書き込んでおき、そのファイルを読み込ませる。/etc/password などで暗号化されたパスワードをTargetpassword として入力してやる。


print "Enter target Paasword:";
$target=;
chop($target);
$key=substr($target,0,2);
while(<>){

chop;
$pass= crypt($_,$key);
if($target eq $pass){
print "\nHit! $target is $_\n";
last;
}
print ".";
}





CSVファイルの二つ目と一つ目のフィールドを出力するPerlスクリプト

while(<>){
    chop;
@a = split(/,/);
print "$a[1],$a[0]\n";
}



http://www.geocities.jp/cofe_fd3/perl.htm



標準入力から1行ずつ読み込んで、grep(若しくはsort)した後に出力する。


$count = 0;

while( $line = <> ){

$all[$count] = $line;

$count = $count +1 ;
}

# @result = sort @all;
@result = grep /610/, @all;


for( $i = 0; $i < $#result + 1 ; $i = $i + 1) {
print $result[$i];
}


                                                                                                • -

http://www.geocities.jp/cofe_fd3/perl.htm