Syntax Error caused by Inserting Hyperlink in String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • group8perl
    New Member
    • Feb 2007
    • 13

    Syntax Error caused by Inserting Hyperlink in String

    am getting syntax error, can someone please explain how to insert a hyperlink into a table.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Originally posted by group8perl
    am getting syntax error, can someone please explain how to insert a hyperlink into a table.
    Is this an HTML question?

    - M

    Comment

    • group8perl
      New Member
      • Feb 2007
      • 13

      #3
      Sorry about the poor topic but it is a perl question
      part of my code consists of
      <td><<A HREF="http://www.whatever.co m">http://www.whatever.co m</A></td>

      And the error i get is "syntax error at line 99, near "<td><<A HREF="http""

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        lets see your real perl code. What you posted is an out of context line of text that is impossible to debug in relationship to your perl code.

        Comment

        • group8perl
          New Member
          • Feb 2007
          • 13

          #5
          Haven't posted the whole code because most of it is HTML
          but the code concerning the error is below

          print "<table border='1'>";
          print "<tr><td>Ty pe</td><td>Size</td><td>Price</td></tr>";
          foreach $line (@all) {
          chop($line);
          ($size,$price,$ type=split(/\|/,$line);
          print "
          <tr>
          <td>$type</td>
          <td>$size</td>
          <td>$price</td>
          <td><A HREF="http://www.whatever.co m">http://www.whatever.co m</A></td>
          </tr>";
          }
          print"</table>";

          If needed i could post the entire code
          Also could you help me change some of the table attributes such as font, font colours, bgcolor, row width, column width
          Thank you

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            you can't use unescaped double-quotes in a print command that uses double-quotes as the string terminator, add a backslash to escape embedded double-quotes:

            Code:
            print "
            <tr>
            <td>$type</td>
            <td>$size</td>
            <td>$price</td>
            <td><A HREF=\"http://www.whatever.com\">http://www.whatever.com</A></td>
            </tr>";
            }
            perl has quote operators that make life easier:

            perldoc Quote and Quote like Operators

            Comment

            • miller
              Recognized Expert Top Contributor
              • Oct 2006
              • 1086

              #7
              To fix your problem, either escape the double quotes inside the string, or use a different encloser. My personal preference is to use qq{my string here}.




              Code:
              print qq{<table border='1'>};
              print qq{<tr><td>Type</td><td>Size</td><td>Price</td></tr>};
              foreach $line (@all) {
              	chop($line);
              	($size, $price, $type) = split(/\|/, $line);
              	print qq{
              <tr>
              <td>$type</td>
              <td>$size</td>
              <td>$price</td>
              <td><A HREF="http://www.whatever.com">http://www.whatever.com</A></td>
              </tr>};
              }
              print qq{</table>};

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                hehehe.... that long hyper link was rather obnoxious, thanks Miller ;)

                Comment

                • miller
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1086

                  #9
                  Your welcome :)

                  perldoc really does have the silliest anchors. Why on earth they feel it necessary to have an anchor that is 157 characters in length when the header for the section is only 30, I'll never know.

                  Comment

                  • group8perl
                    New Member
                    • Feb 2007
                    • 13

                    #10
                    Thanks for the help
                    It works nicely
                    But any ideas on improving how the table looks (fonts, colors etc.)
                    Thank You

                    Comment

                    • group8perl
                      New Member
                      • Feb 2007
                      • 13

                      #11
                      Code:
                      print "<table border='1'>";
                      print "<tr><td>Type</td><td>Size</td><td>Price</td></tr>";
                      foreach $line (@all) {
                      chop($line);
                      ($size,$price,$type=split(/\|/,$line);
                      print "
                      <tr>
                      <td>$type</td>
                      <td>$size</td>
                      <td>$price</td>
                      <td><A HREF="http://www.whatever.com">http://www.whatever.com</A></td>
                      </tr>";
                      }
                      print"</table>";
                      Another question
                      The variable $type, how do i transfer that variable to another perl script using the hyperlink?
                      Most tutorials i have seen comment on forms but not hyperlinks
                      An suggestions
                      Thank You

                      Comment

                      • KevinADC
                        Recognized Expert Specialist
                        • Jan 2007
                        • 4092

                        #12
                        http://www.whatever.co m/cgi-bin/yourscript.pl?t ype=$type

                        Comment

                        • group8perl
                          New Member
                          • Feb 2007
                          • 13

                          #13
                          Brilliant
                          Thanks for the help Kevin, will see if this works

                          Comment

                          • group8perl
                            New Member
                            • Feb 2007
                            • 13

                            #14
                            This code works nicely
                            I have used http://www.whatever.co m/cgi-bin/yourscript.pl?$ type
                            But what if i wish to transfer more than one variable using this method, is it possible?
                            For example tranfer $type, and $size, $code
                            Thank You

                            Comment

                            • KevinADC
                              Recognized Expert Specialist
                              • Jan 2007
                              • 4092

                              #15
                              Code:
                              http://www.whatever.com/cgi-bin/yourscript.pl?type=$type&size=$size
                              or instead of '&' use ';' which to delimit for URI string:

                              Code:
                              http://www.whatever.com/cgi-bin/yourscript.pl?type=$type;size=$size

                              Comment

                              Working...