CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [sh.ajay12] Urgent ( search a file for a line ): Edit Log



FishMonger
Veteran / Moderator

Nov 8, 2008, 8:44 AM


Views: 3986
Re: [sh.ajay12] Urgent ( search a file for a line )

Please take note on who's responding to you. It's fishMonger, not Kevin.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Tie::File;

open my $template, '<', 'key_value' or die "Can't open 'key_value' $!";
tie my @auto_it, 'Tie::File', 'auto_it' or die "Can't open 'auto_it' $!";

my %template;
while ( <$template> ) {
chomp;
my ($key, $value) = split /=/;
$template{$key} = $value;
}

(tied @auto_it)->defer;
for ( @auto_it ) {
$_ = "$1$template{$2}" if /^(.+)(k\d+)$/ and exists $template{$2};
}
untie @auto_it;



(This post was edited by FishMonger on Nov 8, 2008, 8:45 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Nov 8, 2008, 8:45 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives