Hi Monks, I'm trying to extract data from a string and assign them to variables like so:
The result is this, though:use Modern::Perl; my $string = " define('DB_NAME', 'blah'); /** MySQL database username */ define('DB_USER', 'blahbah'); /** MySQL database password */ define('DB_PASSWORD', 'blahblahblah'); "; my ($db, $db_user, $db_pass); my $pre_regex = qr/^\s*define\s*\(\s*['"]/; my $post_regex = qr/['"]\s*,\s*['"]([^'"]+)['"]/; ($db, $db_user, $db_pass) = map { ($string =~ /$pre_regex $_ $post_regex/mix || 'unknown') } q +w(DB_NAME DB_USER DB_PASSWORD); say $db; say $db_user; say $db_pass;
1 unknown unknown
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to Assigning mapped regex to a list by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |