1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Newbie Perl Question #2

Discussion in 'Programming' started by sarahk, Mar 8, 2005.

  1. #1
    Ok, probably not a huge difference between my original question and this but I'll start a new thread anyway.

    I have a site hosted locally which doesn't allow cron jobs.
    I have a site hosted overseas which does
    I need cron jobs on the local site so I'll just get the overseas site to trigger them using perl

    #!/usr/local/bin/perl -w
    use LWP::Simple;
    use CGI;
    my $URL="http://www.mysite.com/cron.manager.php";
    my $content = "Incomplete Cron Job";
    $content = LWP::Simple::get($URL);
    print "$content";
    Code (markup):
    I have a low workload for now but every so often I get this



    To get around that I put in the line where I set a default value to $content

    I'm guessing that the problem is that cron.manager.php doesn't finish in time and so $content isn't being populated. So...

    How do I tell Perl not to change the value of $content if LWP::Simple::get($URL) doesn't return anything?

    thanks

    Sarah
     
    sarahk, Mar 8, 2005 IP
  2. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried using a temporary variable?
    
    my $tmp = "Incomplete Cron Job";
    $tmp = LWP::Simple::get($URL);
    If ($tmp ne "") {
      $content = $tmp;
    }
    
    Code (markup):
     
    neterslandreau, Mar 9, 2005 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Thanks Neters

    I've changed the code to
    my $content = "Incomplete Cron Job";
    my $tmp = LWP::Simple::get($URL);
    If ($tmp ne "") 
    {
    $content = $tmp;
    }
    print "$content";
    Code (markup):
    and get this error


    but from hunting around it seems that the syntax is something like
     die "Couldn't get it!" unless defined $content;
    Code (markup):
    but when I found it I also discovered that I can just have
    #!/usr/local/bin/perl -w
    use LWP::Simple;
    use CGI;
    my $URL="http://www.mysite.com/cron.manager.php";
    LWP::Simple::getprint($URL);
    Code (markup):
    and it should give me the http response if it fails which will do :)

    Sarah
     
    sarahk, Mar 9, 2005 IP
  4. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I should have warned you that I didn't do any syntax checking when I posted that and I rarely use Perl anymore.

    I'm glad you found the solution :)
     
    neterslandreau, Mar 9, 2005 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    Hey, that's ok. I appreciate your response and ultimately it meant that I had more information and therefore more understanding when reading up on the possible solutions. getprint has problems with some urls - seems mine is ok tho'

    Now, when it fails I get



    and I can use this error message to talk to my host if it happens too often.

    thanks

    Sarah
     
    sarahk, Mar 9, 2005 IP