Using root objects in Perl

I have written a perl script and would really like to use the TString class in it, it’s mainly the usefulness of the Contains() method that I want to take advantage of. Is there a simple way of accomplishing this?
I could just use the perl regex matching but I end up with rather large, confusing looking if statements and tend to make mistakes quite often as a consequence.

As a quick example of the kind of stuff I’m hoping to implement:


# read in ps x output, to see if run.sh is running

$running = 0;
@input = `ps x`;
for(int i=0; i<@input; i++)
{
 TString jobs = $input[$ia];
 if (jobs.Contains("run.sh") and (!jobs.Contains("grep"))){
   $running = 1;
 }
}

Is this, or something similar, possible?

Hi,
shouldn’t this do it? my $running = 0; my @input = `ps x`; foreach $ps (@input) { $running = ($ps =~ m/run\.sh/) && (!($ps =~ m/grep/)); }
I’m pretty sure though that your algorithm does not what you want it to do - it will almost always set running to 0. You probably need a last statement. Depending on the flavor of your ps, you could (for this use case) just do my $running = `ps -C run.sh`;
Cheers, Axel.

[quote=“Axel”]Hi,
shouldn’t this do it? my $running = 0; my @input = `ps x`; foreach $ps (@input) { $running = ($ps =~ m/run\.sh/) && (!($ps =~ m/grep/)); }
I’m pretty sure though that your algorithm does not what you want it to do - it will almost always set running to 0. You probably need a last statement. Depending on the flavor of your ps, you could (for this use case) just do my $running = `ps -C run.sh`;
Cheers, Axel.[/quote]

Thanks, the ‘ps -C’ command makes some tasks much easier. But, the sample here was a simple example, in general would it be possible to use root objects like TString, for example, in perl scripts?

Hi,
I believe there has been at least one attempt to provide perl bindings for ROOT. See e.g. root.cern.ch/phpBB2/viewtopic.php?p=7899
Cheers, Axel.