Adding a perl script to automator

Hi

I have a script that do a search and replace in a file in Perl. This script work just fine when executed from the command line, but in automator it result in an empty file.

Any idea?

Eventually I want to replace the $file variable with the arguments passed from previous actions, but for now I'm "in debug mode" only.

Here is the basic of the script:

my $file="full Unix path to file";
my $search="that text";
my $replace="this text";

my @contents;

open (F, $file) || die "Can't open - $!\n";
@File = <F>;
close (F);

open (F, ">$file") || die "Can't open - $!\n";

for (@File) {
s/$search/$replace/g;
push(@contents,$_);
}

# Go to the beginning of the file
seek(F,0,0);

# Update the contents with the data from our array
print F (@contents);
close(F);

PowerBook 12 1.33 768meg RAM, Mac OS X (10.4.4), iLife 06

Posted on Feb 21, 2006 4:43 PM

Reply
5 replies

Feb 22, 2006 12:52 PM in response to Jeffrey Jones2

Not sure to understand your answer, but if I really understand that is:

running it from a file work (for me too)

running it from an shell script action from the previous file work (did not try that one)

but running the script in a shell script by choosing perl as the command interpreter do not work (same for me) and that's exactly my problem.

How it is possible to integrate shell script in perl if that just does not work!

Feb 24, 2006 6:28 AM in response to Steve-Mac-

Hi,

It looks like the script action for Perl in Automator is buggy...

- First, when I select perl in the shell selection, save the workflow, close it then reopen it, the revert back to bash! This cannot work for sure for Perl...

- Also, from what I can see in the debug tests I made, that is the push command that does not work correctly. Instead of pushing the value of $_ (current file line in this case) it add blank (nothing) to the $contents variable. That's why the file goes empty at the end.

So that's really a bug in Automator, as I cannot see any other reason, the scrpt works well in standalone mode (from terminal).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Adding a perl script to automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.