为什么我的chdir文件句柄在Perl中不起作用?(Why does my chdir to a filehandle not work in Perl?)

当我以文件句柄作为参数尝试“chdir”时,“chdir”返回0,并且pwd仍然返回相同的目录。 应该是这样吗?

我试过这个,因为在chdir的文档中我发现:

“在支持fchdir的系统上,可能会传递文件句柄或目录句柄作为参数,在不支持fchdir的系统上,传递句柄会在运行时产生致命错误。”

稍后给出:

#!/usr/bin/perl -w
use 5.010;
use strict;
use Cwd;

say cwd();  # /home/mm
open( my $fh, '>', '/home/mm/Documents/foto.jpg' ) or die $!;
say chdir $fh;  # 0
say cwd();  # /home/mm

我认为这可能是chdir到文件的目录 - 但在这里没有DWIM。


When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so?

I tried this, because in the documentation to chdir I found:

"On systems that support fchdir, you might pass a file handle or directory handle as argument. On systems that don't support fchdir, passing handles produces a fatal error at run time."

Given later:

#!/usr/bin/perl -w
use 5.010;
use strict;
use Cwd;

say cwd();  # /home/mm
open( my $fh, '>', '/home/mm/Documents/foto.jpg' ) or die $!;
say chdir $fh;  # 0
say cwd();  # /home/mm

I thought that this would maybe chdir to the directory of the file - but no DWIM for me here.


原文:https://stackoverflow.com/questions/1730434
2022-05-19 22:05

满意答案

他们可能会使用信息提取技术。

以下是斯坦福大学SUST工具的演示:

http://nlp.stanford.edu:8080/sutime/process

您将在文档中提取关于n-gram(连续词)的属性:

  • numberOfLetters
  • numberOfSymbols
  • 长度
  • previousWord
  • nextWord
  • nextWordNumberOfSymbols
    ...

然后使用分类算法,并提供正,负的例子:

Observation  nLetters  nSymbols  length  prevWord  nextWord isPartOfDate  
"Feb."       3         1         4       "Wed"     "29th"   TRUE  
"DEC"        3         0         3       "company" "went"   FALSE  
...

你可能会有50个例子,但越多越好。 然后,该算法基于这些示例学习,并且可以应用于以前未见过的未来示例。

它可能会学习诸如

  • 如果以前的单词只是字符,也可能是...
  • 现在的词是“二月”,“马尔”,“...”
  • 下一个单词在“第十二”,any_number ...
  • 那么是日期

这是Google工程师就此题材播放的体面视频


They likely use Information Extraction techniques for this.

Here is a demo of Stanford's SUTime tool:

http://nlp.stanford.edu:8080/sutime/process

You would extract attributes about n-grams (consecutive words) in a document:

  • numberOfLetters
  • numberOfSymbols
  • length
  • previousWord
  • nextWord
  • nextWordNumberOfSymbols
    ...

And then use a classification algorithm, and feed it positive and negative examples:

Observation  nLetters  nSymbols  length  prevWord  nextWord isPartOfDate  
"Feb."       3         1         4       "Wed"     "29th"   TRUE  
"DEC"        3         0         3       "company" "went"   FALSE  
...

You might get away with 50 examples of each, but the more the merrier. Then, the algorithm learns based on those examples, and can apply to future examples that it hasn't seen before.

It might learn rules such as

  • if previous word is only characters and maybe periods...
  • and current word is in "february", "mar.", "the" ...
  • and next word is in "twelfth", any_number ...
  • then is date

Here is a decent video by a Google engineer on the subject

相关问答

更多

Ruby:Cc地址的电子邮件丢失了(Ruby: Emails go missing for Cc addresses)

你最好使用“actionmailer”或“mail”宝石。 两者都有很好的文档。 https://github.com/rails/rails/tree/master/actionmailer https://github.com/mikel/mail I ended up dropping the use of mailfactory to try mail instead, but I hit an issue not covered in the documentation. The doc...

苹果如何在电子邮件中找到日期,时间和地址?(How does Apple find dates, times and addresses in emails?)

