English 中文(简体)
如何在垂直模块中引用这一参数
原标题:How to quote this parameter in perl module
  • 时间:2012-04-10 03:59:30
  •  标签:
  • perl
  • twitter

我试图使用“任何发明”:Twitter:Stream模块,我想提一个文件,列出Twitter uids,我想照此办理。 我可以把女子放在法典本身,并做如下工作:

my $done = AnyEvent->condvar;
       my $nt_filter = AnyEvent::Twitter::Stream->new(
             username => $cf{account},
             password => $cf{password},
           method =>  filter ,
           follow =>  15855509,14760150,18598536 ,
            on_tweet => sub {
                 #some code.....
            },
            on_error => sub {
                my $error = shift;
                debug "ERROR: $error";
            },
            timeout => 45,
        );
       $done->recv;

但是,当我试图使用同样档案时:

my $done = AnyEvent->condvar;
       my $nt_filter = AnyEvent::Twitter::Stream->new(
           open UID_FILE, "/tmp/uids" or die $!;

           my @uid_line = <UID_FILE>;

             username => $cf{account},
             password => $cf{password},
           method =>  filter ,
           follow => @uid_file,
            on_tweet => sub {
                  #some code....
            },
            on_error => sub {
                my $error = shift;
                debug "ERROR: $error";
            },
            timeout => 45,
        );
       $done->recv;

它失败了。 The uids file has the following content:

 15855509,14760150,18598536 

I m从Twitter中发现406个错误,表明格式不正确。 猜测引言不正确?

最佳回答

The AnyEvent:Twitter:Stream 模块子类别<代码>AnyEvent,你根本不需要进入基单元。 所有功能均由<条码>新方法及你具体指明的背书提供,并附有<条码>。

。 页: 1 任何Event:Twitter:Stream->new。

此外,你为提供<代码><<<<<> > >参数>的价值而使用的变量是@uid_file,而不是@uid_line

页: 1 <代码>严格使用;和use presss;, at thestart of their programmes, especially if You arequest for help with them. 这将把你本来可以忽略的那种简单错误trap起来。

一般来说,你可以使用一个阵列来提供单一的微粒价值。 在这种情况下,只要档案仅有一个单一线(因此阵列中只有一个要素),它就可能是科索沃的,但还有许多可能是错误的。

此外,你在价值上只读一字:在《法典》中,这些字眼只是为了标示“Perl”的开始和结束。

我建议你从你档案中读出所有精彩的画像。

open my $uid_fh,  < ,  /tmp/uids  or die $!;
my @uids;
push @uids, /d+/g for <$uid_fh>;

(Note that these lines belong before the call to AnyEvent::Twitter::Stream->new)

然后,可以通过书面方式提供<条码>参数。

follow => join( , , @uids),

我希望这一点是明确的。 请再次询问是否需要进一步帮助。


<><>Edit>>

列入你的法典的这些改动应当照此办理,但并非不完整,我不能保证会妥善工作。

use strict;
use warnings;

use AnyEvent::Twitter::Stream;

open my $uid_fh,  < ,  /tmp/uids  or die $!;
my @uids;
push @uids, /d+/g for <$uid_fh>;

my %cf = (
  account =>  myaccount ,
  password =>  password ,
);

my $nt_filter = AnyEvent::Twitter::Stream->new(
  username => $cf{account},
  password => $cf{password},
  method =>  filter ,
  follow => join( , , @uids),
  on_tweet => sub {
    #some code....
  },
  on_error => sub {
    my $error = shift;
    debug "ERROR: $error";
  },
  timeout => 45,
);
问题回答

我像你一样试图通过一个阵列,以便你能够遵循<1><>1>,即阵列中的要素数目(档案中线数)。

假设在你档案中只有一个一线身份证,则做以下工作:

   open UID_FILE, "/tmp/uids" or die $!;

   # Load the first line of uids
   my $uid_line = <UID_FILE>;

   # Remove apostrophes from input.
   # This may or may not be necessary
   $uid_line =~ s/ //g;

   # Don t forget to close the file
   close(UID_FILE);

   my $done = AnyEvent->condvar;
   my $nt_filter = AnyEvent::Twitter::Stream->new(

         username => $cf{account},
         password => $cf{password},
       method =>  filter ,
       follow => $uid_line,
        on_tweet => sub {
              #some code....
        },
        on_error => sub {
            my $error = shift;
            debug "ERROR: $error";
        },
        timeout => 45,
    );
   $done->recv;

也许你需要从你的输入线上脱下主线和拖网。 例如:

$uid_line =~ s/^ //;
$uid_line =~ s/ $//;

也许你会放弃仅仅去除所有外逃,例如:

$uid_line =~ s/ //g;




相关问题
Why does my chdir to a filehandle not work in Perl?

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: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签