in reply to FileOperation.pl
As for things that could be improved:
Here's an alternative version that shows what I'm talking about (and a few other adjustments):
(updated to add "die" traps on the "rename" calls)#!/usr/bin/perl -- use strict; die "We don't seem to be in the right directory.\n" unless ( -d 'inboundd' and -d 'DN_Dump' and -d 'MO_Dump' ); my @datfiles = <inboundd/*.dat>; die "No inboundd/*.dat files were found. We must be done.\n" unless ( @datfiles ); local $/; # set input record separator to "undef" for my $GetFile ( @datfiles ) { ( my $PutFile = $GetFile ) =~ s{inboundd/}{}; if ( $PutFile =~ /^DN_/ ) { rename $GetFile, "DN_Dump/$PutFile" or die "Can't move $GetFil +e to DN_Dump: $!"; next; } open( CHECKBOOK, $GetFile ) || die "$GetFile: $!"; my $InString = <CHECKBOOK>; close CHECKBOOK; rename $GetFile, "MO_Dump/$PutFile" or die "Can't move $GetFile to + MO_Dump: $!"; # GETTING THE FILE OUT AND FORM MO if (( my @InArrData = split( /,/, $InString )) >= 9 ) { my ( $Mobile, $Msg, $Short, $Vendor, $Inbound ) = @InArrData[1,5,6,7,9]; $Msg =~ s/[0-9a-f]{2}/chr(hex($1))/egi; print "mo:$Mobile:$Short:$Inbound:$Vendor:$Msg\n"; } }
I don't really know what those *.dat files contain. I'm taking your word for it that applying "split /,/" to the file content will always produce exactly the set of values, in the exact order, required by your list of assignments: no unexpected commas within quoted CSV fields, no extra lines of commentary (with commas) before the expected data, no leading or trailing whitespace that would mess up the output string, and so on. (Usually, I'd be less trustful of data file contents.)
|
|---|