perl regex problem

Sharky Forums


Results 1 to 2 of 2

Thread: perl regex problem

  1. #1
    Goldfish
    Join Date
    May 2002
    Posts
    59

    perl regex problem

    All,

    I am trying to take this input:

    /first/second/third/fourth
    "tk2020"
    "tk2020pl"

    and obtain this output (order doesn't matter)
    first
    second
    third
    tk2020
    tk2020pl


    code i am using (@ references is used to eliminate duplicate string matches as I work through the file):
    %references = ();


    while (<IN_FILE>)
    {
    # find references between two / marks
    while (m{/([a-z0-9/-]+)/}gi)
    {
    @substrings = split('/',$1);
    foreach $element (@substrings)
    {
    if (length ($element) >0 ){
    $references{$element} = 0;}
    }
    }

    if (m/"(.*####.*)"/i)
    {
    $references{$1} = 0;
    }


    }

    then i print the hash keys to OUT_FILE, etc.

    what I get is:
    first
    third
    second


    I believe this has to do with g option on the first match expression. How can I tell it to start looking at the beginning of the line for the next match i want to perform?

  2. #2
    Goldfish
    Join Date
    May 2002
    Posts
    59
    nm. I simply used temp variables (fixed my "#"s)

Posting Permissions

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