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:


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!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try this......

Let's say each line is stored in a variable (v1)


$v1="\"Title\" \"blahblah\" \"the_first_field\"";
print $one,"\n";

$v1="\"Title2\" \"etcetc\" \"second_field\"";
print $one,"\n";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
toomuchcoffeemanAuthor Commented:
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.

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:

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:)

toomuchcoffeemanAuthor Commented:

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!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.