[ic] Usertag return value

Peter peter at pajamian.dhs.org
Thu Feb 5 23:30:20 UTC 2009


On 02/05/2009 03:11 PM, Davor Ocelic wrote:
> $ret= 0;
> do_resize1(...) or $ret+= 1;
> do_resize2(...) or $ret+= 2;
> do_resize3(...) or $ret+= 4;
> return $ret;
> 
> So if the tag exits with 0, it worked. Otherwise, the exit
> status will be a sum of all resizes that failed. I.e. if 
> exit value is 5, it means resizes 1 and 3 failed.

An easier way to see that might be:
do_something("foo") or $ret += 1 << 0;
do_something("bar") or $ret += 1 << 1;
do_something("baz") or $ret += 1 << 2;
...etc

return $ret;

What's good about this is if foo, bar and baz are filenames stored in an
array, ie:

my @filenames = qw(
	foo
	bar
	baz
);

...you can actually do this:

my $ret = 0;

foreach (0 .. #@filenames) {
	do_something($filenames[$_]) or $ret += 1 << $_;
}

return $ret;


...then after running the tag:

foreach (0 .. #@filenames) {
	if ($ret & 1 << $_) {
		Log ("Error writing to file $filenames[$_]");
	}
}


Well, you get the idea.


Peter





More information about the interchange-users mailing list