-   Linux - Newbie (
-   -   blank space in perl (

zahheb 08-11-2012 04:22 AM

blank space in perl
if $line =~ /^\s*$/;

this is the code for avoiding blank lines.....can someone tel why do we have $..... i know its for matching \s means space ... and why dont we have if $line =~ m/^\s*$/;......
why match operator m is not present?


pan64 08-11-2012 07:16 AM

which $? $ is used to define scalar variables, so $line is a scalar variable, see here:
using regexp: ^ is the beginning of the line, $ is the end of the line, \s means white space, * means any number, so ^\s*$ means any number of white space chars between the beginning and end of the line, so the whole line can contain only white space chars.
^\s* would mean some white spaces at the beginning of the line... see here: or there:
why we do not need m? because the operator is =~, we do not need both. see:

All times are GMT -5. The time now is 04:35 PM.