Monday, February 17, 2014

Format is Showing Incorrect for Perl Scripting

www.unixbabuforum.inI am using a perl script file, which has following format 

while(<>) 

if ($_ =~ /*.*/){ 

print "I am in enable part"; 
exit; 

else{ 
print "I am in disable part"; 








here I am providing one file as file.txt as an input, which have *.* pattern at the beginning. 

But after execution, could see the following error 
Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE .*/ at file.txt line 3. 


www.unixbabuforum.inThe error message says that there is nothing in front of the [q]uantifier - the first '*'. 
Regular Expression is powerful and fun, but need time to learn it. 

For you problem the right expression should be: /^\*\.\*/. But the better way is t substring. 

if (substr($_,0,3) eq '*.*') 

perl -le 'if (substr("*.*,adfa",0,3) eq "*.*") {print "got it"}' 
got it

0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM