Finance::QIF(3pm)
π 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
$qifobject withFinance::QIF->new( file => "test.qif" )β thatfilekey is where your QIF lives π¦ - then
$qif->nextin awhileloop just keeps handing you one$recordat a time until there's nothing left. main character energy honestly. π - every
$recordhas aheader, and the loop prints that first:print( "Header: ", $record->{header}, "\n" );π - then it walks
keys %{$record}and prints each key/value β but itnexts right pastheader,splits,budgetandprices, because those get their own special little moments. not me skipping the four keys that are too famous to share a line π splits? ifexists( $record->{splits} )it loops every$splitin@{ $record->{splits} }and prints each$key/value pair prefixed withSplit:. πbudget? ifexists( $record->{budget} )it printsBudget:and then just dumps every$amountfrom@{ $record->{budget} }separated by spaces, then a newline. πprices? ifexists( $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", andprintfs 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 astransactionbut 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 asamountbut 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 asamountbut 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 likebuty,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 payeezipβ 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 πΈ
header()
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 π¦
Carp,IO::File- Quicken Interchange Format (QIF) specification
http://web.intuit.com/support/quicken/docs/d_qif.html
π ACKNOWLEDGEMENTS π
- Simon Cozens
"simon@cpan.org", Author of originalFinance::QIF - Nathan McFarland
"nmcfarl@cpan.org", Maintainer of originalFinance::QIF
π AUTHORS π
- Matthew McGillis
<matthew@mcgillis.org><http://www.mcgillis.org/> - Phil Lobbes
<phil at perkpartners dot com>
Project maintained at <http://sourceforge.net/projects/finance-qif>
π COPYRIGHT π
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
- debian bookworm: libfinance-qif-perl 3.02-1.1
- debian trixie: libfinance-qif-perl 3.02-1.1
- ubuntu jammy: libfinance-qif-perl 3.02-1.1
- ubuntu noble: libfinance-qif-perl 3.02-1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms