Results 1 to 5 of 5
I'm having trouble with a variable in a perl script. This is my first perl script (probably obvious).
Code:
#!/usr/bin/perl
$TODAY=`date "+%A"`;
$NAME=mike;
$xml_file="/opt/$NAME.$TODAY.xml";
print $TODAY;
print $xml_file;
output
Code:
...
- 11-14-2008 #1Linux Newbie
- Join Date
- May 2007
- Posts
- 106
[SOLVED] set varialbe in perl
I'm having trouble with a variable in a perl script. This is my first perl script (probably obvious).
outputCode:#!/usr/bin/perl $TODAY=`date "+%A"`; $NAME=mike; $xml_file="/opt/$NAME.$TODAY.xml"; print $TODAY; print $xml_file;
I expected the second line of output to be:Code:Friday /opt/mike.Friday
/opt/mike.Friday.xml
what gives?
- 11-14-2008 #2Linux Newbie
- Join Date
- May 2007
- Posts
- 106
to summarize: any time the variable $TODAY is called the rest of the filename is dropped.
- 11-15-2008 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
You're having trouble with newlines -- too many in some places, not enough in others.
If you look carefully at your output, you'll almost certainly see that ".xmp" was printed, but on a separate line. That's because when you got the string from date it included a newline. You can use the chomp function to remove it.
When you print, include "\n" to add a newline, typically at the end of whatever it is you wish to print.
See perldoc -f chomp, etc., for details.
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 11-18-2008 #4Linux Newbie
- Join Date
- May 2007
- Posts
- 106
thanks for the suggestion, I've been slammed this week so I haven't had a chance to test, but I will asap
thanks again, I'll let you know what I find
- 11-21-2008 #5Linux Newbie
- Join Date
- May 2007
- Posts
- 106



