use strict; use warnings; my ($user, $third, @data); $user = 'Thomas'; $third = 'newvalue'; chomp(@data = <DATA>); for (@data) { # Skip if user is not $user next if !m/^\Q$user\E\s*:/; # Change third field and exit loop @_ = split /:/, $_; $_[2] = $third; $_ = join ':', @_; last; } # Print data back to file (replace this) print $_, "\n" for @data; __DATA__ Username : Password : Download | Tom : 12345678 : Thomas : 12345678 : 121312313123131313
In reply to Re: adding an element in existing file..
by TedPride
in thread adding an element in existing file..
by bran4ever
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |