我怎样才能获得脚本的名称?
例如,我有一个名为Perl的脚本XXX.pl.该文件包含:
$name = #some function that obtains the script's own name
print $name;
Run Code Online (Sandbox Code Playgroud)
输出:
XXX.pl
Run Code Online (Sandbox Code Playgroud)
我想将其比作获取脚本目录的CWD函数.我需要一个获取脚本名称的函数.
@array = qw(one two three four five six seven eight);
<Some command here>
print @array;
Run Code Online (Sandbox Code Playgroud) 需要帮助搞清楚如何做到这一点.我的代码:
my %hash;
$hash{'1'}= {'Make' => 'Toyota','Color' => 'Red',};
$hash{'2'}= {'Make' => 'Ford','Color' => 'Blue',};
$hash{'3'}= {'Make' => 'Honda','Color' => 'Yellow',};
&printInfo(%hash);
sub printInfo{
my (%hash) = %_;
foreach my $key (keys %_{
my $a = $_{$key}{'Make'};
my $b = $_{$key}{'Color'};
print "$a $b\n";
}
}
Run Code Online (Sandbox Code Playgroud) 这是代码......
use strict;
use warnings;
my @array= (1,2,3,4,5);
my $scalar= 5;
@array= $scalar*@array;
print @array;
Run Code Online (Sandbox Code Playgroud)
需要能够用很少的代码执行类似功能的东西.谢谢!
我试图解析一个json对象并遇到问题.
import json
record= '{"shirt":{"red":{"quanitity":100},"blue":{"quantity":10}},"pants":{"black":{"quantity":50}}}'
inventory = json.loads(record)
#HELP NEEDED HERE
for item in inventory:
print item
Run Code Online (Sandbox Code Playgroud)
我可以弄清楚如何获得这些值.我可以得到钥匙.请帮忙.
每次我对python脚本进行更改时,都必须重新加载python并重新导入模块.请告诉我如何修改我的脚本然后运行,而无需在终端重新启动python.
谢谢.
我的代码......
$option = "[1]";
if ($option =~ m/^\[\d\]$/) {print "Activated!"; $str=$1;}
Run Code Online (Sandbox Code Playgroud)
我需要一种方法从$ option中删除方括号.$ str = $ 1由于某种原因不起作用.请指教.
我有这个代码
use strict;
use warnings;
my %hash;
$hash{'1'}= {'Make' => 'Toyota','Color' => 'Red',};
$hash{'2'}= {'Make' => 'Ford','Color' => 'Blue',};
$hash{'3'}= {'Make' => 'Honda','Color' => 'Yellow',};
foreach my $key (keys %hash){
my $a = $hash{$key}{'Make'};
my $b = $hash{$key}{'Color'};
print "$a $b\n";
}
Run Code Online (Sandbox Code Playgroud)
这个出来了:
丰田红色本田黄色福特蓝色
需要帮助按Make排序.
我无法弄清楚为什么以下代码不起作用. JSFIDDLE LINK
$(document).ready(function () {
addInput();
});
var limit = 30;
function addInput() {
var numberOfRows = $("#shipping tr").size();
var id = numberOfRows;
if (numberOfRows == limit) {
alert("You have reached the limit of adding " + limit + " inputs");
} else {
$('#shipping').append('<tr id="rate' + id + '"></tr>');
$('tr#rate' + id).append('<td></td>');
$('tr#rate' + id).append('<td><input type="text" name="rate" /></td>');
}
$('input[name=rate]').on('keyup', 'input', function () {
alert('YAY');
return false;
});
}
Run Code Online (Sandbox Code Playgroud)
我试图将keyup函数分配给我动态添加的输入.
预期产量:YAY!在弹出框内
请帮忙!
需要一个正则表达式或其他方法将UNIX路径转换为DOS路径.
我有
C:/My Document/Photo.gif
Run Code Online (Sandbox Code Playgroud)
需要
C:\My Document\Photo.gif
Run Code Online (Sandbox Code Playgroud)