http://qs321.pair.com?node_id=596827

greatdane has asked for the wisdom of the Perl Monks concerning the following question:

Dear PerlGods, Any idea how I can get quotewords of Text::ParseWords to split inputs quoted with qq{} or q{}. Users of my program want/need to give me input with qq{} instead of standard quotes because long_story.
use Text::ParseWords; @list = &quotewords ('\s+', 0, $input); foreach $item (@list) { <whatever>; }

Replies are listed 'Best First'.
Re: quotewords and qq{}/q{}
by Zaxo (Archbishop) on Jan 27, 2007 at 07:50 UTC

    Is your user input coming at you as a perl expression to be evaled, or does q{} or qq{} get evaluated in the user's process before you see it?

    In the second case, there is no difference between qq{} and "" or q{} and ''.

    In the first, you're trusting your users more than you ought to.

    After Compline,
    Zaxo

      Is your user input coming at you as a perl expression to be evaled, or does q{} or qq{} get evaluated in the user's process before you see it?

      The way I read his post, neither. It looks to me like users are supplying data that he wants to parse, but they want to supply it with Perl-style quoting constructs, probably for the obvious reason that Perl-style quoting constructs eliminate most of the worst problems with escaping quote characters in short bits of quoted text.

      OTOH, if we knew more about long_story, it is possible that there is another, possibly even a better, solution.

      -- 
      We're working on a six-year set of freely redistributable Vacation Bible School materials.
        Thanks for all the feedback. You are all correct. My users are inputting a string to be split like a shell. Yet, there is a complication since the user's input would also like CPP pre-processing which will not modify things within quotes. For this reason, I would like to provide the users a method for quoting without quotes (e.g. qq{} or q{}). These operators would allow CPP to perform substitutions which is great. Yet, afterwards, I would continue to want to "parse" the input string like a shell using something like "quotewords".
Re: quotewords and qq{}/q{}
by Anonymous Monk on Jan 27, 2007 at 07:28 UTC
    Re-invent Text::ParseWords using Text::Balanced