satish.rpr has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am working on a perl script that was written on linux. I am using EPIC on windows to make changes to the above script.The author has used grep commands extensively througout the script to get some data. My problem is, when I run the script using EPIC, it does not execute as expected. I am using the cygwin's perl interpreter (perl 5.10.0) and have set the interpreter type to cygwin in EPIC settings. `grep -e '<regular expression>' filename > output_filename` executes well in EPIC with above mentioned settings, but @some_array = `grep -e '<regular_expresion>' filename` does not execute, i.e tha array is not populated.The above script works well on linux. any help ? thanks in advance

Content restored by GrandFather

Replies are listed 'Best First'.
Re: EPIC grep
by bart (Canon) on Jul 02, 2009 at 08:50 UTC
    Shell quoting on Windows is different from shell quoting on Unix. Could that be your problem?

    Windows uses double quotes for shell quoting, whereas a single quote is a plain character.

    Although, admittedly, I don't know what Cygwin perl uses for shell.

      cygwin uses unix style, sh (or bash) but you can still invoke cmd.exe
Re: EPIC grep
by tprocter (Sexton) on Jul 02, 2009 at 11:29 UTC
    This sounds like a symptom of someone writing perl code that knows shell programming better than perl programming. As a perl script, you should be using perl features instead of system features. It will make it more portable and more efficient.

    open (my $fh, '<', 'filename') or die $!; @some_array = grep /regular_rexpression/, <$fh>; close $fh; # process results...

    This slurp method will load the entire file into memory, so if the files could get large, then you should iterate line-by-line.