in reply to So Simple, Yet no tutorial covers it

ok, i wrote this code, just a simple regex thing to extract the "Location" data. Here it is:
#!/usr/local/bin/perl -w use LWP::Simple; #program starts $totalAdress = "http://www.foobar.com/htmlschuff/data.html"; $content = get($totalAdress) || die "doesn't seem to be a valid adress +: $!"; #Location $start = "<p><b>Location:</b>\n"; $end = "<p>"; if ($content =~ /\b$start\b(.*?)\b$end\b/) { $Location = $1; print $Location; } print "\ndone\n";
And it won't work. Now I'm a newbie, ok. So its probably that the regex cant take variables but I'm not sure. All i get when i use this code against a real page that has the same data as the original example and this is the program output:
$./thecode.pl done $
Any idea, I'm sure its some newbie mistake but it beats me.

Replies are listed 'Best First'.
(jeffa) Re: Re: So Simple, Yet no tutorial covers it
by jeffa (Bishop) on Jan 22, 2001 at 07:47 UTC
    Change your if conditional line with the regex to this:
    if ($content =~ /$start\s*(.*?)\s*$end/) {
    you really don't have to have the word boundaries, and you should always expect possible white space.

    Remember, TIMTOWTDI

    Jeff

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
      And take out .*? You probably want .+? Since this will grab at least one character for sure. Also, adding an else clause after the if would be a good way to notify the user if there is not match, or to provide a default location, like 'no location given'.