TrinityInfinity has asked for the wisdom of the Perl Monks concerning the following question:

I'm playing around with creating RSS feeds, and found this tutorial over at perl.com. But, I'm having a devil of a time with one line in the example, perhaps someone can shed some light on it for me? The line pasted in below is supposed to (according to the comments in the example), grab a headline between certain tags.
$headline = $stream->get_trimmed_text('/b') \ if ($tag->[1]{class} =~ /^h[12]$/);
... I've pasted in the code exactly, and played around with spaces, formats, everything I could think of! But I come back to an error that says
Backslash found where operator expected at rss.cgi line 32, near ") \"
        (Missing operator before \?)
syntax error at rss.cgi line 32, near ") \"
Any advice or pointing out of obvious facts I may have missed is greatly appreciated!!

Replies are listed 'Best First'.
(dooberwah) Re: Explanation of complicated line?
by dooberwah (Pilgrim) on Apr 02, 2002 at 21:14 UTC
    I think that that was just included in the tutorial to show you that those two lines are one statment. Just delete the back-slash and you should be fine.

    -Ben Jacobs (dooberwah)
    http://dooberwah.perlmonk.org
    "one thing i can tell you is you got to be free"

Re: Explanation of complicated line?
by FoxtrotUniform (Prior) on Apr 02, 2002 at 21:16 UTC

    I'm guessing that's a typo: the if(...); looks suspiciously like a modifier, and the \ key is awfully close to the enter key. So:

    $headline = $stream->get_trimmed_text('/b') if $tag->[1]{class} =~ /^h[12]$/);

    --
    :wq

      That's the solution I was looking for.... I thought it was some complicated substitution that depended upon the '\' character for something...but surely enough, just a typo. Things are peachy now! Much thanks...
        Looks like a bad habit developed by a bash programmer, as bash gets really upset if you don't "literal" your newlines . The backslash means, roughly, "continued on next line".

        Perl, fortunately, understands what you mean when you split lines for readabilty. You can even split your quotes, such as:
        my $foo = "This Is Rather Poetic";
        Which, for comparison, is not so easy in something like C:
        char *foo = "This\ Is\ Rather\ Tedious";