Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected leading spaces while using wc -l command

Tags:

unix

perl

wc

I am trying to execute the below command - but the output has some leading space introduced.

ls -lrt | wc -l
     29
echo $SHELL
/bin/bash

When I run the same command on a different machine,the output is as expected.

ls -lrt | wc -l
183
echo $SHELL
/bin/bash

The leading spaces is causing my perl validation to fail

unless ( $phCountRet->{COUNT} =~ /^\d+$/ ){
...
}

I can opt to trim the leading white spaces and then do the validation,but it wont be a clean solution.

Any pointer as to what might be causing this will be a great help.

like image 802
Soumya Avatar asked Oct 30 '22 20:10

Soumya


1 Answers

use

unless ( $phCountRet->{COUNT} =~ /^\s*\d+$/ ){

this matches also numbers with blanks in front.

like image 105
Jens Avatar answered Nov 15 '22 12:11

Jens