#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    30
    Rep Power
    3

    String not interpolating


    I run this code
    Code:
    #!/usr/bin/perl -w
    use WWW::Mechanize;
    use Data::Dumper;
    #$url = 'http://www.$urli.com';
    &intro;
    sub intro {
    	print " Enter:  ";
    	&mech;
    }
    sub mech {
    	$urli = <STDIN>;
    	chomp($urli);
    	$m = WWW::Mechanize->new(autocheck => 1);
    	
    	
    	if ($urli eq 'google') {
    		print " 1.) News\n";
    		print " 2.) Images\n";
    		print " 3.) Quit\n";
    		
    		$q1 = <STDIN>;
    		chomp($q1);
    		if ($q1 == '1') {
    			$url = 'http://www.google.com/news';
    			$m->get($url);
    		}
    	}
    	else {
    		$url = 'http://www.$urli.com';
    		$m->get($url);	
    		system('firefox', $url);
    	}
    }
    and i get
    Code:
    Error GETing http://www.$urli.com: Can't connect to www.$urli.com:80 (Bad hostname)
    the program thinks the url contains $urli when its just a variable. How do i correct this mistake?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Code:
    $url = 'http://www.$urli.com';
    The single quotes is preventing variable interpolation. Change them to double quotes.
    Code:
    $url = "http://www.$urli.com";

IMN logo majestic logo threadwatch logo seochat tools logo