Hello monks, I have a file that looks something like this:
<TABLE name="table1"> FieldName1 VARCHAR(20) FieldName2 INT(20) FieldName3 BOOL </TABLE> <TABLE name="table"2> FieldName1 VARCHAR(20) FieldName2 INT(20) FieldName3 BOOL </TABLE>
Now I expect to be able to say:
while ($file =~ s/<TABLE(.*)>([\n.]*)<\/TABLE>//i) { # $1 should equal ' name="table1"' my $attributes = $1; #$2 should equal # #FieldName1 VARCHAR(20) #FieldName2 INT(20) #FieldName3 BOOL # my $fields = $2; }
What I get is nothing. When I say
$file =~ s/<TABLE(.*)>(\n.*)//i
Then
$2 = 'FieldName1 VARCHAR(20)'
- the first line of text. Or:
$file =~ s/<TABLE(.*)>([\n.]*)//i\
Then
$2 = "\n";
I know that the . (wildcard) charcater doesn't match newlines, hence using the character class \n. in my original example - does anyone have an answer as to why this doesn't work, and what should I do instead? Thank you!

In reply to Regex, Newline, Wilcard by boblawblah

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.