Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Matching a keyword, value and optional comma delimited values

by runrig (Abbot)
on Dec 22, 2000 at 21:24 UTC ( [id://48051]=note: print w/replies, xml ) Need Help??


in reply to Matching a keyword, value and optional comma delimited values

You could always take $3 and do something like:
my $opts = $3; $opts =~ s/\s*,\s*//g;
I think I'd rather do the whole thing in more than one step though, so if there were spaces IN the optional args you have more control over them, and the thing looks simpler:
#!/usr/local/bin/perl -l -w use strict; my $str="abc = def, ghi, jkl"; my ($req, $opts) = split /\s*,\s*/, $str, 2; $opts = '' unless defined $opts; my ($key, $value) = split /\s*=\s*/, $req; my @opts = split /\s*,\s*/, $opts; print qq(key="$key"); print qq(val="$value"); print join(",", map {qq("$_")} @opts);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-29 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found