ClearCase.ClearTool returns No view context available error


You need to make sure your $view is a valid dynamic view tag for cleartool startview to work.
(make sure to not use cleartool setview, as it spawns a subshell)

Also if it returns error 0, you can assume it has worked: CAL might return an "error", but status 0 should mean the command has been executed.

An error different from 0, though, means something went wrong.

And you need to cd into that view (/view/<viewTag> or m:\<viewTag>) for a cleartool descr to work.
That one, executed in the wrong folder, is supposed to fail, hence "error 2".

The OP Jirong Hu points in the comments to Using Perl with Rational ClearCase Automation Library (CAL) and this script as an example.