Parse and create quicken interchange format files
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"} ); } } }
Finance::QIF is a module for working with \s-1QIF\s0 (Quicken Interchange Format) files in Perl. This module reads \s-1QIF\s0 data records from a file passing each successive record to the caller for processing. This module also has the capability of writing \s-1QIF\s0 records to a file.
The \s-1QIF\s0 file format typically consists of a header containing a record or transaction type, followed by associated data records. Within a file there may be multiple headers. Headers are usually followed by data records, however data is not required to always follow a header.
A hash reference is returned for each record read from a file. The hash will have a \*(L"header\*(R" value which contains the header type that was read along with all supported values found for that record. If a value is not specified in the data file, the value will not exist in this hash.
No processing or validation is done on values found in files or data structures to try and convert them into appropriate types and formats. It is expected that users of this module or extensions to this module will do any additional processing or validation as required.
The following record types are currently supported by this module:
These are non investment ledger transactions. All of these record types support the following values.
Date of transaction.
Dollar amount of transaction.
Dollar amount of transaction. This is generally the same as transaction but in some cases can be higher. (Introduced in Quicken 2005 for windows)
Reconciliation status of transaction.
Check number of transaction.
Who the transaction was made to.
Additional text describing the transaction.
Address of payee.
Category the transaction is assigned to.
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 the split is assigned to.
Additional text describing the split.
Dollar amount of split.
This is for Investment ledger transactions. The following values are supported for this record type.
Date of transaction.
Type of transaction like buy, sell, ...
Security name of transaction.
Price of security at time of transaction.
Number of shares purchased.
Cost of shares in transaction.
Reconciliation status of transaction.
Text for non security specific transaction.
Additional text describing transaction.
Commission fees related to transaction.
Account related to security specific transaction.
Dollar amount of transaction.
Dollar amount of transaction. This is generally the same as amount but in some cases can be higher. (Introduced in Quicken 2005 for windows)
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.
Account name.
Account description.
Account limit usually for credit card accounts that have some upper limit over credit.
Defined if the account is tax related.
Additional information about the account.
Type of account.
Current balance of account.
This is a list of categories. The following values are supported for category records.
Name of category.
Description of category.
An array of 12 values Jan-Dec to represent the budget amount for each month.
Usually exists if the category is an expense account however this is often a default assumed value and doesn't show up in files.
Exists if the category is an income account.
Exists if this category is tax related.
If this category is tax related this specifies what tax schedule it is related if defined.
This is a list of classes. The following values are supported for class records.
Name of class.
Description of class.
This is a list of memorized transactions. The following values are supported for memorized transaction records.
Type of memorized transaction \*(L"C\*(R" for check, \*(L"D\*(R" for deposit, \*(L"P\*(R" for payment, \*(L"I\*(R" for investment, and \*(L"E\*(R" for electronic payee.
Dollar amount of transaction.
Dollar amount of transaction. This is generally the same as amount but in some cases can be higher. (Introduced in Quicken 2005 for windows)
Reconciliation status of transaction.
Who the transaction was made to.
Additional text describing the transaction.
Address of payee.
Category the transaction is assigned to.
Type of investment transaction like buty, sell, ... (Inroduced in Quicken 2006 for windows)
Security name of transaction. (Inroduced in Quicken 2006 for windows)
Price of security. (Inroduced in Quicken 2006 for windows)
Quantity of security. (Inroduced in Quicken 2006 for windows)
Dollar amount of transaction. (Introduced in Quicken 2006 for windows)
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 the split is assigned to.
Additional text describing the split.
Dollar amount of split.
First payment date.
Total years for loan.
Number of payments already made.
Number of periods per year.
Interest rate of loan.
Current loan balance.
Original loan amount.
This is a list of securities. The following values are supported for security records.
Security name.
Security symbol.
Security type.
Security goal.
This is a list of budget values for categories. The following values are supported for budget records.
Category name of budgeted item.
Category Description of budgeted item.
Usually exists if the category is an expense account however this is often a default assumed value and doesn't show up in files.
Exists if the category is an income account.
Exists if this category is tax related.
If this category is tax related this specifies what tax schedule it is related if defined.
An array of 12 values Jan-Dec to represent the budget amount for each month.
This is a list online payee accounts. The following values are supported for online payee account records.
Name of payees.
Address of payee.
City of payee.
State of payee
Zipcode of payee.
Country of payee.
Phone number of payee.
Account number for payee transaction.
This is a list of prices for a security. The following values are supported for security prices records.
Security Symbol.
An array of hashes. With each hash having the following values.
Date of security values.
Close value of security for the date.
Max value of security for the date.
Min value of security for the date.
Number of shares of security exchanged for the date.
These record types aren't related to transactions but instead provided ways to control how Quicken processes the \s-1QIF\s0 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.
Creates a new instance of Finance::QIF. Supports the following initializing values.
my $qif = Finance::QIF->new( file => "myfile", debug => 1 );
If the file is specified it will be opened on new.
Specifies file to use for processing. See \*(L"file()\*(R" for details. my $in = Finance::QIF->new( file => "myfile" ); OR my $in = Finance::QIF->new( file => [ "myfile", "<:crlf" ] ); For output files, be sure to open the file in write mode. For example: my $out = Finance::QIF->new( file => ">myfile" );
Can be used to redefine the \s-1QIF\s0 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 \*(L"\015\*(R". Quicken on MacOS X generates files with \*(L"\015\*(R" 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 \*(L"\012\*(R". See \*(L"autodetect\*(R" for another option.
Enable auto detection of the record separator based on the file contents. Default is \*(L"0\*(R". my $in = Finance::QIF->new( autodetect => 1 ); Perl uses $/ to define line separators for text files. Perl sets this value according to the \s-1OS\s0 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 \s-1OS\s0. In these cases Finance::QIF by default will not process that \s-1QIF\s0 file correctly. This feature is an attempt to help with the most common cases of having the wrong text file for the \s-1OS\s0 Finance::QIF is running on. This feature depends on being able to seek to the end of the file and reading 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. If a valid record_separator is found then it will be set according to what was in the file. 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.
Can be used to remove leading and trailing white space from values returned. Default is \*(L"0\*(R". my $qif = Finance::QIF->new( trim_white_space => 1 );
Can be used to output debug information. Default is \*(L"0\*(R". my $qif = Finance::QIF->new( debug => 1 );
Specify file name and optionally additional parameters that will be used to obtain a filehandle. The argument can be a filename (\s-1SCALAR\s0), an \s-1ARRAY\s0 reference, or an \s-1ARRAY\s0 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.
Returns the currently used record_separator. This is used primarly in situations where you open a \s-1QIF\s0 file with autodetect and then want to write out a \s-1QIF\s0 file in the same format.
my $in = Finance::QIF->new( file => "input.qif", autodetect => 1 ); my $out = Finance::QIF->new( file => ">write.qif", record_separator => $in->record_separator );
Open already specified file.
$qif->open();
Open also supports the same arguments as \*(L"file()\*(R".
For input files return the next record in the \s-1QIF\s0 file.
my $record = $in->next();
Returns undef if no more records are available.
For output files use to output the passed header for records that will then be written with write.
$out->header( "Type:Bank" );
See \*(L"\s-1RECORD\s0 \s-1TYPES\s0 & \s-1VALUES\s0\*(R" for list of possible record types that can be passed.
For output files use to output the passed record to the file.
$out->write( $record );
Resets the filehandle so the records can be read again from the beginning of the file.
$qif->reset();
Closes the open file.
$qif->close();
Read an existing \s-1QIF\s0 file then write out to new \s-1QIF\s0 file.
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();
Carp, IO::File
Quicken Interchange Format (\s-1QIF\s0) specification <http://web.intuit.com/support/quicken/docs/d_qif.html>
Simon Cozens \*(C`[email protected]\*(C', Author of original Finance::QIF
Nathan McFarland \*(C`[email protected]\*(C', Maintainer of original Finance::QIF
Matthew McGillis <[email protected]> <http://www.mcgillis.org/>
Phil Lobbes <phil at perkpartners dot com>
Project maintained at http://sourceforge.net/projects/finance-qif <http://sourceforge.net/projects/finance-qif>
Copyright (C) 2006-2008 by Matthew McGillis. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.