我在用
Server version: Apache/1.3.34 (Debian)
mod_perl - 1.29
Run Code Online (Sandbox Code Playgroud)
通过引用STDIN,STDOUT和STDERR Streams
#!/usr/bin/perl5
package main;
use strict 'vars';
{
# Our mighty holy legacy code love to print out message in the middle of operation. Shihh....
# Let's quietly redirect those message to /dev/null.
my $nullfh = Apache::gensym( );
open $nullfh, '>/dev/null' or warn "Can't open /dev/null: $!";
local *STDOUT = $nullfh;
print "BYE BYE WORLD"; # Shouldn't show in webpage.
close $nullfh;
}
print "X BEGIN HELLO WORLD"; # Should …Run Code Online (Sandbox Code Playgroud) 抱歉.我不想尝试任何火焰.我的脚本编写经验来自Perl,我是Python的新手.
我只是想检查一下我是否可以像Python一样具有相同程度的灵活性.
在Python中:
page = form.getvalue("page")
str = 'This is string : ' + str(int(page) + 1)
Run Code Online (Sandbox Code Playgroud)
在Perl中:
$str = 'This is string : ' . ($page + 1);
Run Code Online (Sandbox Code Playgroud)
有什么方法可以避免int/str转换吗?
// I prefer to perform forward declaration on myclass, as I do not
// wish to ship "myclass.h" to client
// However, the following code doesn't allow me to do so, as class defination
// is needed in header file.
//
// a.h
#include "myclass.h"
class a {
public:
a();
myclass me;
};
Run Code Online (Sandbox Code Playgroud)
我试着以另一种方式做到这一点.但是,我需要使用动态分配,我通常会尽量避免.
// a.h
class myclass;
class a {
public:
a();
myclass& me;
};
// But I just wish to avoid new and delete, is it possible?
// …Run Code Online (Sandbox Code Playgroud) 以下代码工作正常:
std::map<int, int>& m = std::map<int, int>();
int i = m[0];
Run Code Online (Sandbox Code Playgroud)
但不是以下代码:
// error C2678: binary '[' : no operator...
const std::map<int, int>& m = std::map<int, int>();
int i = m[0];
Run Code Online (Sandbox Code Playgroud)
大多数时候,由于理由,我更喜欢让我的大部分东西变成不变的:
http://www.javapractices.com/topic/TopicAction.do?Id=29
我看一下地图源代码.它有
mapped_type& operator[](const key_type& _Keyval)
Run Code Online (Sandbox Code Playgroud)
有什么理由,为什么std :: map无法提供
const mapped_type& operator[](const key_type& _Keyval) const
Run Code Online (Sandbox Code Playgroud) 给出以下代码?
final Map<String, List<E>> map = new HashMap<String, List<E>>();
List<E> list = map.get(mapKey);
if (list == null) {
list = new ArrayList<E>();
map.put(mapKey, list);
}
list.add(value);
Run Code Online (Sandbox Code Playgroud)
如果有什么办法我可以避免空检查?但是,让我第一次插入Map时会自动为我创建List吗?
我记得我曾经看过一个能够做到这一点的专业地图.但是,我忘记了我已经看到的地方:(
我尝试使用允许字符数限制为5
try {
jFormattedTextField2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("*****")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我只输入1个字符时,总会有4个其他空格被填充.如何避免填充,同时限制字符数?
而不是编写以下非线程安全的方法.
private static final Calendar calendar = Calendar.getInstance();
public void fun() {
// Going to call mutable methods in calendar.
}
Run Code Online (Sandbox Code Playgroud)
我将其更改为线程安全版本.
public void fun() {
final Calendar calendar = Calendar.getInstance();
// Going to call mutable methods in calendar.
}
Run Code Online (Sandbox Code Playgroud)
即使对于同一个线程,我也不是每次创建一个新实例,而是通过执行改进
public void fun() {
final Calendar calendar = getCalendar();
// Going to call mutable methods in calendar.
}
/**
* Returns thread safe calendar.
* @return thread safe calendar
*/
public Calendar getCalendar() {
return calendar.get();
}
private static …Run Code Online (Sandbox Code Playgroud) 当我尝试从XML文件执行加载时,我觉得xstream加载速度达不到我的要求.对于具有10k ++条目的"数据库",将需要几分钟.
以下是我用于序列化的整个数据结构.列表的大小(符号和代码)大约是10k ++条目.
有什么方法我可以尝试,看看它是否会加快我的加载时间?能够仍然加载以前保存的文件也很重要.
以下是用于反序列化的代码.谢谢.
@SuppressWarnings("unchecked")
public static <A> A fromXML(Class c, File file) {
XStream xStream = new XStream(new DomDriver("UTF-8"));
InputStream inputStream = null;
try {
inputStream = new java.io.FileInputStream(file);
Object object = xStream.fromXML(inputStream);
if (c.isInstance(object)) {
return (A)object;
}
}
catch (Exception exp) {
log.error(null, exp);
}
finally {
if (false == close(inputStream)) {
return null;
}
inputStream = null;
}
return null;
}
Run Code Online (Sandbox Code Playgroud) 目前,我正在寻找一个可以放在我的Java Swing应用程序中的多列梳状盒组件.
目前,我在用户输入时使用组合框作为自动完成下拉列表.

是否有任何可用的GUI组件,使我能够拥有以下(多列)?如您所见,下拉列表中有3列,而上例中的列为1列.

谢谢.