|We don't bite newbies here... much|
Non-regex Methods of Extracting the Last Field from a Recordby ozboomer (Monk)
|on May 07, 2009 at 23:55 UTC||Need Help??|
ozboomer has asked for the
wisdom of the Perl Monks concerning the following question:
I have a text data record that comprises a variable number of 'fields'... and I would like to extract the last field from the record.
Now, I realize I could probably use a (fancy) regex... and I understand they are (often) efficient and so on... but, like a lot of people, I get intimidated by regex... so I was looking for a simpler, array-manipulation method of extracting the last item from a variable length array.
Some example code:
There are a number of solutions there that I've worked-out... so I've more-or-less come up with a suitable solution... but I guess the primary question is why doesn't the following construct work:
(@junk, $ads) = (split(/\s+/, $rec));
I've looked through the perlfaq, the Camel and Ram books... and have searched through the HallowedHalls(tm) here but couldn't find anything specific..
Would appreciate any thoughts...