There's some room for improvement here. First, I have to confess that I don't know what "MO" refers to, and I don't think I'll ever have a set of directories called "inboundd", "DN_Dump" and "MO_Dump" with files called "*.dat" that have the particular arrangement of comma-separated values that your code expects. I don't want to discourage you, but in order for people to find this useful, there needs to be more explanation about how and why it might be useful.

As for things that could be improved:

Here's an alternative version that shows what I'm talking about (and a few other adjustments):

#!/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"; } }
(updated to add "die" traps on the "rename" calls)

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.)


In reply to Re: FileOperation.pl by graff
in thread FileOperation.pl by amyarjun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.