perl problem

Discussion in 'Programming' started by ssimon171078, May 2, 2014.

  1. #1
    i need to insert into url varible $i using perl i have probleb to do this.
    #!/usr/bin/perl

    use WWW::Mechanize;
    use strict;

    print "Content-type: text/html\n\n";
    $i=1;'
    $websie='url/' .'$i' .' ?s=c';
    print $website
     
    ssimon171078, May 2, 2014 IP
  2. tylerman169

    tylerman169 Member

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    43
    #2
    You need to use double quotes if you want to interpret the value of a variable. You can use this code to insert the $i variable value into $website:

    print "Content-type: text/html\n\n";
    $i=1;
    $website="url/$i?s=c";
    print $website;
    Code (markup):
     
    tylerman169, May 2, 2014 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    A few issues your code has:

    1) You have an extra apostrophe after $i=1;' Having that ' will break your code.
    2) You are settings $websie variable, but printing $website variable. Those two are different (missing the t).
    3) You are placing the $i in quotes, which will translate it into string. If you want it to use a variable, remove the quotes: $websie='url/' . $i .' ?s=c';
    4) You have an extra space before the ?: $websie='url/' .'$i' .'?s=c';

    Overall I would say you are starting to learn Perl, in which case you should cover the basics of the language first. You can read this ebook to increase your expertise: http://www.perl.org/books/beginning-perl/ (or google learn perl).
     
    ThePHPMaster, May 4, 2014 IP