Link to home
Start Free TrialLog in
Avatar of toomuchcoffeeman
toomuchcoffeeman

asked on

matching and discarding...

I have to take the input from a socket, which is an array of lines that look like so:

"Title" "blahblah" "the_first_field"
"Title2" "etcetc" "second_field"

Each element of the array is one line that looks like the above two examples.

With my code I am able to read it in just fine.

I need to take each field from theis array and fill a new array with ONLY the beginning part of each field, that is, the text in the quotes that corresponds to "Title" above, AND remove the quotes.  Discard the rest of each field.

So, after I would have a new array:

Title
Title2

Anyone have a clue?  All my attempts at finding the right regexp have failed, but I am kind of a PERL newbie.

Thanks for any help!
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toomuchcoffeeman
toomuchcoffeeman

ASKER

From this it looks as though you are looking for the literal word "Title" and "Title2", etc.

Also, your $v1 is already known in my script - I don't want to define it again.

For my purposes, the text inside the quotes could be anything.

"anyword" "anythingelse" "blahblah"
"anotherword" "and so on" "and so on"

I need to isolate the area where 'anyword' and 'anotherword' is , between the quotes, for each field, for any number of fields (although the number of elements for the array is already calculated and known - I would run this pattern match for every field using a foreach loop)

Thanks for your help though!
the above solution would work with anything.

i have just used the above strings as example.
you can replace them with any other compatible string and the output would be what you want.

i would suggest that you use as many samples values to test it as you want/can.

Rgds
Don't know what the name of the variable is that contains the line each time it is read, but substitute it for the $line below:

$line=~/\"([^"]*)\"/;
push @newarray, $1;

The $1 should contain the stripped down contents of the first field.  Then you just push it onto the @newarray.  Of course, you have a loop surrounding all of this.  Also, this won't work if you allow escaped "'s.

Hello maneshr.  syu1 needs you:)

Rob
OK.

The first answer was indeed correct.

Like I said, I'm a newbie. :)

I was about to post that I tried it and it did work, and I found the other solution as well.

It worked too.

I have to give the points to manseshr as he gave the first correct answer.

Thanks to BOTH of you for a couple of very quick and helpful answers!!