CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Follow up to my earlier post Trying to match Crystal-Cont : ++++_+++ | 0.9000

 



vishy64
New User

May 11, 2006, 7:09 AM

Post #1 of 3 (2640 views)
Follow up to my earlier post Trying to match Crystal-Cont : ++++_+++ | 0.9000 Can't Post

 Hi
As an addendum to my doubt posted earlier, (which I have provided below once again), I am initially checking whether the line begins with "//" as such lines are to be ignored.
I am doing that with ($_ !~m/\/\//) BEFORE calling the split on the line.

The delimiter between the field-name and the value is the ":"

Hence I am trying to do
my ($field, $value) = split($_, ":");

I want $field = Crystal-Cont and $value = '+++++_+++++ | 0.9000'.

However when I run my script it throws the following error
" Nested quantifiers in regex; marked by <-- HERE in m/ Cryst-Cont : ++ <-- HERE ++_+++++| 0.9000
/ at pdbfinder_xml.pl line 18 (#2)
(F) You can't quantify a quantifier without intervening parentheses. So things like ** or +* or ?* are illegal. The <-- HERE shows in the regular expression about where the problem was discovered.

Note that the minimal matching quantifiers, *?, +?, and
?? appear to be nested quantifiers, but aren't. See perlre "


Please advise me regarding the best way to eliminate this error.
Note that I cannot do a substitution or modify the $_ in any way.

Thanks


rork
User

May 12, 2006, 1:22 AM

Post #2 of 3 (2638 views)
Re: [vishy64] Follow up to my earlier post Trying to match Crystal-Cont : ++++_+++ | 0.9000 [In reply to] Can't Post

Davorg posted a perfect answer to the original question.

Your regexp matches if the text contains // at any place, to match at the beginning of the string only use ^


Code
if ($_ !~ m/^\/\//) { split ... };


Regexps don't have to use m/foo/ but can also use other characters which make it easier to read:


Code
if ($_ !~ m|^//|) { split ...};


You're matching $_ which is taken by default and you may use unless instead of if and !

Code
unless (m|^//|) { split ... };


I guess you're using this in a while loop reading from a filehandle so it would also be possible to use

Code
while (<FOO>) { 
next if m|^//|;
# do stuff with $_ if it isn't a comment;
}


see perlreref for more info about regular expressions.
--
Don't reinvent the wheel, use it, abuse it or hack it.


KevinR
Veteran


May 12, 2006, 11:54 AM

Post #3 of 3 (2635 views)
Re: [vishy64] Follow up to my earlier post Trying to match Crystal-Cont : ++++_+++ | 0.9000 [In reply to] Can't Post

try reading what people post:


Code
my ($field, $value) = split($_, ":");


dave told you in your first thread that your split function is not coded correctly, nothing you do will work if you code your split function in reverse. Fix that then read what rork posted.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives