可能重复:
需要perl就地编辑不在命令行上的文件
我已经有一个编辑我的日志文件的工作脚本,但我正在使用一个临时文件,我的脚本像这样工作:
Open my $in , '<' , $file;
Open my $out , '>' , $file."tmp";
while ( <in> ){
print $out $_;
last if $. == 50;
}
$line = "testing";
print $out $line;
while ( <in> ){
print $out $_;
}
#Clear tmp file
close $out;
unlink $file;
rename "$file.new", $file;
Run Code Online (Sandbox Code Playgroud)
我想编辑我的文件而不创建一个tmp文件.
使用Symfony2/doctrine2,我们使用find()函数根据所选实体获取特定对象(如有关系)(如OneToMany),Doctrine返回所有其他对象.
例如 :
$em = $this->get(
'doctrine.orm.entity_manager',
$request->getSession()->get('entity_manager')
);
$product = $em->getRepository('MyBundle:Product')->find($id);
Run Code Online (Sandbox Code Playgroud)
$ product上的结果将是Product对象+其他链接对象,如(Store,Category,...等).
我们如何控制学说来确定我们需要返回哪个对象.
我可以使用Querybuilder,但我正在寻找是否有任何功能都确定.