0

perl的标准输入STDIN


perl的标准输入stdin

  1. #!/usr/bin/perl
  2. print "wait stdin:";
  3. $sr = <STDIN>;
  4. if ( $sr eq "\n" ){
  5.    print "just a blank line \n"
  6. }else{
  7.    print "the data of input is $sr"
  8. }

相比shell比较奇怪的是输入为空,perl的判断却是”\n” 换行符!

  1. #!/bin/bash
  2. read a
  3. if [ -z $a ];then
  4. echo "blank line!"
  5.  else
  6.  echo a
  7. fi

我猜~这些文章你可能也感兴趣

暂时没有留言..

给我留言:

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word