Reworked test files for better error reporting
[nasm/perl-rewrite.git] / perl / lib / Nasm / Utils.pm
blob8363e91526683d5e62fc4f80805cdd27d6db29d1
1 =head1 NAME
3 Nasm::Utils
5 =head1 DESCRIPTION
7 Several utilities used in other modules
9 =head1 Subroutines
11 =cut
13 package Nasm::Utils;
14 use strict;
15 use warnings;
17 use base 'Exporter';
19 our @EXPORT_OK = qw{
20 str2hex
21 addprefix
24 =head2 str2hex
26 Turn a numeric list into a hex string
28 =cut
29 sub str2hex{
30 my @return = map {sprintf("%02X", $_)} @_;
32 return @return if wantarray;
33 return join '', @return;
36 =head2 addprefix( $prefix, @list )
38 Takes a prefix, and a list of strings, and
39 adds the prefix to each element in the list
41 =cut
42 sub addprefix{
43 my ($prefix, @list) = @_;
44 my @return = map {
45 sprintf("%s%02X", $prefix, $_)
46 } @list;
48 return @return if wantarray;
49 die "Don't know what to do in scalar context.";