1 / 5

ファイルの読み込み

ファイルの読み込み. #!/usr/bin/env perl #Perl スクリプトの指定 open(FILE, "food.txt"); # ファイル処理の開始 # ファイル名は、” food.txt” # ファイルハンドルは FILE while(<FILE>){ # 一行ずつ、最後まで読む print $_; # 読み込んだ一行を出力する } close FILE; # ファイル処理の終了. 変数について. $val = 150; print $val; $name = “Watson”; print $name;. If 文.

lotus
Download Presentation

ファイルの読み込み

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ファイルの読み込み #!/usr/bin/env perl #Perlスクリプトの指定 open(FILE, "food.txt"); # ファイル処理の開始 # ファイル名は、”food.txt” # ファイルハンドルはFILE while(<FILE>){ # 一行ずつ、最後まで読む print $_; # 読み込んだ一行を出力する } close FILE; # ファイル処理の終了

  2. 変数について $val = 150; print $val; $name = “Watson”; print $name;

  3. If文 #!/usr/bin/perl open(FILE, “food.txt”); while(<FILE>){ if(length($_) > 10){ print $_;} } close FILE; if(条件){ 条件にあったときの処理 } elsif(2番目の条件){ 条件にあったときの処理 } else { どの条件にも合わなかったときの処理 }

  4. while文 #!/usr/bin/perl $num = 0; while($num <= 5 ){ print “$num “; $num ++; # $numの値を1つ増やす }

  5. for文 #!/usr/bin/perl for($num = 0;$num <= 5;$num ++){ print “$num “; }

More Related