[Cialug] Perl - find blank/white line

Claus cialug@cialug.org
Tue, 12 Apr 2005 10:26:04 -0500


I think the following will do what I want:

   if (!$line =~ /\S/)

This should return true only if $line consists of whitespaces, right?

Printable characters are probably the same as non-whitespaces which 
include the alphabet, numbers, punctuation marks, and symbols.  It 
doesn't include spaces, tabs, newlines.

Sample (of what I want):

$line       result
------------------
\n       -> false
\t \n    -> false
blah\n   -> true
   blah\n -> true
\tblah\n -> true

   Claus

On 4/12/2005 10:10 AM, Aaron Thompson wrote:
> What do you mean by 'without a printable character'? I assumed from your
> example that you were referring to white space.
> 
> If you looking for the first line that has white space:
> 
>   if($line =~ /\s+/)
> 
> If you are looking for the first line that starts with white space:
> 
>   if($line =~/^\s+/)
> 
> Good luck.
> 
> @
> 
> 
> On Tue, 2005-04-12 at 09:55 -0500, Claus wrote:
> 
>>Hello Perl gurus
>>
>>I'm having a program that reads lines and I want to find the first line 
>>without a printable character and I am having problems creating the 
>>correct condition.  So far I have:
>>
>>   if ($line le " ")
>>
>>But that treats a line starting with a tab as a blank line (aka the if 
>>is true) but unless the tab is not followed by a printable character I 
>>would like to tread it as a blank line.
>>
>>If it helps, the lowest ord. of a printable character is 33 (!).
>>
>>String functions prefered but regex is also accepted if need be.  Any 
>>help is appreciated.
>>   Claus
>>_______________________________________________
>>Cialug mailing list
>>Cialug@cialug.org
>>http://cialug.org/mailman/listinfo/cialug