From: Seansan on
Hi there,

I am trying to read a bank file with a format called MT940 swift into a
data structure. The format is as follows:

:28C:12345/1
:60F:C041019GBP607,20
:61:041020C110088,00N540NONREF

I am still learning unpack (I always used s/regex/ and then $1, $2, etc ..)
and am wondering if someone can help me decode one of these lines e.g. the
:60F: record. Is it even possible? The format =
:<record>:<date,6chars><str,3><amount,0-32>

ps. Does anyone know of a swift/mt940 module or have a script you can share?
I searched everywhere but didnt find usefull information.

Kind regards, Seansan



From: Dave Weaver on
Seansan <sheukels=cuthere=(a)yahooo.co.uk> wrote:
> I am trying to read a bank file with a format called MT940 swift
> into a data structure. The format is as follows:

> :28C:12345/1
> :60F:C041019GBP607,20
> :61:041020C110088,00N540NONREF

That isn't a format specification, it's just a sample of the data. We
can only guess (probably incorrectly) what the format is from a sample
data set. Especially one so brief.

> I am still learning unpack (I always used s/regex/ and then $1, $2,
> etc ..)
^
ITYM m/regex/
The regex approach seem best suited to this data, from what I can see
of it.

> and am wondering if someone can help me decode one of these lines
> e.g. the :60F: record. Is it even possible? The format =
> :<record>:<date,6chars><str,3><amount,0-32>

No it isn't. Let's take another look at that line:

> :60F:C041019GBP607,20

What's that 'C'? Doesn't look like it's part of the date.
And the amount after "GBP" is not in the range 0-32.
Ignoring that:

#!/usr/bin/perl
use strict;
use warnings;

while( <DATA> ) {
if ( /:([^:]+):C(\d{6})(...)(\d+)/ ) {
print qq(record: "$1" date: "$2" str: "$3" amount: "$4"\n);
}
}

__DATA__
:28C:12345/1
:60F:C041019GBP607,20
:61:041020C110088,00N540NONREF


this prints:
record: "60F" date: "041019" str: "GBP" amount: "607"

As you can see, your suggested format matches only one of those 3
records ( and then, only if ignoring that 'C' ).

I suggest you determine your data format first. Then it's simply a
case of composing one or more regexs to extract the information you
require.

From: JayEs on
> I am trying to read a bank file with a format called MT940 swift into a
> data structure. The format is as follows:
>
> :28C:12345/1
> :60F:C041019GBP607,20
> :61:041020C110088,00N540NONREF
>


OT: Swift MT940... Oh boy that brings back memories. None of it any good :-)



 | 
Pages: 1
Next: Is there neq for strings?