Professional Web Applications Themes

Matching repeated lines. - PERL Beginners

Sorry to post again on a new thread, but I think I need to clear my basci problem up. I want to read in a file and print repeated lines like: yum yum or xorg-x11 xorg-x11 What's the best way to do this? A RE or a module from CPAN? -- Just getting into the best language ever... Fancy a me.uk? Just ask!!!...

  1. #1

    Default Matching repeated lines.

    Sorry to post again on a new thread, but I think I need to clear my basci
    problem up.

    I want to read in a file and print repeated lines like:

    yum
    yum

    or

    xorg-x11
    xorg-x11


    What's the best way to do this? A RE or a module from CPAN?


    --
    Just getting into the best language ever...
    Fancy a me.uk? Just ask!!!
    Gavin Guest

  2. #2

    Default Re: Matching repeated lines.

    On Wed, Oct 06, 2004 at 01:42:43PM +0100, Gavin Henry wrote:
     

    uniq -d

    Or, if you aren't on a system where that is available, use the ppt
    version: http://ppt.perl.org/commands/uniq/index.html

    --
    Paul Johnson - net
    http://www.pjcj.net
    Paul Guest

  3. #3

    Default Re: Matching repeated lines.

    On Wed, 06 Oct 2004 13:42:43 +0100, Gavin Henry wrote:
     

    Are all your duplicates one after another? If so just store the previous
    line's package name and compare with the current line with a regex, e.g.:

    print if (/^$prev/);

    However, if your duplicates are spread around then you'll need to use hash
    to store all the package names and test to see if keys exist already as
    you go along.
    HTH
    Chris.
    Chris Guest

  4. #4

    Default Re: Matching repeated lines.

    Paul Johnson said: 
    >
    > uniq -d
    >
    > Or, if you aren't on a system where that is available, use the ppt
    > version: http://ppt.perl.org/commands/uniq/index.html[/ref]

    Quicker and easier I suppose, thanks.
     


    --
    Just getting into the best language ever...
    Fancy a me.uk? Just ask!!!
    Gavin Guest

Similar Threads

  1. Regular Expresssion - Matching over multiple lines
    By Andrew in forum PERL Beginners
    Replies: 4
    Last Post: May 18th, 04:34 PM
  2. Matching pattern in multiple lines
    By Prabu in forum PERL Beginners
    Replies: 3
    Last Post: April 7th, 02:19 PM
  3. Reg. 'repeated pattern' matching
    By Balaji in forum PERL Beginners
    Replies: 3
    Last Post: February 26th, 05:47 AM

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