Click to See Complete Forum and Search --> : perl regex problem


PsychoKow51
06-21-2005, 03:37 PM
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?

PsychoKow51
06-21-2005, 03:59 PM
nm. I simply used temp variables (fixed my "#"s)