It should work on Perl 5. I will accept patches to maintain compatibility for such older Perls, but you may need to fix it on 5. Not tested on VMS although there is platform specific code for those. Anyone who haves a second would be very kind to send me a report of how it went. This combination may be overkill for applications which do not need IPC::Cmd 's complicated interface for running programs, or do not need the memory overhead required for installing Perl modules.
At least some older versions will find executables in the current directory, even if the current directory is not in the search path which is the default on modern Unix. This is frequently useful for tools that just need to run something using system in scalar mode, but may be inconvenient for tools like App::pwhich where user readability is a premium.
This module purports to "check that a command is available", but does not provide any documentation on how you might use it. For more information on module installation, please visit the detailed CPAN module installation guide. Implementations File::Which searches the directories of the user's PATH the current implementation uses File::Spec path to determine the correct PATH , looking for executable files having the name specified as a parameter to "which".
Cygwin Cygwin provides a Unix-like environment for Microsoft Windows users. VMS Same case as Windows 9x: uses. If it does not find the executable, it returns undef. If which is called in list context, it will return all the matches. Included as part of the Perl core as of 5. Devel::CheckBin Requires Perl 5. To install File::Which, copy and paste the appropriate command in to your terminal. If that's all we need to do, can just use the existing Unix grep command.
It is much more interesting when we need to process certain lines of a file. For example in a log file of a web server we would like to collect the IP address of of the clients who visited a specific page. For this we would need to go over the lines of the file, as we do it above, but instead of printing the line we would break it into parts, extract the IP address and put it in a hash.
We'll see such an example in a separate article. Written by Gabor Szabo Published on Toggle navigation Perl Maven. How to grep a file using Perl grep regex. Written by Gabor Szabo. If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub. Comment on this post. Gabor can help refactor your old Perl code-base. Improve this question. Peter Mortensen Haritz Haritz 1, 7 7 gold badges 31 31 silver badges 48 48 bronze badges.
Instead of "Can't open That works fine if mydirectory exists in the current working directory and you have permission to create in it. Yes, this code works fine for me. Another thing to check: are you sure that Perl's current working directory is what you think it is? Check with CWD: perldoc. Add a comment. Active Oldest Votes. If not create it. Improve this answer.
Demnogonis Demnogonis 3, 5 5 gold badges 29 29 silver badges 45 45 bronze badges. This might make the script run without dying, but it doesn't diagnose and solve the actual problem.
0コメント