in reply to adding an element in existing file..
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
|
|---|