in reply to What is wrong with variable?

.... did you see: i closed connection and run function login.... Now it's work:
#!/usr/bin/perl use warnings; use strict; use Net::POP3; my $pop = Net::POP3->new('pop3.server') || die("Coudn't connect"); if(!$pop->login('email@adress.com', 'password') < 0){ die("Can't connect"); } my $last, $now) = '0'; sub check { $last = shift; $pop->quit; sleep 5; $pop = Net::POP3->new('pop3.server') || die("Can't connect"); $now = $pop->login('email@adress', 'password') || die("Can't c +onnect"); if ($last < $now){ my $msg = $pop->get($now); for my $line (@$msg){ if( $line =~ /^Subject: '(.*)'/ ){ system(`$1`); return $now; print "I done $1"; last } } } return $now; } while (1){ &check($now); } $pop->quit();
Now I can add next function =] I love perl=] greetz & thx

Replies are listed 'Best First'.
Re^2: What is wrong with variable?
by insaniac (Friar) on Mar 19, 2006 at 08:41 UTC
    so the posted code works?
    my $last, $now)= '0';
    What is this supposed to do? Initialize both $last and $now to '0'? Guess again...
    my $last = my $now = '0';
    works better ;-)

    btw, what is this supposed to do:

    system(`$1`); return $now; print "I done $1"; last
    The last two lines will never get executed... never! BTW: why do you use backticks in your system() sub? It's either `$1`, or do{ open(my $cmdh, '-|', $1); <$cmdh> } or system($1)... but combining two of them is probably not what you want to do...
    and... you might wanna write those 4 lines in a different order:
    `$1`; print qq{I've done $1}; return $now
    3 lines... does the same thing ;)

    cya!

    to ask a question is a moment of shame
    to remain ignorant is a lifelong shame

      I wrote bad version of script... now i see.... I'll copy good version today... sorry