LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   blank space in perl (https://www.linuxquestions.org/questions/linux-newbie-8/blank-space-in-perl-4175421543/)

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?


thanks

pan64 08-11-2012 07:16 AM

which $? $ is used to define scalar variables, so $line is a scalar variable, see here: http://www.comp.leeds.ac.uk/Perl/scalars.html
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: http://perldoc.perl.org/perlretut.html or there: http://perldoc.perl.org/perlre.html
why we do not need m? because the operator is =~, we do not need both. see: http://perldoc.perl.org/perlop.html#Binding-Operators


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