jagtar has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I am trying to make inline changes to the file(passed using Glob) I am doing like this, but i think it is not the best way to do it. In below code i have to use stdout redirection to a new local file, which i don't want to do. I need to make changes to the same file being passed by rm_spaces(\*FILE)
Thanks, Jagtaropen(STDOUT, "+>csv_add_up"); rm_spaces(\*CSVADD_FILE); close STDOUT; sub rm_spaces { my $file = shift; while (<$file>) { chomp; my @fields = split /,/; s/\s+//g for @fields; s/\/I\/0//g for @fields; s/\/T\/0//g for @fields; print join ",", @fields,"\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inline change to the file passed by Glob
by haukex (Archbishop) on Aug 23, 2017 at 05:35 UTC | |
by jagtar (Initiate) on Aug 23, 2017 at 05:45 UTC | |
by poj (Abbot) on Aug 23, 2017 at 06:52 UTC | |
by Anonymous Monk on Aug 23, 2017 at 06:40 UTC |