carlriz has asked for the wisdom of the Perl Monks concerning the following question:
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" );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Broken Function
by choroba (Cardinal) on Apr 04, 2014 at 13:21 UTC | |
by Anonymous Monk on Apr 05, 2014 at 08:23 UTC | |
|
Re: Broken Function
by Happy-the-monk (Canon) on Apr 04, 2014 at 13:22 UTC | |
|
Re: Broken Function
by BrowserUk (Patriarch) on Apr 04, 2014 at 13:22 UTC | |
by carlriz (Beadle) on Apr 04, 2014 at 13:34 UTC | |
by Anonymous Monk on Apr 04, 2014 at 14:35 UTC |