Hi, I was hoping for some help with parsing out information from a very large string variable so that I might place html tags around different portions of the string. Here goes:

I have a variable that contains both spaces and newline characters. Within an HTML table, I would like to create a new row for each "\n" character in the string and a new colum for every space in the string.

My code looks like this so for, but I know that it is incorrect.
#!/usr/bin/perl use strict; my $input='unixhelp pts/5 10.3.4.54 Fri Jun 13 11:08 still logged in unixhelp pts/5 10.3.4.00 Fri Jun 13 11:05 - 11:05 (00:00) unixhelp pts/5 10.3.4.00 Fri Jun 13 11:04 - 11:05 (00:00) unixhelp pts/5 10.3.4.00 Fri Jun 13 11:00 - 11:01 (00:00) unixhelp pts/5 10.3.4.00 Fri Jun 13 10:49 - 10:52 (00:03) unixhelp pts/8 10.3.4.00 Fri Jun 13 10:46 - 10:46 (00:00) unixhelp pts/3 10.3.4.00 Fri Jun 13 10:12 - 10:12 (00:00) unixhelp pts/3 10.3.4.00 Fri Jun 13 10:10 - 10:10 (00:00) unixhelp pts/3 10.3.4.00 Fri Jun 13 10:09 - 10:09 (00:00) unixhelp pts/3 10.3.4.00 Fri Jun 13 10:07 - 10:08 (00:00)'; print "Content-type: text/html\n\n"; print "<HTML><BODY>\n"; print " <TABLE>\n"; print " <TR>\n"; foreach ($input) { print "<TD>"; print; print "\n</TD>"} print " </TR>\n"; print " </TABLE>\n"; print "<BODY><HTML>\n";

This code only places a table around the entire variable and does not break it up into pieces. I am still very new to perl and am not sure of all of the unique things that you can do with a for loop. If anyone knows how to seperate a variable into pieces using newline and space as a character, I would be very appreciateive if you would send me some suggestions or resources. Thank you very much for your time in reading this.

In reply to Parsing Variables by JoeJaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.