Chris Schults wrote:
I'm sending this on behalf of our intern Elmer. Thanks in advance for any
assistance. Chris

Hi there!

If anyone out there is good with Perl's pattern matching, maybe you can help
me out.  I am trying to take a string and derive information from it that is
separated by commas so I can then analyze the individual values.

So if I have a string like: 'Associated Press, John. D. Reporter, 01 Apr
2005'

I want to be able to scan it, and extract 'Associated Press' 'John. D.
Reporter' and '01 Apr 2005' as distinct values--maybe store them as
variables so I can manipulate them.

It should also be that the number of data items not be relevant.  In case
the string is like 'Joe Freelancer, 01 May 2005'  or 'Reuters, 01 Jun 2005'.
Or if it has no commas and is just '01 Jul 2005'.

Kind regards,

Elmer Zahraie




Check out the 'split' function.

perldoc -f split

my @items = split /,/, $string;

Is the simplest, but you may need to take into account whitespace, etc. Also note that if you are parsing data that is coming in a true CSV format, aka with quoted values that might contain commas, etc. then you should consider using a module designed for this purpose, such as something in the Text::CSV range.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to