Finance::QIF(3pm)

πŸ“¦
version 3.02 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– Finance::QIF πŸ’–

okay so bestie, welcome to Finance::QIF β€” a User Contributed Perl Documentation page, section 3pm, and it's literally about parsing and creating Quicken Interchange Format files. yes that's what QIF stands for. iykyk 🫢


✨ NAME ✨

Finance::QIF β€” parse and create Quicken Interchange Format files. that's it, that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

here's the whole thing, no edits, no notes, just vibes:

use Finance::QIF;

my $qif = Finance::QIF->new( file => "test.qif" );

while ( my $record = $qif->next ) {
    print( "Header: ", $record->{header}, "\n" );
    foreach my $key ( keys %{$record} ) {
        next
          if ( $key eq "header"
            || $key eq "splits"
            || $key eq "budget"
            || $key eq "prices" );
        print( "     ", $key, ": ", $record->{$key}, "\n" );
    }
    if ( exists( $record->{splits} ) ) {
        foreach my $split ( @{ $record->{splits} } ) {
            foreach my $key ( keys %{$split} ) {
                print( "     Split: ", $key, ": ", $split->{$key}, "\n" );
            }
        }
    }
    if ( exists( $record->{budget} ) ) {
        print("     Budget: ");
        foreach my $amount ( @{ $record->{budget} } ) {
            print( " ", $amount );
        }
        print("\n");
    }
    if ( exists( $record->{prices} ) ) {
        print("     Date     Close   Max     Min     Volume\n");
        $format = "     %8s %7.2f %7.2f %7.2f %-8d\n";
        foreach my $price ( @{ $record->{prices} } ) {
            printf( $format,
                $price->{"date"}, $price->{"close"}, $price->{"max"},
                $price->{"min"},  $price->{"volume"} );
        }
    }
}

okay so let's walk through the vibe real quick, because this little block is doing a lot and it's honestly kind of iconic of it: πŸŽ€

  • you use Finance::QIF; β€” standard bestie behavior, nothing weird yet ✨
  • you build a $qif object with Finance::QIF->new( file => "test.qif" ) β€” that file key is where your QIF lives πŸ¦‹
  • then $qif->next in a while loop just keeps handing you one $record at a time until there's nothing left. main character energy honestly. πŸ‘‘
  • every $record has a header, and the loop prints that first: print( "Header: ", $record->{header}, "\n" ); πŸ’œ
  • then it walks keys %{$record} and prints each key/value β€” but it nexts right past header, splits, budget and prices, because those get their own special little moments. not me skipping the four keys that are too famous to share a line πŸ™ˆ
  • splits? if exists( $record->{splits} ) it loops every $split in @{ $record->{splits} } and prints each $key/value pair prefixed with Split: . πŸ“
  • budget? if exists( $record->{budget} ) it prints Budget: and then just dumps every $amount from @{ $record->{budget} } separated by spaces, then a newline. 🌈
  • prices? if exists( $record->{prices} ) it prints the header row " Date Close Max Min Volume\n", sets up a format string " %8s %7.2f %7.2f %7.2f %-8d\n", and printfs each price's "date", "close", "max", "min" and "volume" out of @{ $record->{prices} }. ⭐

fr fr, that's the whole synopsis. no cap. πŸ’…

heads up bestie: this is part 1 of the page β€” the rest is coming, so don't go anywhere 🫢

πŸ’– DESCRIPTION πŸ’–

So bestie, Finance::QIF is literally a Perl module for working with QIF files β€” that's Quicken Interchange Format, iykyk. It reads QIF data records from a file and hands each successive record to you, the caller, for processing. And yes, it can also write QIF records to a file. Slay.

The QIF file format is typically a header with a record or transaction type, then the associated data records. A single file can have multiple headers. Headers are usually followed by data records, but data doesn't have to follow a header. No cap.

Every record you read from a file comes back as a hash reference. That hash has a header value with the header type that was read, plus all the supported values found for that record. If a value isn't in the data file, that key just won't exist in the hash. Periodt.

