Thread undefined value as a HASH reference - problem (7 answers)
Opened by Mindfoo at 2009-04-03 22:16

Mindfoo
 2009-04-03 22:16
#120278 #120278
User since
2009-04-03
10 Artikel
BenutzerIn
[default_avatar]
Hallo, Ich hab ein kleines Problem mit einem Script :/

Kurze erklärung was es überhaupt macht:

Ich möchte auf einen jabberserver connecten, das passwort was ich bei diesem login brauche muss ich vorher von einer website scrapen... Das funktioniert auch, aber ich kann die variable im connect nicht nutzen, bekomme immer diesen fehler raus:
Can't use an undefined value as a HASH reference at /usr/local/share/perl/5.10.0/XML/Stream.pm line 1165.

der code:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use Net::XMPP;

sub getxmpp {
    my $mech = WWW::Mechanize->new( cookie_jar => {} );
    $mech->agent_alias( 'Windows IE 6' );
    $mech->add_header('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' );
    $mech->add_header('X-Requested-With' => 'XMLHttpRequest' );
    my ( $self, $event ) = @_;
    my $nick = shift;

    my $loginpost = $mech->post(
        'http://www.quakelive.com/user/login',
        {
            u => 'email@domain.com',
            p => 'meinpass',
            r => '0',
        }
    );
    $mech->get("http://www.quakelive.com/user/load");
    my $site = $mech->content();
    if($site =~/".+XAID":"(.+)","STATUS/){
        return $1;
    } else {
        print "fail";
    }
}

sub xmppconnect {
        my $connection = Net::XMPP::Client->new();
        my $xmpp = getxmpp();
        $connection->Connect( hostname => 'xmpp.quakelive.com') or die "Cannot connect ($!)\n";
        my @result = $connection->AuthSend( "username" => 'qlstats', "password" => $xmpp, "resource" => 'quakelive');
        if ($result[0] ne "ok") {
                die "Ident/Auth with server failed: $result[0] - $result[1]\n";
        }

#       $connection->PresenceSend();

        my $message = Net::XMPP::Message->new();
        $message->SetMessage(
                "to"           => 'Mindfoo\@xmpp.quakelive.com',
                "type"         => "chat",
                "body"         => "testmsg from script");
        $connection->Send($message) or die "Cant send msg!\n";
        sleep(2);

        $connection->Disconnect();
}

xmppconnect();


Hat jemand nen Tipp?

View full thread undefined value as a HASH reference - problem