Wednesday, June 11, 2008

Read data from a file in perl

Below is the sample perl script, if you want to read some data from a file and pass it to as a argument in your perl script.

In my case, I have some object ids in a file and for each id I have to run oocheck command.

#!/usr/local/bin/perl

open FILE, "testoids" or die $!;

while ()

{

chomp $_;

systemCmd("oocheck -id $_");

}

close(FILE);

sub systemCmd {

my($cmd) = @_;

print("$cmd\n");

(system($cmd) == 0) || die ("cmd $cmd failed");

}

No comments: