Hello,
I am very new to perl and am trying to use perl to create an xml file and let the user specify the filename. Here is my code:
#!/usr/bin/perl
use Fcntl; #The Module
print "Series:\n";
$series = <>;
print "Filename:\n";
$filename = <>;
open (XMLFILE,">c:/Perl_Tests/temp.xml");
printf XMLFILE '<?xml version="1.0" encoding="UTF-8"?>\n';
printf XMLFILE '<XML TAGS>';
printf XMLFILE '<SERIES>'.$series.'</SERIES>';
printf XMLFILE '<ETC>'.$etc.'</ETC>';
printf XMLFILE '<ETC>'.$etc.'</ETC>';
printf XMLFILE '</XMLTAGS>';
close(XMLFILE);
I want the use to specify the filename (instead of temp.xml) but I can't get the value of $filename into that path:
eg
open (XMLFILE,">c:/Perl_Tests/".$filename.".xml");
or something like that.
Can anyone help? Also... I want to put carriage returns after each line of XML so when the outputted file is view in a text editor it is easier to read...
I can create the file and enter the XML into it - i just cant specify the name of the file during the program execution... i have to rename it aftewards.
Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.