Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

REGEX malfunction

by rayken (Initiate)
on Jul 13, 2009 at 07:24 UTC ( #779485=perlquestion: print w/replies, xml ) Need Help??

rayken has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: REGEX malfunction
by si_lence (Deacon) on Jul 13, 2009 at 09:13 UTC
    I agree with jethro: code tags would help.

    One thing I do not understand is that it looks as if you are looping through the file, but match against a constant $string.

    Also you should be using

    use strict; use warnings;
    in your code, especially if you're just starting with perl. They do help a lot.

    In your code there is one thing (if I read it right): Your variable $string starts with an opening parenthesis, but you anchor your match to start without it.
    You also have additional blanks around your \s+ matches. You would require 3 blanks to match: one literal one, then one from \s+ and then another literal one. In your string you only have one.

    So either change (added quotes around the $string assignment, updated m//) code to

    # string to be searched my $string = '(FT CDS complement(join(18028..18116,19351..20668)))'; #search for the first line highlighted in bold if ($string =~ m/^\(FT\s+CDS\s+complement\(join\([0-9.,]+\)\)\)$/) { print 'match' } else { print 'no match' }
    or get rid of the outermost pair of parenthesis.

    cheers, si_lence

Re: REGEX malfunction
by jethro (Monsignor) on Jul 13, 2009 at 08:42 UTC
    Please edit your node and use <code> tags around your example text file. As you can see your node is unreadable at the moment
Re: REGEX malfunction
by graff (Chancellor) on Jul 13, 2009 at 22:18 UTC
    You said:
    My wish is to able to search for the lines that are in bold and print them out.

    How would you know whether a given line is "in bold"? There doesn't seem to be anything in the sample data that would convey this sort of information.

    The only other occurrence of "bold" in the OP is a comment line next to an "if" condition, which is looking for an html anchor tag in the data. Is there something about html anchor tags that makes you think of a line being "in bold"?

    ... am still a perl newbie.

    That hardly begins to describe your current condition. The current OP turns out to be exactly equivalent in every way to your three previous attempts to get help at PerlMonks, leading us to conclude that there's a bigger problem than just being a newbie.

    For whatever reason(s), you are not learning anything -- you don't show any evidence of having read any book, tutorial, or manual about programming in perl, or any of the references that you've been given repeatedly about how to post questions effectively at PerlMonks. You haven't responded to any of the advice you've been given in your previous threads.

    Have you been able to figure out that your code as posted in this thread does not compile? Do you know what that means? How about if you try to run the code, read the error messages that you get, and try to fix the problems in the code that the error messages are reporting?

    If you don't know how to do that, and you want us to help you with that, you would have to:

    1. Post the exact code that you tried to run (using <code> tags)
    2. Post the exact error messages that you are unable to fix by yourself (again, using <code> tags)

    That would be a good start. It would indicate a tremendous amount of progress for you, relative to what you have been able to show us so far.

Re: REGEX malfunction
by davorg (Chancellor) on Jul 15, 2009 at 14:00 UTC

    Before you posted that node you were forced to preview it. When you previewed it you would have seen some text that said:

    If something looked unlike you expected it to you might need to check out Writeup Formatting Tips

    But you didn't check out Writeup Formatting Tips, did you? You were apparently really happy with the way that your node looked and you just went ahead and published it.

    As I've said to you before, if you can't be bothered to make it as easy as possible for us to help you, then why should we be bothered to offer any assistance. You need to put <code> tags around any code in your nodes. This is all explained in Writeup Formatting Tips. Why can't you do that?

    Oh, and my username is davorg, not "Daveorg". Attention to detail is a useful trait in a programmer.

    --

    See the Copyright notice on my home node.

    Perl training courses

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://779485]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2022-06-30 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (97 votes). Check out past polls.

    Notices?