#!/usr/bin/perl use strict; use warnings; use Data::Dumper; foreach my $file (glob("*.ATT")) { open(my $fh, '<', $file) or die "$file: $!"; my $content = do { local $/; <$fh> }; close($fh); my ( $page_id ) = $content =~ m/^page_id=(.*)/m; my ( $site_code ) = $content =~ m/^site_code=(.*)/m; my ( $subject_id ) = $content =~ m/^subject_id=(.*)/m; my ( $page_description ) = $content =~ m/^page_description=(.*)/m; #if value is non-alphanumeric it skips this file next if( ($page_id =~ m/[^a-zA-Z0-9]/) || ($site_code =~ m/[^a-zA-Z0-9]/) || ($subject_id =~ m/[^a-zA-Z0-9]/) ) {die}; #all versions of these numbers results in those descriptions. if ($page_id = "27.*") {$page_description = "GRAPHICS"}; if ($page_id = "21.*") {$page_description = "GENERAL COMMENTS"}; if ($page_id = "24.*") {$page_description = "DATA IS CLEAN"}; if ($page_id = "22.*") ($page_description = "PICTURES"}; then; $content =~ s/^page_description=.*/page_description=$page_description/m; print "$content"; #saves the updated text file? close(OUT);