Hi! I opened a file and placed it into an array - now before I print to the browser the contents of the array, I want to find two specific lines and remove them.

How I want it to be setup is like so:
1.) Print to the browser the xml version, dtd + xsl location
2.) Read in the xml file and store it in an array.
3.) Remove the xml file version, dtd + xsl location in the actual xml file read in from step 2.
4.) Print out to the browser the xml file data ONLY (minusing the xml version/xsl/dtd location that was removed on step 3)


That's it. The reason being is that becuase the xml data files I'm recieving have the dtd/xsl location different than were it's actually going to be - so I need to remove that from the xml data file.

The other problem, is that we have 4 reports type, but right now I'm just testing for just one type. Is the a way to use the regex to start from particular characters and end at a particular characters with a wildcard in the middle? I want to find the string and replace with no value. e.g.:

@lines =~ s/<!DOCTYPE XMLDATA SYSTEM \"artist_royalty.dtd\">//; #????


It could be a artist_royalty.dtd or license_royalty.dtd or mechanical_royalty.dtd - so I'd like to do the wild card before the report type and end off with --> .dtd\"> for the replace search.

Here's my code, everything works great EXCEPT for the Regex on the array which has the xml file contents:

print "<?xml version=\"1.0\"?>\n";

# The conditional statement below checks to see what report type the user is requesting
# Then prints out the dtd + xsl for that report type.


if ($doctype eq "m") { print "<!DOCTYPE XMLDATA SYSTEM \"http://www.mydotcom.com/DRM/clients/ +XML_FORM/XML_DTD/mechanical_royalty_rightrax.dtd\">\n"; print "<?xml-stylesheet type=\"text/xsl\" href=\"http://www.mydotcom.c +om/DRM/clients/XML_FORM/XSL_templates/M_template_rightrax.xsl\"?>\n"; } elsif ($doctype eq "a") { print "<!DOCTYPE XMLDATA SYSTEM \"http://www.mydotcom.com/DRM/clients/ +XML_FORM/XML_DTD/artist_royalty_rightrax.dtd\">\n"; print "<?xml-stylesheet type=\"text/xsl\" href=\"http://www.mydotcom.c +om/DRM/clients/XML_FORM/XSL_templates/A_template_rightrax.xsl\"?>\n"; else { print "<!DOCTYPE XMLDATA SYSTEM \"http://www.mydotcom.com/DRM/clients/ +XML_FORM/XML_DTD/license_royalty_rightrax.dtd\">\n"; print "<?xml-stylesheet type=\"text/xsl\" href=\"http://www.mydotcom.c +om/DRM/clients/XML_FORM/XSL_templates/L_template_rightrax.xsl\"?>\n"; # The snippet below opens then reads the XML data file from the server +<br> # and prints it to the browser - so that they can view it - and not kn +ow<br> # where the doc originates from. open (XMLFILE, "/opt/www/docs/$document") || &open_error("http://$serv +er$document"); @lines = <XMLFILE>; close (XMLFILE); @lines =~ s/<?xml version=\"1.0\"?>//; #???????????? @lines =~ s/<?xml-stylesheet type=\"text/xsl\" href=\"A_template.xsl\" +?>//; #???????????? @lines =~ s/<!DOCTYPE XMLDATA SYSTEM \"artist_royalty.dtd\">; #??????? +????? foreach $line (@lines) { #chop $line; print "$line"; }

In reply to Regex on a array by adobepro

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.