经过几个链接后我才知道Perl进行编译并创建一个中间字节代码,然后解释该字节代码.我的问题是字节代码在哪里?
像java,c等其他语言一样,我们可以在编译后看到机器可执行目标代码.虽然Perl不会创建机器可执行代码,但应该存在一些临时存储字节代码的位置.
int a=b=c=10; //invalid statement
Run Code Online (Sandbox Code Playgroud)
但以下是有效的陈述
int a,b,c;
a=b=c=10;
Run Code Online (Sandbox Code Playgroud)
第一个是无效的,因为b在b得到它的值之前被分配到一个偶数.
但是第二种情况是有效的,因为相等(=)符号具有右关联,即"="符号将开始从右侧获得偏好.
我的问题是:为什么在第一种情况下不适用右关联?这是否意味着Associativity不适用于声明声明?我需要更加明确这一点.
我是Perl的新手,我面临以下问题,不知道为什么跟随不起作用.
我的Perl模块包含:
package PACK2;
use Exporter;
@ISA = ('Exporter');
@EXPORT_OK=('whom');
sub why(){
print "why\n";
}
sub whom(){
print "whom\n";
}
1;
Run Code Online (Sandbox Code Playgroud)
我的Perl文件包含:
#!/usr/bin/perl -w
use pack;
use pack2 ('whom');
PACK::who();
&whom();
Run Code Online (Sandbox Code Playgroud)
我运行这个程序,找不到whom:
perl use_pack_pm.pl
who
Undefined subroutine &main::whom called at use_pack_pm.pl line 7.
Run Code Online (Sandbox Code Playgroud) 在我的Perl代码中,我使用了以下行:
$host=$hostname if ($host eq undef);
Run Code Online (Sandbox Code Playgroud)
在输出中我得到以下消息:
Use of uninitialized value $host in string eq at cli.pl line 18.
Run Code Online (Sandbox Code Playgroud)
虽然我没有使用strict.如何避免在输出上打印此消息?
我是php世界的新手.我写了以下内容:
<html>
<head>
<title>It joins simple1 and prac1 program together</title>
</head>
<body>
<?php
if($_POST['user'])
{
print "hello,";
print $_POST['user'];
}
else{
print <<<_HTML_
<form method="post" action="$_server[PHP_SELF]">
Your name:<input type="text" name="user">
</br>
<input type="submit" value="hello">
</form>
_HTML_;
}
?>
</body>
</html> ---- line 23
Run Code Online (Sandbox Code Playgroud)
获取错误消息:
Parse error: syntax error, unexpected $end in C:\wamp\www\php_practice\simple2.php on line 23
Run Code Online (Sandbox Code Playgroud)
我删除了所有的html标签,只保留了它的php标签:
<?php
// Print a greeting if the form was submitted
if ($_POST['user']) {
print "Hello, ";
// Print what was submitted in the form …Run Code Online (Sandbox Code Playgroud) 当我运行ls命令时运行正常.但是echo $PATH没有给我任何来自perl的输出.当我echo从shell提示符运行它给我输出.你能解释一下这种行为吗?
#!usr/bin/perl
$\="\n";
$out = `ls`;
print $out;
$out=`echo $PATH`;
print $out;
Run Code Online (Sandbox Code Playgroud)