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
    antirice,

    It didn't work, i got a space. Using single quote in place of double quotes didn't work either: (if i write '</quantity>' i'll get /quantity>; and if i write '\</quantity>', i get \</quantity>)it's really getting weird.

    Tanx

      Ah, I never cleaned up the code and am reaping the rewards now. This post is pretty long, so I've used readmore to explain everything in detail.

      Sorry for not going into greater detail the first time.

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1