#!/usr/bin/env perl use strict; use warnings; # Simulate Tie::File array my @config_file = map { chomp; $_ } ; print_config('Initial config'); for (@config_file) { $_ = /^\s*terminal\b/ ? change_value(terminal => $_) : /^\s*editor\b/ ? change_value(editor => $_) : /^\s*names\b/ ? get_tags($_) : $_; } print_config('Final config'); sub change_value { my ($key, $line) = @_; print "Current: $line\n"; print 'Change (Enter to keep): '; chomp(my $new_value = <>); if ($new_value) { $line =~ s/^(\s*$key\s*=\s*")[^"]+("\s*)$/$1$new_value$2/; } return $line; } sub get_tags { my $line = shift; $line =~ /^\s*names\s*=\s*{\s*([^}]+)/; (my $names = $1) =~ y/" //d; my @tags = split /,/ => $names; print "TAGS: @tags\n"; return $line; } sub print_config { my $heading = shift; print '=' x 64, "\n"; print "$heading\n"; print '-' x 64, "\n"; print "$_\n" for @config_file; print '=' x 64, "\n"; return; } __DATA__ -- This is used later as the default terminal and editor to run. terminal = "urxvt" editor = "vim" -- Define a tag table which hold all screen tags. tags = { names = { "Main", "WWW", "GIMP", "EMail", 6, 7 },