给出以下代码:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my $text = do { local $/ ; <DATA> };
#filter text for 'description' text:
my @matches = $text =~ m{m_description=\"([^\"]+)\"}gms;
print Dumper \@matches;
#Generate a search-and-replace hash
my %replace = map { $_ => s/[\r\n]+/ /gr } @matches;
print Dumper \%replace;
#turn the keys of that hash into a search regex
my $search = join ( "|", keys %replace );
$search = qr/\"($search)\"/ms;
print "Using search regex: $search\n";
#search and replace text block
$text =~ s/m_description=$search/m_description="$replace{$1}"/mgs;
print "New text:\n";
print $text;
__DATA__
preceding lines
stuff m_description="Over
any number
of lines" other stuff
more lines
我有一个显示不同框的循环。像真菌,没有洋葱等 每个盒子在这个例子中都有一个类别比萨饼和烤肉串,如下图所示。
如果最后一个元素已从此类别加载,我的目标是添加一个条形码。然后它应该将类别栏添加到DOM。因此,当密钥(披萨,烤肉串)发生变化时,我想在DOM中添加一个元素。
我如何存档?
任何帮助非常感谢。
答案 0 :(得分:0)
从第一个循环中删除var
var values = {pizza: true, box: true, kebab: false};
var key;
for (key in values) {
console.log(key);
}
答案 1 :(得分:0)
$.each(values, function(key, val) {
if (val === true) {
$.getJSON("js/" + key + "/" + key + ".json", function(data) {
$("#whatToOrder2").append("<div class='box3'>" + key + "</div>");
$.each(data, function(key, val) {
$("#whatToOrder2").append("<div class='box'>" + val.name.toUpperCase() + "<input type='number' min='0' max='18' step='1' value='0' name=" + val.name.replace(/\s/g, '') + " class='css-input2 input-form2' placeholder='Menge'>");
});
})
}
})