in reply to Converting Binary Numbers into Binary File
This deserves a one-liner:
perl -ne "$i++ || binmode(STDOUT);chomp;print pack(q/B*/,$_);" infile +>outfile
This is untested, but ought to work fine. It might be golfed down a bit if you allow it to set binmode on each iteration instead of only on the first iteration, and if you incorporate the -p switch instead of -n (which in this case, I believe hampers the legibility of the code):
perl -pe "binmode STDOUT;chomp;$_ = pack(q/B*/,$_);" infile >outfile
My biggest complaint with the golfed version is that it calls binmode on each iteration, which is unnecessary.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting Binary Numbers into Binary File
by shmem (Chancellor) on Sep 13, 2006 at 16:56 UTC | |
by ikegami (Patriarch) on Sep 13, 2006 at 17:22 UTC | |
by borisz (Canon) on Sep 14, 2006 at 08:32 UTC | |
by shmem (Chancellor) on Sep 15, 2006 at 21:23 UTC | |
by shmem (Chancellor) on Sep 13, 2006 at 20:48 UTC |