Professional Web Applications Themes

Isolating a word with a certain pattern - PERL Beginners

Dear All I am trying to write a script to identify all words having a certain pattern in a text file. Is there in Perl a direct way of isolating a word with a certain pattern? Or has one to check all characters, bearing in mind that a word is a string delimited by two spaces? Thanks in advance, Paul...

  1. #1

    Default Isolating a word with a certain pattern

    Dear All

    I am trying to write a script to identify all words having a certain
    pattern in a text file. Is there in Perl a direct way of isolating a
    word with a certain pattern? Or has one to check all characters, bearing
    in mind that a word is a string delimited by two spaces?

    Thanks in advance,

    Paul

    Paul Guest

  2. #2

    Default Re: Isolating a word with a certain pattern

    Have a look at "\w"
    Refer:
    http://www.perldoc.com/perl5.8.4/pod/perlrequick.html

    Paul Smith wrote:
     

    Prasanna Guest

  3. #3

    Default Re: Isolating a word with a certain pattern

    Hi Paul,

    I'm not entirely sure of what you mean by "isolating" a word, but Perl
    programmers often use regular expressions to locate and manipulate
    words. You can look at 'perldoc perlre' for more info on regular
    expressions and 'perldoc perllocale' for information on making the
    regular expression's "words" more sensitive to non-US character sets.
    Maybe this script does more or less what you're looking for:

    #!/usr/bin/perl
    use strict;
    use warnings;

    while ( <DATA> ) {
    s!(\w*a+\w*)!<word>$1</word>!g; # words with 'a' in them
    print;
    }

    __DATA__
    I am trying to write a script to identify all words having a certain
    pattern in a text file. Is there in Perl a direct way of isolating a
    word with a certain pattern? Or has one to check all characters, bearing
    in mind that a word is a string delimited by two spaces?


    Output:
    I <word>am</word> trying to write <word>a</word> script to identify
    <word>all</word> words <word>having</word> <word>a</word>
    <word>certain</word> <word>pattern</word> in <word>a</word> text file.
    Is there in Perl <word>a</word> direct <word>way</word> of
    <word>isolating</word> <word>a</word> word with <word>a</word>
    <word>certain</word> <word>pattern</word>? Or <word>has</word> one to
    check <word>all</word> <word>characters</word>, <word>bearing</word> in
    mind <word>that</word> <word>a</word> word is <word>a</word> string
    delimited by two <word>spaces</word>?

    Best,

    Damon

    --
    Damon Allen Davison
    http://www.allolex.net

    Damon Guest

  4. #4

    Default Re: Isolating a word with a certain pattern

    Prasanna Kothari wrote: [/ref]

    I thank you and Damon for your very helpful replies to my question.

    Paul

    Paul Guest

Similar Threads

  1. Isolating a page element for print
    By npish in forum Macromedia Dynamic HTML
    Replies: 7
    Last Post: August 9th, 12:17 PM
  2. Replies: 42
    Last Post: May 31st, 06:26 PM
  3. A challenge? Help isolating links in a WebPage
    By Steve in forum PHP Development
    Replies: 9
    Last Post: October 28th, 04:26 PM
  4. Replies: 5
    Last Post: September 1st, 09:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139