1

我试过这个例子:

#!C:/Perl64/bin/perl.exe

$mickey = "Hi i'm Mickey";
$pluto = "Hi i'm Pluto";

print <<EOF;
$pluto
Hi i'm Goofy
$mickey
EOF

print <<'EOF';
$pluto
Hi i'm Goofy
$mickey
EOF

获得以下输出:

Hi i'm Pluto
Hi i'm Goofy
Hi i'm Mickey

$pluto
Hi i'm Goofy
$mickey

我想使用 whitout 获得相同的行为<< operator。所以我尝试了另一个:

#!C:/Perl64/bin/perl.exe

$mickey = "Hi i'm Mickey";
$pluto = "Hi i'm Pluto";

print STDOUT "$pluto
Hi i'm Goofy
$mickey";

实际打印:

Hi i'm Pluto
Hi i'm Goofy
Hi i'm Mickey

我怎样才能逃脱每个 perl 特殊字符?

我尝试使用print 'STDOUT' ...没有我想要的东西。


Access-Control-Allow-Origin 和 Angular.js

我一直在努力寻找解决方案,但到目前为止我没有找到任何工作。因此,我正在尝试对天气 API 进行带有角度的 HTTP 请求,但我不断收到以下响应:

Origin http://mydomain.com is not allowed by Access-Control-Allow-Origin. 

到目前为止我已经尝试过:

  1. 将此行添加到我的应用程序配置中

    删除 $httpProvider.defaults.headers.common['X-Requested-With'];

  2. 我已经尝试了多个版本的角度,都具有相同的结果

  3. 将此添加到我的 .htacces

    标头添加 Access-Control-Allow-Origin "*"

  4. 使用 PHP 添加标头

  5. 为 GET 请求尝试不同的 URL

    (甚至不同的API,相同的结果)

  6. 使用 jQuery HTTP 请求而不是 Angular 的,同样的结果......

我的代码

       $http({
          method: 'GET',
          url: 'https://api.forecast.io/forecast/myapikey/52.370216,4.895168'
        }).
        success(function(response) {
            console.log('succes');  
            console.log(response);
        }).
        error(function(response) {
            console.log('failed');  
            console.log(response);
        });

这些解决方案似乎都不起作用,我之前一直在使用 Angular,通常添加delete $httpProvider.defaults.headers.common['X-Requested-With'];可以解决问题

我完全迷失在这里,任何帮助表示赞赏,谢谢!

4

3 回答 3

3

如果您不希望发生插值,请使用单引号(或q/STRING/ 引号运算符)而不是双引号:

$mickey = "Hi I'm Mickey";
$pluto = "Hi I'm Pluto";

print STDOUT q{$pluto
Hi I'm Goofy
$mickey};

STDOUT这里也是多余的,这是默认的。print 'foo $bar';就足够了。

于 2013-10-19T17:28:14.837 回答
2
print <<"EOF";   # <<EOF is short for <<"EOF"
$pluto
Hi i'm Goofy
$mickey
EOF

print <<'EOF';
$pluto
Hi i'm Goofy
$mickey
EOF

is equivalent to

print
"$pluto
Hi i'm Goofy
$mickey
";

print
'$pluto
Hi i\'m Goofy
$mickey
';

Note the parallel between the quotes used.

Unfortunately, because the delimiter is present in the literal, you must escape it.

于 2013-10-19T17:32:37.560 回答
0

我怎样才能逃脱每个 perl 特殊字符?

使用“\”来做到这一点

my $var = "test";

print "\$var\n";
print "$var\n";

输出:

$var
test
于 2013-10-19T17:40:48.320 回答