Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Modifying data in variable length file

by nsyed (Novice)
on Apr 27, 2011 at 22:18 UTC ( #901671=perlquestion: print w/replies, xml ) Need Help??

nsyed has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Sorry for asking a very basic question. I am trying to do the following with a test.DAT file. The file contains data in various columns that I want to replace to a constant or a random value. However in some cases there might be no data for that particular field length.

Problem:

Start Colum = 161 End Column = 190 , If there is text set to value MYTEXT

Start Column = 221 End Column = 230 , If there is text set to value 01/01/1980

Start Column = 231 End Column = 245 , If there is text set to value random 15 numbers

And leave everything else unchanged. Thanks you so much in advance.

Replies are listed 'Best First'.
Re: Modifying data in variable length file
by wind (Priest) on Apr 27, 2011 at 22:28 UTC

    Use Tie::File to manipulate each line of the file, and substr to access the columns you want to change.

Re: Modifying data in variable length file
by Tanktalus (Canon) on Apr 27, 2011 at 22:26 UTC

    What have you tried? What does your data look like?

    Define "if there is text" - does that mean "if the line is this long"? Are spaces text? Because "variable length" and "strict column definitions" seem at odds to me.

Re: Modifying data in variable length file
by Anonymous Monk on Apr 27, 2011 at 22:26 UTC
Re: Modifying data in variable length file
by nvivek (Vicar) on Apr 28, 2011 at 04:48 UTC
    Tell how the columns are separated and what the delimiter is? Express your question with defined manner and if possible give example data. It will make you to get answer soon.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2021-03-05 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (115 votes). Check out past polls.

    Notices?