in reply to Re^3: Question on the format statement
in thread Question on the format statement

Thank you :)

Probably should have read some more before posting. Well the code does not work if some of the fields are left undefined i.e. this section of code:
$consname = "" if !defined($consname); $subdvn = "" if !defined($subdvn); $chequeno = 0 if !defined($chequeno); $receiptno = 0 if !defined($receiptno); $amount= 0 if !defined($amount);
Sample data:
M/s. Something Pvt. Ltd.!Elm Street!134!27456.00 ---no cheque no. Somethin&Someone!New Park Street!29787!135!28477.00 Something-Something!Washington!136!28476.00 ---no cheque no. Someone!Pole Street!38947!137!28376.00
Also for variable length fields e.g, $consname,$subdvn, the space between the columns in the report is not adjusted.
If the report contained several rows of data formatting the space between columns would be tedious. Is there a solution to this?

Replies are listed 'Best First'.
Re^5: Question on the format statement
by roboticus (Chancellor) on Apr 06, 2010 at 13:48 UTC

    perl seeker:

    I don't quite follow--I just added your sample data to the program, ran it, and don't see a problem. When you say "the code does not work if some of the fields are left undefined", what do you mean exactly? I'm not seeing any problems.

    Regarding your comment on the space between columns not being adjusted, I don't know what you mean. Do you mean that the column headers don't match the numbers? If so, just adjust your format statements a bit. Or do you want all the columns to spread apart if one of the columns is wider than expected and shrink when a column is narrower than expected? If so, that's a bit more complicated...

    ...roboticus

      "Some of the fields are left undefined": These are the col headers-

      Consumer name Subdivision Cheque no. Receipt no. Amount

      And this a sample row of data-

      M/s. Something Pvt. Ltd.!Elm Street!134!27456.00

      The field left undefined in this row of data is the cheque number(for cash payments)

      If some column data is missing in this way the output report I get is all jumbled up. In the format statements I've just assigned the possible max no of characters for each field.But the data tends to vary in length for ex. the consumer name could be:
      @<<<<<<<<<<<<<<<<<<<<<<< M/s. Something Pvt. Ltd Somethin&Someone Something-Something Someone
      The names are of different lengths and none are as long as the max defined no. of characters.
      The same could happen for other fields. In such a situation is it possible to get the column headers and data below to match, like in a tabular format?
      Expected output:
      Col1 Col2 Col3 Col4 Someone 26354 151 27364.00 M/s Something 152 234.00 Mr. xxx 36454 153 4856679.00 Mr.yy 154 3645.00 Mr.Z 2675 155 23459.00

        perl seeker:

        Oh, I see what you're asking now. For a delimited file, you usually don't leave out the delimiters. In other words, I wouldn't expect to see this:

        M/s. Something Pvt. Ltd.!Elm Street!134!27456.00

        Rather, I would expect to see (notice the extra !):

        M/s. Something Pvt. Ltd.!Elm Street!!134!27456.00

        In this version, you get the correct number of fields, with a blank cheque number. If the format is under your control, I'd suggest always having the correct number of delimiters. Otherwise you won't be able to reliably tell the difference between the fields--how would you determine it was the cheque number that was missing rather than the receipt number?

        ...roboticus