Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

quotewords doesn't return a list

by zemplen (Novice)
on Oct 10, 2003 at 18:14 UTC ( #298362=perlquestion: print w/replies, xml ) Need Help??
zemplen has asked for the wisdom of the Perl Monks concerning the following question:

I am having problems with quotewords. Using an editor create a file entering the following text and seperating the fields with a tab character.
1 2 3 4 foo bar 7 8 9 ' "
Why doesn't quotewords break out the list?
use Text::ParseWords; open (MASTER, "<master.txt"); $delim = "\t"; $master = <MASTER>; chomp $master; @list = &quotewords(${delim}, 1, ${master}); close (MASTER);

Replies are listed 'Best First'.
Re: quotewords doesn't return a list
by Enlil (Parson) on Oct 10, 2003 at 18:57 UTC
    The quotes are what is messing it up and causing the unexpected behaviour. Since it doesn't find a matching closing quote it fails to match, and returns nothing. I am assuming that the advantage over this module over just using split is that you can tokenise something like
    foo\tbar foo bar bar\t\tbar
    instead of just splitting at every \t (in this case).


Re: quotewords doesn't return a list
by snax (Friar) on Oct 10, 2003 at 18:41 UTC
    It does here. Update: No, it doesn't. My mistake; I completely missed seeing the single and double quotes at the end of the input data (props to Enlil). Sorry :(


  • Check to see if you are opening the file properly: use the or die "Useful message here: $?" idiom
  • Your chunk above doesn't print anything or do anything with @list -- is it just a case of not really looking at your variables?
      Adding a print statment or using the debugger shows that @list is empty.
      If I add $master = "1    2    3    4    foo  bar    7    8    9"; to the program then it returns a list as expected. The problem appears to be tied to getting the data from a file.
      I am running Activestate perl, v5.8.0 built for MSWin32-x86-multi-thread
        How odd. Using a file (master.txt as you suggest) and the offered input data (tab separated)
        1 2 3 4 foo bar 7 8 9
        I have no problems: I get a list as expected. However, after adding a single and double quote
        1 2 3 4 foo bar 7 8 9 ' "
        things behave as you describe: an empty list results. As such I concluded that Enlil got it right, and there's a bug/behavior problem associated with unmatched quotes in the Text::ParseWords module.

        I'm testing this with 5.8.0 (Cygwin) and 5.6.1 (Activestate).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://298362]
Approved by krisahoch
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2016-10-26 14:14 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (341 votes). Check out past polls.