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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |