[ANN] p5scm 0.1.0

On the Linux systems I have head doesn’t append any trailing %. I don’t see how that would be useful and why the FreeBSD version of head would do so. Adding a call to awk as you suggest also works on Linux. I have little familiarity with awk but it doesn’t seem right to be using sed and awk together when either should work.

Two thoughts:

  1. I know that awk in particular behaves differently on different UNIX systems. You might want to require GNU awk.
  2. This is a good reason to use Perl5 – which is the same everywhere. It’s why I use Perl for scripting such as you cite above.
  3. Others have suggested that I rewrite these Perl scripts in OCaml, and I cannot fault them for this: OCaml would also fit the bill. I don’t do so, b/c that would obscure the meaning of the scripts and make it more-likely that there are errors. But others may find differently on this question.

A test :
echo “4.13.1” > a
echo “4.13.1” | head -c 6 >b
a is 7 characters long
b is 6 characters long
diff a b
1c1
< 4.13.1

4.13.1

I think the % was the representation of the absence of a newline.

Is this what you want ?

$ perl -e '$x = $ARGV[0]; $x =~ s,\.[0-9]+$,\.X,; print $x' 1.2.3 ; echo
1.2.X
$ 

Or, here is a Makefile that you can copy from:

VERSION = $(shell ocamlc --version)
VERSION0 = $(shell perl -e '$$x = $$ARGV[0]; $$x =~ s,\.[0-9]+$$,\.X,; print $$x' $(VERSION))

all:
	echo $(VERSION)
	echo $(VERSION0)

and to run:

$ make
echo 4.13.1
4.13.1
echo 4.13.X
4.13.X
$ 

Notice the doubling of “$” to pass Make syntax.

Running that script returns :

make (bsd-make)

echo

echo

gmake (gnu-make)
echo 4.13.1
4.13.1
echo 4.13.X
4.13.X

I believe I have sorted this out via OCaml which is up now on github. If I’d seen the followup below I’d likely have just copy and pasted in your Perl code since it is already a dependency of camlp5.