Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

I wanna customize qw()

by nickcave25 (Acolyte)
on Feb 18, 2000 at 21:15 UTC ( [id://3689]=perlquestion: print w/replies, xml ) Need Help??

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

Does anyone know if it is possible to specify what qw() uses as a delimiter? By default it uses, like, whitespace (it wraps quotes around words (or something like that.)) If not, is there a similar function that works like qw() but uses some other (hopefully customizable) delimiter? Thanks in advance!

Hail Larry!

Replies are listed 'Best First'.
Re: I wanna customize qw()
by btrott (Parson) on Feb 18, 2000 at 23:13 UTC
    I don't think there is such an operator, no. (Could be wrong, though.) But according to perlop, qw is "exactly equivalent to
    split(' ', q/STRING/);
    ". So couldn't you just use split? Say you wanted to split on commas instead of whitespace:
    my @words = split /,/, q/foo,bar,baz/;
Re: I wanna customize qw()
by nickcave25 (Acolyte) on Feb 19, 2000 at 00:34 UTC
    btrott:

    That is exactly what I needed to know. I am doing some R&D on the simplest (yet most flexible) way to access a library of custom-made functions that return HTML tags wrapped around the fed-in arguments.

    I was settling for issuing a print statement for each and every returned value (I had also tried just printing within the subroutine itself, but the print-the-returned-value-outside-of-the-subroutine route seemed the more flexible way to go in the long run).

    Then I hit upon the idea of packing each separate command into an array (but only if I could do it without having to wrap every line in quotes) and then printing out the array elements one by one. Assigning the array using qw() seemed like it would work early on but it ran out of steam when it came to making function calls with an argument that consisted of more than one word. Quotes seemed to cause problems too, as would be expected.

    But I just swapped out the qw() call for the split() version that you recomended and it seems to be working... at least in my test case so far.

    The big question I am facing is how deep I can nest function calls (function calls within function calls for example) because I am running each segment of the array through eval() before printing it out in order to get the subroutines processed. I suspect that either eval() will process all of my subroutine calls (even those embeded within other calls) or will only go one level deep. I can't wait to find out which it is.

    Thanks again for your advice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-16 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found