Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

how can i increase the size of a record in a file

by rajsai28 (Novice)
on Feb 07, 2013 at 06:19 UTC ( #1017568=perlquestion: print w/ replies, xml ) Need Help??
rajsai28 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, '|' field delimeter. I am writing the input to the file by using a field delimiter. when i see the output file, The output file looks like( where the output scattered on the more than one line:
00002|GR_TESTING_Release|00001|0000997|3500243| 5909|20121115|2012111|TESTING |CHECK
output:
00002|TESTING|00001|0000004|0000006|0001|11111111||11111111|ABCDEFH||| +|9999999999|ABCDEF|ABCDK|ABCD|ABCDEF |||||||||||||||||||||0001-01|AB|TESTING|||||||AB|ABC|ABC|CHECK
but i want file ouput as below: In single line.
00002|GR_TESTING_Release|00001|0000997|3500243|5909|20121115|2012111|T +ESTING|CHECK
expected:
00002|TESTING|00001|0000004|0000006|0001|11111111||11111111|ABCDEFH||| +|9999999999|ABCDEF|ABCDK|ABCDEF|ABCD|||||||||||||||||||||5909-01|IW|A +LDEA|||||||AB|ABC|ABC|||||||||||CHECK

Comment on how can i increase the size of a record in a file
Select or Download Code
Re: how can i increase the size of a record in a file
by vinoth.ree (Parson) on Feb 07, 2013 at 06:38 UTC

    Its Already in single line only. I do not think I understood your problem clearly, could you please elaborate your requirement?

Re: how can i increase the size of a record in a file
by Athanasius (Monsignor) on Feb 07, 2013 at 06:57 UTC

    Hello rajsai28, and welcome to the Monastery!

    Like vinoth.ree, I don’t know what you are asking. So I’ll just make two observations:

    1. If the fields can contain the separator character |, then the output is meaningless because there is no way to tell where one record ends and the next begins. But if they can’t contain that character, then the output shown cannot have come from the print statement shown, because the former contains 60 such characters but the latter only 21.

    2. You can save yourself a lot of typing by using join:

      16:41 >perl -Mstrict -wE "my @recs = (1, 'a', 2, 'z'); print STDOUT jo +in('|', @recs), qq[\n];" 1|a|2|z 16:44 >

    Hope that helps,

    Update: The question as originally posted contained the following print statement:

    print DETAIL $Record_Detail_id."|".$NUMBER."|".$NUMBER1."|".$NUMBER2." +|".$NUMBER4."|".$NUMBER5."|".$NUMBER6."|".$NUMBER12."|".$State_Provin +ce_Code."|".$Org_Id."|".$Vendor_Name."|".$Dummy_Field_7."|".$Dummy_Fi +eld_8."|".$Dummy_Field_9."|".$Dummy_Field_10."|".$Dummy_Field_11."|". +$Dummy_Field_12."|".$Dummy_Field_13."|".$Dummy_Field_14."|".$Dummy_Fi +eld_15."|".$Dummy_Field_16."|".$Action_time_stamp."\n";

    It was this to which my reply referred.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: how can i increase the size of a record in a file
by Kenosis (Priest) on Feb 07, 2013 at 07:00 UTC

    The output string you shared has a length of 212, which is 40 fewer than the record size of 252--and you have exactly 40 empty fields, i.e., ||, in that string. If you filled each empty field with a character, e.g., an "X", you'd have a 252-byte record. Is this what you want to do? Since the records are | delimited, why does each record need to be 252 bytes?

    If you do want to fill all the empty fields with an "X" (or some other character) you can do the following with the string:

    $string =~ s/(?<=\|)(?=\|)/X/g;

    However, it would be far better to address the data in your variables before creating that string.

    My apologies if I've misunderstood your problem.

    Update I: Athanasius makes an excellent point about the "|" character; I merely assumed it was the field delimiter.

    Update II: Eliminating elements in your original posting makes your issue(s) a moving target and nullifies some responses; e.g., you've removed the record-size 'problem.' Nevertheless, your reformatting evidences a newline in one of your variables, and by the break in your output string, you should be able to tell which variable and then remove the newline.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1017568]
Approved by Kenosis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-12-18 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (49 votes), past polls