I wrote this function...the concept is simple but hey I am a perl newbie, so it doesn't really work as intended. The function is supposed to be passed a path name, check to see if the file exists, and pipe the output from a cat function (of that file) to a new file (which is saved into a predetermined directory). Now, here is my broken function:

sub find_files { my $file_name = shift; my $path = qx/pwd/; print $path; my $file = basename($file_name); open(my $FILE_H, '>', "$path/$file"); #|| + + # die "Unable to open file: $!"; + + if(defined(qx/test -e $file_name; echo $?/)) { my $file_data = qx/cat $file_name/; print $FILE_H $file_data; } else { print "here"; print $FILE_H "Unable to find file name: $file_name"; } close($FILE_H); }
my @file_name_array = ( "/proc/cpuinfo", "/proc/meminfo", "/etc/fstab", "/proc/net/pf_ring/info", "/var/log/boot.log", "/etc/sysconfig/network-scripts/ifcfg-eth0", "/etc/sysconfig/network-scripts/ifcfg-eth1", "/etc/sysconfig/network-scripts/ifcfg-eth2", "/etc/sysconfig/network-scripts/ifcfg-eth3", "/etc/sysconfig/network-scripts/ifcfg-eth4", "/etc/udev/rules.d/70-persistent-net.rules" );

In reply to Broken Function by carlriz

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.