Ole Tange
Ole Tange

Reputation: 33685

Perl: Parse string as shell

I would like to dequote and split a string the same way Bash does (excluding ` and $). Given the string:

'"'"'\""'"'  foo\ bar\"   '\" '\ quux

I would like an array containing:

@a = (q("'""), 'foo bar"', '\"  quux');

Upvotes: 0

Views: 288

Answers (1)

ernix
ernix

Reputation: 3643

use Text::ParseWords ();
my @list = Text::ParseWords::shellwords($string);

Upvotes: 4

Related Questions