他们可能会使用信息提取技术。 以下是斯坦福大学SUST工具的演示: http://nlp.stanford.edu:8080/sutime/process 您将在文档中提取关于n-gram(连续词)的属性: numberOfLetters numberOfSymbols 长度 previousWord nextWord nextWordNumberOfSymbols ... 然后使用分类算法,并提供正,负的例子: Observation nLetters nSymbols length p...

我应该如何安排我的模型和cron rake任务以不同开始日期的间隔发送电子邮件?(How should I arrange my models and cron rake task to send emails on intervals with different start dates?)

我还建议使用delayed_job来处理电子邮件的发送。 通过delayed_job,您将拥有一个包含相关时间的任务队列。 它允许您在将来的特定时间安排任务。 这可能比使用cron更方便。 就调度而言,它看起来像电子邮件在电话完成之前不会被发送,因此队列中的电子邮件条目应该在应用程序被通知完成呼叫时创建。 日期计算应该像Time.now + 4.days一样简单。 如果在电子邮件发送前有多个电话需要完成,那么在将电子邮件发送到队列中之前,您只需检查是否已完成所有呼叫。 I would also s...

使用scrapy查找正文中的电子邮件地址(Finding email addresses in body using scrapy)

您可以在response.body上使用正则表达式搜索来查找电子邮件ID。 emails = re.findall(r'[\w\.-]+@[\w\.-]+', response.body) You can use a regular expression search on the response.body to find email ids. emails = re.findall(r'[\w\.-]+@[\w\.-]+', response.body)

验证多重电子邮件地址(validation for multipe email addresses)

1)您可以使用简单的正则表达式来检查电子邮件字段的值。 有许多正则表达式可以起作用,从最宽松的到最复杂的。 人们通常倾向于使用这样的东西: unless email =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/ puts "Your email address does not appear to be valid") 这个正则表达式可能会传递一些...

Apple的iCloud阻止来自我网站的电子邮件(Apple's iCloud blocking emails from my website)

为我们服务器的IP地址添加了反向DNS条目,并从Apple的黑名单中取出服务器的IP地址。 Had a reverse DNS entry added for our server's IP address, and got the server's IP address taken off of Apple's blacklist.

从Thunderbird电子邮件中提取电子邮件地址(Extract Email Address from Thunderbird Emails)

正则表达式诞生于此类工作。 这是一个最小的控制台应用程序,它显示了如何使用RegEx从一个长文本块中提取所有电子邮件地址: program Project25; {$APPTYPE CONSOLE} uses SysUtils, PerlRegex; var PR: TPerlRegEx; TestString: string; begin // Initialize a test string to include some email addresses. This ...

Excel查找并替换除电子邮件地址以外的所(Excel find and replace everything except email addresses?)

你可以使用这个公式: =TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),FIND("@",SUBSTITUTE(A1," ",REPT(" ",99)))-99,198)) You could use this formula: =TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),FIND("@",SUBSTITUTE(A1," ",REPT(" ",99)))-99,198))

如何读取传入电子邮件的IP地址(How to read ip address of the incoming emails)

$mailinfo = imap_headerinfo($inbox, $emails[$x]); print_r($mailinfo->from); 应该给你: personal, adl, mailbox, and host 以下任何一项应该可以帮助你$ mailinfo - > ... : (如需完整参考,请查看http://php.net/manual/en/function.imap-headerinfo.php ) ->to - an array of objects from th...

相关文章

更多

Script.NET Perl解释器代码已经在GitHub开源发布

Script.NET Perl解释器的代码已经提交到GitHub网站。GitHub项目地址: http ...

RabbitMQ Work模式消息队列

一个生产者、多个消费者。 一个消息只能被一个消费者获取。 生产者发布消息 private ...

Don’t work. Be hated. Love someone.

http://halfhalf.posterous.com/dont-work-be-hated-lo ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

She’s Not Carrying A Handbag

Gao Yuanyuan from after 2005 drama " world fir ...

ServletOutputStream cannot be resolved to a type

在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec ...

Book Report: THE SOUL OF A NEW MACHINE

Book Report: THE SOUL OF A NEW MACHINE Zhengdong Zh ...

How to Start a Business in 10 Days

With an executive staffing venture about to open, a ...

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本