Thursday, April 9, 2015

[Perl] Trimming leading & following whitespace characters, Skip a blank line

example

   open( LIST, $filename ) || die "Cannot open $!";
   while ( $phone = <LIST> ) {

      # trimming leading and following whitespace characters
      $phone =~ s/^\s+//;
      $phone =~ s/\s+$//;

      # skip a blank line
      if ( $phone eq '' ) {
         next;
      }
   }
   close( LIST );

No comments:

Post a Comment