Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

quotewords and qq{}/q{}

by greatdane (Beadle)
on Jan 27, 2007 at 04:31 UTC ( #596827=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://596827]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-12-04 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?