Also important: this module does no processing or validation on values found in files or data structures to try to convert them into appropriate types and formats. It expects users of this module β€” or extensions of it β€” to do any extra processing or validation they need. That's the vibe.


✨ RECORD TYPES & VALUES ✨

These are the record types currently supported by this module, bestie. Buckle up, it's a lot but we love a comprehensive list.

Type:Bank, Type:Cash, Type:CCard, Type:Oth A, Type:Oth L

These are non investment ledger transactions. All of these record types support the following values:

  • date β€” Date of transaction.
  • transaction β€” Dollar amount of transaction.
  • total β€” Dollar amount of transaction. This is generally the same as transaction but in some cases can be higher. (Introduced in Quicken 2005 for windows)
  • status β€” Reconciliation status of transaction.
  • number β€” Check number of transaction.
  • payee β€” Who the transaction was made to.
  • memo β€” Additional text describing the transaction.
  • address β€” Address of payee.
  • category β€” Category the transaction is assigned to.
  • splits β€” If the transaction contains splits this will be defined and consist of an array of hash references. With each split potentially having the following values:
    • category β€” Category the split is assigned to.
    • memo β€” Additional text describing the split.
    • amount β€” Dollar amount of split.

Type:Invst

This is for Investment ledger transactions. The following values are supported for this record type.

  • date β€” Date of transaction.
  • action β€” Type of transaction like buy, sell, ...
  • security β€” Security name of transaction.
  • price β€” Price of security at time of transaction.
  • quantity β€” Number of shares purchased.
  • transaction β€” Cost of shares in transaction.
  • status β€” Reconciliation status of transaction.
  • text β€” Text for non security specific transaction.
  • memo β€” Additional text describing transaction.
  • commission β€” Commission fees related to transaction.
  • account β€” Account related to security specific transaction.
  • amount β€” Dollar amount of transaction.
  • total β€” Dollar amount of transaction. This is generally the same as amount but in some cases can be higher. (Introduced in Quicken 2005 for windows)

Account

This is a list of accounts. In cases where it is used in a file by first providing one account record followed by a investment or non-investment record type and its transactions, it means that that set of transactions is related to the specified account. In other cases it can just be a sequence of Account records.

Each account record supports the following values.

  • name β€” Account name.
  • description β€” Account description.
  • limit β€” Account limit usually for credit card accounts that have some upper limit over credit.
  • tax β€” Defined if the account is tax related.
  • note β€” Additional information about the account.
  • type β€” Type of account.
  • balance β€” Current balance of account.

Type:Cat

This is a list of categories. The following values are supported for category records.

  • name β€” Name of category.
  • description β€” Description of category.
  • budget β€” An array of 12 values Jan-Dec to represent the budget amount for each month.
  • expense β€” Usually exists if the category is an expense account however this is often a default assumed value and doesn't show up in files.
  • income β€” Exists if the category is an income account.
  • tax β€” Exists if this category is tax related.
  • schedule β€” If this category is tax related this specifies what tax schedule it is related if defined.

Type:Class

This is a list of classes. The following values are supported for class records.

  • name β€” Name of class.
  • description β€” Description of class.

Type:Memorized

