my $head = system head => -1 => $in_file; # Grab header/first line of file

system does not return the output of the command, it returns its exit code. There are ways to get the output in Perl*, but I would instead recommend opening and reading the file using the tools built into Perl (see e.g. Files and I/O):

use warnings; use strict; my $ENCODING = ":encoding(UTF-8)"; die "Usage: $0 FILENAME\n" unless @ARGV==1; check_file($ARGV[0]); sub check_file { my ($in_file) = @_; open my $fh, "<$ENCODING", $in_file or die "Failed to open $in_file: $!\n"; my $head = <$fh>; close $fh; if ( $head =~ m/^ABC/ ) { print "This is a ABC File. Processing ABC File...\n"; prcss_abc_file($in_file); } elsif ( $head =~ m/^ISA~ / ) { print "This is an EDI File. Processing EDI File...\n"; prcss_edi_file($in_file); } else { print "I don't know this file type! Attempting to process BTN. +..\n"; prcss_btn($in_file); } }

(* For example backticks, but as I wrote about at length here, I wouldn't recommend it for this task. If you really wanted to capture the output, at least use capturex from IPC::System::Simple.)

Update: Note that I am just guessing as to the purpose of the $encoding variable in the code you showed.


In reply to Re: Matching patterns in condisional statements by haukex
in thread Matching patterns in condisional statements by smturner1

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.