Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Increasing a field size for a record

by zwon (Monsignor)
on Oct 16, 2012 at 15:38 UTC ( #999357=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Increasing a field size for a record
in thread Increaing a field size for a record

That's a funny approach, but is not very efficient, every time you're assigning to $line[$i] it rewrites all the file starting from the record $i.

Update: More efficient would be to use File::Slurp:

use strict; use warnings; use File::Slurp qw(edit_file_lines); sub fix { my @fields = split / +/; $fields[1] = sprintf "%-50s", $fields[1]; $_ = join ' ', @fields; } edit_file_lines \&fix, $file_name;
The problem is that it doesn't preserve the width of the other fields


Comment on Re^3: Increasing a field size for a record
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2015-07-07 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls