Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You haven't provided much detail...and no code that you have tried. You are much more likely to get more informative help if you post your code and let others see what you have tried. Search the perlmonks site. Its a great resource. (for example QandASection: regular expressions ) regardless... I'm assuming you have your data in some text file.

here's the data in a text file...

This is first sentence. This is second sentence.

You can try this for a start...

use strict; open (INP,"data.txt") || die "Cannot open data.txt\n"; while (my $line = <INP>) { if ($line=~/^This\b/i) { # first word This if ($line !~ /\bfirst\b/i) { # without word first if ($line =~ /\.$/) { # . at the end print $line; } } } }
I have written the comments next to the pattern match so you can see what's happening at each line. If you want to know what the symbols mean, its better to look at a table of regular expression symbols in perl. There is no other short cut. however, this is only one of ways you could do this. I'm sure people can come up with shorter, fancier and even easier ways to do this kind of pattern match. This why you need to post your code, and provide better problem descriptions... so people can suggest different things, and then you learn much more.

perliff

----------------------

-with perl on my side

"If you look at the code too long, the code also looks back at you"


In reply to Re: Reguar expression by perliff
in thread Reguar expression by selva

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found