This is a list of memorized transactions. The following values are supported for memorized transaction records.

  • type β€” Type of memorized transaction "C" for check, "D" for deposit, "P" for payment, "I" for investment, and "E" for electronic payee.
  • transaction β€” Dollar amount of transaction.
  • total β€” Dollar amount of transaction. This is generally the same as amount but in some cases can be higher. (Introduced in Quicken 2005 for windows)
  • status β€” Reconciliation status of transaction.
  • payee β€” Who the transaction was made to.
  • memo β€” Additional text describing the transaction.
  • address β€” Address of payee.
  • category β€” Category the transaction is assigned to.
  • action β€” Type of investment transaction like buty, sell, ... (Inroduced in Quicken 2006 for windows)
  • security β€” Security name of transaction. (Inroduced in Quicken 2006 for windows)
  • price β€” Price of security. (Inroduced in Quicken 2006 for windows)
  • quantity β€” Quantity of security. (Inroduced in Quicken 2006 for windows)
  • amount β€” Dollar amount of transaction. (Introduced in Quicken 2006 for windows)
  • splits β€” If the transaction contains splits this will be defined and consist of an array of hashes. With each split potentially having the following values:
    • category β€” Category the split is assigned to.
    • memo β€” Additional text describing the split.
    • amount β€” Dollar amount of split.
  • first β€” First payment date.
  • years β€” Total years for loan.
  • made β€” Number of payments already made.
  • periods β€” Number of periods per year.
  • interest β€” Interest rate of loan.
  • balance β€” Current loan balance.
  • loan β€” Original loan amount.

Type:Security

This is a list of securities. The following values are supported for security records.

  • security β€” Security name.
  • symbol β€” Security symbol.
  • type β€” Security type.
  • goal β€” Security goal.

Type:Budget

This is a list of budget values for categories. The following values are supported for budget records.

  • name β€” Category name of budgeted item.
  • description β€” Category Description of budgeted item.
  • expense β€” Usually exists if the category is an expense account however this is often a default assumed value and doesn't show up in files.
  • income β€” Exists if the category is an income account.
  • tax β€” Exists if this category is tax related.
  • schedule β€” If this category is tax related this specifies what tax schedule it is related if defined.
  • budget β€” An array of 12 values Jan-Dec to represent the budget amount for each month.

Type:Payee

This is a list online payee accounts. The following values are supported for online payee account records.

  • name β€” Name of payees.
  • address β€” Address of payee.
  • city β€” City of payee.
  • state β€” State of payee
  • zip β€” Zipcode of payee.
  • country β€” Country of payee.
  • phone β€” Phone number of payee.
  • account β€” Account number for payee transaction.

Type:Prices

This is a list of prices for a security. The following values are supported for security prices records.

  • symbol β€” Security Symbol.
  • prices β€” An array of hashes. With each hash having the following values:
    • date β€” Date of security values.
    • close β€” Close value of security for the date.
    • max β€” Max value of security for the date.
    • min β€” Min value of security for the date.
    • volume β€” Number of shares of security exchanged for the date.

Option:AllXfr, Option:AutoSwitch, Clear:AutoSwitch

These record types aren't related to transactions but instead provided ways to control how Quicken processes the QIF file. They have no impact on how this software operates and are ignored when found.

Note: If this software finds unsupported record types or values in a data file a warning will be generated containing information on what unexpected value was found.

✨ METHODS ✨


new()

okay bestie, this is where it all begins πŸ’– It creates a brand new instance of Finance::QIF. It supports these initializing values:

my $qif = Finance::QIF->new( file => "myfile", debug => 1 );

and like, if you specify the file, it just gets opened right there on new. no waiting, no drama ✨

file

Specifies the file to use for processing. See "file()" for details, iykyk.

my $in = Finance::QIF->new( file => "myfile" );

OR

my $in = Finance::QIF->new( file => [ "myfile", "<:crlf" ] );

For output files, bestie, be sure to open the file in write mode. like this:

my $out = Finance::QIF->new( file => ">myfile" );

record_separator

Can be used to redefine the QIF record separator. Default is $/.

my $in = Finance::QIF->new( record_separator => "\012" );
Note: For MacOS X it will most likely be necessary to change this to "\015". Quicken on MacOS X generates files with "\015" as the separator, which is typical of Mac, however the native perl in MacOS X is unix based and uses the default unix separator, which is "\012". See "autodetect" for another option πŸ‘€

autodetect

Enables auto detection of the record separator based on the file contents. Default is "0".

my $in = Finance::QIF->new( autodetect => 1 );

Perl uses $/ to define line separators for text files. And perl sets this value according to the OS perl is running on:

Windows="\015\012"
Mac="\015"
Unix="\012"

