in reply to Format weird behaviour
First, let me say ugh. What are you using to parse this that it requires fixed length fields? Secondly, shouldn't you have closing tags starting with / instead of \?
Now how to fix your problem. It's pretty simple. If you output what is going to be evaluated, you'd realize that format will see @<<<<<<<\product. So it's misinterpreting what you really want. Replace the < that you want to show up with an @ and add "<" to the list of variables to fill it in. For more information on this, perldoc perlform.
$item="heat741a"; #for the sake of the example I fixed the variables $OrderQty = 55; open(LOG, ">order.xml") || die "Can't open the log file: $!\n"; $format = "format LOG = \n" . "\<\?xml version\=\"1\.0\"\?\>" . "\n" . "\<order\>" ."\n" . "\<product\>" .'@' . '<<<<<<' . '@' . "\\product\>" . "\n" . '$item,"<"' . "\n" . "\<quantity\>" .'@' . '<' x (length($OrderQty)-1) . '@' . "\\qua +ntity>" . "\n" . '$OrderQty,"<"' . "\n" . "\<\\order\>" ."\n" . ".\n"; eval $format; write LOG; close LOG;
Hope that helps.
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Format weird behaviour
by Anonymous Monk on Jun 11, 2003 at 04:08 UTC | |
by antirice (Priest) on Jun 11, 2003 at 04:57 UTC |