好吧,我想我把事情变得过于复杂了,现在我迷路了。基本上,我需要将其从 Perl 翻译为 Lua:
my $mem;
my $memfree;
open(FILE, 'proc/meminfo');
while (<FILE>)
{
if (m/MemTotal/)
{
$mem = $_;
$mem =~ s/.*:(.*)/$1/;
}
}
close(FILE);
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经写了这个:
for Line in io.lines("/proc/meminfo") do
if Line:find("MemTotal") then
Mem = Line
Mem = string.gsub(Mem, ".*", ".*", 1)
end
end
Run Code Online (Sandbox Code Playgroud)
但这显然是错误的。我没有得到什么?我明白为什么它是错误的,它实际上在做什么,以及为什么我这样做
print(Mem)
Run Code Online (Sandbox Code Playgroud)
它返回
.*
Run Code Online (Sandbox Code Playgroud)
但我不明白什么是正确的方法。正则表达式让我困惑!
我有一个像这样的字符串:
mystring = "test1, 1, anotherstring, 5, yetanother, 400";
Run Code Online (Sandbox Code Playgroud)
myarray可以有不同的长度.我想做的是像这样拆分字符串:
{"test1, 1"}
{"anotherstring, 5}
{"yetanother, 400"}
Run Code Online (Sandbox Code Playgroud)
这可能吗?我尝试了,string[] newArray = mystring.Split(',')但是在每个逗号分开它,而不是我想做的第二个逗号.
谢谢你的帮助
跳越
我的目的是取两个字符串并比较结果,如果它们都以"ing","ed"结尾或者结尾不匹配.它总是说字符串不匹配.
#include <stdio.h>
#include <conio.h>
#include <string.h>
int ised(char str[]);
int ising(char str[]);
int main()
{
char str1[30],str2[30];
printf("Enter 1st string:\n");
gets(str1);
printf("Enter 2nd string:\n");
gets(str2);
if((ising(str1))||(ised(str1))||(ising(str2))||(ised(str2)))
{
if(ising(str1)&&ising(str2))
{
printf("Both strings end with ing");
}
else if(ised(str1)&&ised(str2))
{
printf("Both strings end with ed");
}
else
printf("Both strings ending do not match");
}
else
printf("One or both strings do not end with ing or ed.Program Quitting...");
getch();
return 0;
}
int ising(char str[])
{
int len,flag=0;
len=strlen(str);
if (!(strncpy(&str[len-3],"ing",3)))
flag=1; …Run Code Online (Sandbox Code Playgroud) 我希望使用用户键入的字符串生成密码,我正在阅读的书推荐使用sha,md5因为它被认为更强.
sha但是已被弃用,我现在正在使用该hashlib模块以类似于此处所示的方式加密我的字符串:http://docs.python.org/py3k/library/hashlib.html#module-hashlib.
import os
import hashlib
from getpass import getpass
print('Username: ' + os.environ['USER'])
passwd = getpass('Password: ')
h = hashlib.md5()
h.update(passwd.encode())
passwd_encrypt = h.hexdigest()
Run Code Online (Sandbox Code Playgroud)
然后passwd_encrypt,我将与包含用户名和加密密码列表的普通ascii文件进行比较,如下所示:
THO 5f4dcc3b5aa765d61d8327deb882cf99
Run Code Online (Sandbox Code Playgroud)
这是一种加密密码的合适技术还是有更好的方法?我也对以这种方式存储密码是否合适以及可能的替代方案感兴趣.
谢谢
我正在使用WAMP,我的页面的根文件夹是: http://localhost/projects/bp/
在Worpress应用程序中,我想给body每个页面的标签赋予唯一的ID .所以我做了以下事情:
<?php
$page = $_SERVER['REQUEST_URI'];
$page = str_replace("/","",$page);
$page = str_replace(".php","",$page);
$page = str_replace("?s=","",$page);
$page = $page ? $page : 'default'
?>
<body id="<?php echo $page ?>">
Run Code Online (Sandbox Code Playgroud)
当我单击该About页面时,URL将更改为以下内容:http://localhost/projects/bp/about并$page显示以下值:projectsbpabout
我该怎么做才能让$ page只显示URL的最后一个字.在这种情况下,about我不想要这projectsbp部分)?
我是否必须在Wordpress路由中更改某些内容?
NoClassDefFoundError扩展了LinkageError,后者又扩展了Error.
用于Error类的Javadoc状态:
An
Error是一个子类Throwable,表示合理的应用程序不应该试图捕获的严重问题.
类加载方法Class.forName()只ClassNotFoundException在throws子句中声明.其中,除了上面的描述Error意味着我们通常不应该NoClassDefFoundError在加载类Class.forName()等时捕获它们.
我的问题是NoClassDefFoundError抛出的条件是什么而不是ClassNotFoundException?
如何找到在Haskell中存储某些数据类型值所需的实际内存量(主要是使用GHC)?是否可以在运行时(例如在GHCi中)对其进行评估,还是可以从其组件中估算复合数据类型的内存要求?
在一般情况下,如果类型的存储需求a和b已知的,什么是代数数据类型,如内存开销:
data Uno = Uno a
data Due = Due a b
Run Code Online (Sandbox Code Playgroud)
例如,这些值占用的内存中有多少字节?
1 :: Int8
1 :: Integer
2^100 :: Integer
\x -> x + 1
(1 :: Int8, 2 :: Int8)
[1] :: [Int8]
Just (1 :: Int8)
Nothing
Run Code Online (Sandbox Code Playgroud)
据我所知,由于垃圾收集延迟,实际的内存分配更高.由于惰性评估,它可能会有很大的不同(并且thunk大小与值的大小无关).问题是,给定数据类型,在完全评估时它的值会占用多少内存?
我发现:set +sGHCi中有一个选项可以查看内存统计信息,但目前尚不清楚如何估算单个值的内存占用量.
我注意到"有时"我在Eclipse项目中放入源文件夹的资源不会立即复制到输出文件夹("bin").
例如,我使用eclipse编辑器更改属性文件并保存...并且"bin"仍然具有旧版本.
有谁知道究竟是什么触发了复制(以及我如何从插件中触发)?我认为当资源发生变化时会自动发生.
- 编辑 -
通过从插件中触发它来澄清我的意思:我有一个插件,它依赖于输出文件夹中的最新资源,但显然我的插件被调用时资源已过时.这就是为什么我需要更好地了解发生了什么以及如何在需要时强制它.
我有一个使用xslt转换编写的html表,看起来像这样
<table>
<xsl:for-each select="someNode">
<xsl:if test="testThis">
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>something</td>
</tr>
</xsl:if>
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>this is always displayed</td>
</tr>
<xsl:if test="testThis2">
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>something 2</td>
</tr>
</xsl:if>
....
</xsl:for-each>
<tr>
<!-- <xsl:call-template name="conditionalRowStyle"/> -->
<td>this is always displayed</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我需要一种方法来应用不同的类oddRow/evenRow到tr elems.
<tr class="evenRow"> or <tr class="oddRow">
Run Code Online (Sandbox Code Playgroud)
我试着在每个<tr> elem之后使用这样的模板
<xsl:template name="conditionalRowStyle">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="(count(../preceding-sibling::tr) mod 2) = 0">oddrow</xsl:when>
<xsl:otherwise>evenrow</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.任何的想法?
java ×2
string ×2
c ×1
c# ×1
c++ ×1
classloader ×1
conditional ×1
eclipse ×1
encryption ×1
ghc ×1
gsub ×1
haskell ×1
html-table ×1
if-statement ×1
lua ×1
passwords ×1
php ×1
python ×1
python-3.x ×1
regex ×1
split ×1
uri ×1
url ×1
visitor ×1
wordpress ×1
xml ×1
xslt ×1