in reply to Re: How to use split() in perl to ignore white space and ','
in thread How to use split() in perl to ignore white space and ','

Hi Athanasius, Thanks for a warm welcome, Can't we optimize it using regex memory ?
  • Comment on Re^2: How to use split() in perl to ignore white space and ','

Replies are listed 'Best First'.
Re^3: How to use split() in perl to ignore white space and ','
by soonix (Chancellor) on Feb 11, 2015 at 10:01 UTC
    Sure, if you can exactly tell what the regex should accomplish -
    1. split commas
    2. except commas between quotes
    3. except it's not between any quotes, but the quotes must be balanced
    4. perhaps the quotes are nested
    5. escaped quotes (\') have to be exempt
    6. the same conditions for double quotes
    7. them mixed and matched
    8. what about escaped commas (\,)?
    9. other special cases I forgot to think of?
    I do use split sometimes, but only if it's guaranteed to be commas only. As soon as a special case becomes visible on the horizon, I use Text::CSV (which in turn uses Text::CSV_XS if possible).
Re^3: How to use split() in perl to ignore white space and ','
by Not_a_Number (Prior) on Feb 11, 2015 at 09:43 UTC
    Can't we optimize it

    Please explain in what way you find the code sub-optimal.

    using regex memory

    I'm sorry, I don't understand. What it this 'regex memory' you speak of?

      I think the term 'using regex memory' which iamnewbie used means 'using capturing parentheses' in the regexp.

Re^3: How to use split() in perl to ignore white space and ','
by karlgoethebier (Abbot) on Feb 11, 2015 at 14:31 UTC
    "...Can't we optimize it using regex memory?"

    I'm not sure what you mean but i guess you perhaps mean something like this:

    my $string = "hello,'world, yo',matt"; my @result = $string =~ /(\.+),('.+'),(.+)/; print qq($_\n) for @result;

    See also Is guessing a good strategy for surviving in the IT business? and perlretut.

    But i'm sure that this is not really an optimization. I think, the some solutions given already are probably better.

    Edit: I tried to be more precise in judgement...

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»