In many cases you may find yourself with text files that do not match the OS 😭 and in these cases Finance::QIF by default will not process that QIF file correctly. This feature is an attempt to help with the most common cases of having the wrong text file for the OS Finance::QIF is running on. periodt.

This feature depends on being able to seek to the end of the file and read the last 2 characters to determine the proper separator πŸ” If a seek can not be performed, or the last 2 characters are not a proper separator, the record_separator will default to $/ or the value passed in. But if a valid record_separator is found, then it will be set according to what was in the file. slay.

This code requires a file use a consistent line separator 🚨 If you find your self dealing with unusual files containing mixed separators you need to first Normalize the file to a consistent separator.

Normalizing a text file to have a consistent line separator is done in modules like File::LocalizeNewlines or Template::Parser::LocalizeNewlines, so if you are having issues with trying to process poorly formated text files, look at preprocessing them with something like those before passing on to Finance::QIF. big brain move πŸ’…

trim_white_space

Can be used to remove leading and trailing white space from values returned. Default is "0".

my $qif = Finance::QIF->new( trim_white_space => 1 );

debug

Can be used to output debug information. Default is "0".

my $qif = Finance::QIF->new( debug => 1 );

file()

Specify file name and optionally additional parameters that will be used to obtain a filehandle. The argument can be a filename (SCALAR), an ARRAY reference, or an ARRAY whose values must be valid arguments for passing to IO::File->new.

$qif->file( "myfile" );

OR

$qif->file( [ "myfile", "<:crlf" ] );

OR

$qif->file( "myfile", "<:crlf" );

For output files, be sure to open the file in write mode. (yes, again, it matters bestie 🫢)


record_separator()

Returns the currently used record_separator. This is used primarly in situations where you open a QIF file with autodetect and then want to write out a QIF file in the same format. iconic behaviour, honestly.

my $in  = Finance::QIF->new( file => "input.qif", autodetect => 1 );
my $out = Finance::QIF->new( file => ">write.qif",
                             record_separator => $in->record_separator );

open()

Open already specified file.

$qif->open();

Open also supports the same arguments as "file()". so versatile πŸ’–


next()

For input files, return the next record in the QIF file.

my $record = $in->next();

Returns undef if no more records are available. that's it, that's the vibe 🌸


For output files, use to output the passed header for records that will then be written with write.

$out->header( "Type:Bank" );

See "RECORD TYPES & VALUES" for the list of possible record types that can be passed πŸ‘‘


write()

For output files, use to output the passed record to the file.

$out->write( $record );

reset()

Resets the filehandle so the records can be read again from the beginning of the file. rewind moment πŸŒ€

$qif->reset();

close()

Closes the open file. bye bestie πŸ’œ

$qif->close();

🌈 EXAMPLES 🌈

Read an existing QIF file, then write out to a new QIF file. lowkey the classic move:

my $in  = Finance::QIF->new( file => "input.qif" );
my $out = Finance::QIF->new( file => ">write.qif" );

my $header = "";
while ( my $record = $in->next() ) {
    if ( $header ne $record->{header} ) {
        $out->header( $record->{header} );
        $header = $record->{header};
    }
    $out->write($record);
}

$in->close();
$out->close();

πŸ¦‹ SEE ALSO πŸ¦‹


πŸ’– ACKNOWLEDGEMENTS πŸ’–

  • Simon Cozens "simon@cpan.org", Author of original Finance::QIF
  • Nathan McFarland "nmcfarl@cpan.org", Maintainer of original Finance::QIF

πŸ‘‘ AUTHORS πŸ‘‘

Project maintained at <http://sourceforge.net/projects/finance-qif>


Copyright (C) 2006-2008 by Matthew McGillis. All rights reserved.


⭐ LICENSE ⭐

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's a wrap bestie 🫢 this page was served up by perl v5.32.0, dated 2021-01-07, for Finance::QIF(3pm) β€” go forth and format your finances, no cap πŸ’…βœ¨

πŸ“¦ where this page comes from