Maybe this will help you out
#!/usr/bin/perl -w
use strict;
my @serialNums = ();
my @macAddrs = ();
while(<DATA>) {
my @a = ( /SA......./g );
for( my $i=0; $i <= $#a; $i++ ) {
push( @serialNums, $a[$i] );
}
@a = ( /00:..:..:..:..:../g );
for( my $i=0; $i <= $#a; $i++ ) {
push( @macAddrs, $a[$i] );
}
}
foreach my $s ( @serialNums ) {
print "s=[$s]\n";
}
foreach my $m ( @macAddrs ) {
print "m=[$m]\n";
}
__DATA__
Dear Monks,
Please be kind...
I have a file that looks something like this:
SABFBXGNP^@00:01:A6:D9:AF:D4^@^L^\^@^2^@A|@SABFBXGTG^@00:01:A6:D9:B0:8
+E...
The first part, SA......., is a serial number and the second part, 00:
+..:..:..:..:.., is the corresponding MAC
address. There are no delimiters (save for the ^@ and ^@^L^\^2^@A|@),
+whitespaces, returns or new lines
in the file.
My question is this: As I will need to run this on a similar file each
+ month or so, what is the most flexible
way for me to turn this mess into a hash, assuming the serial numbers
+will always begin with SA, the MAC
addresses will begin with 00: and both will remain a consistent number
+ of characters (not sure if the
'delimiters' will remain the same in each version of the file)?
THANK YOU!
Here's the output ...
$ ./getStr.pl
s=[SABFBXGNP]
s=[SABFBXGTG]
s=[SA.......]
s=[SA, the M]
m=[00:01:A6:D9:AF:D4]
m=[00:01:A6:D9:B0:8E]
m=[00:..:..:..:..:..]
|