I am BOGGLED.

I have a file of check book data. Here's a sample line:

"Lunch Place", 1/22/2010, -4.110000, "Lunch", "", , 0

I want to run through the file, add up all the entries that say lunch and then see how much I spend a year on lunch.

# this is the format of the lines # "Description", "Date", "Amount", "Category", "Memo", "Check Number", + "Reconciled" my $file = "checkdata.csv"; open( F, "$file" ); my @lines = <F>; my $sum = 0; foreach my $line ( @lines ) { chomp( $line ); my @data = split( ",", $line ); my $v = $data[2]; my$vplus = $v + 1; # I tried doing this to take care of trailing zeros, leading space + and minus. my $data[2] =~ /\s*(-?\d*\.\d*)0000/; my $v2 = $1; print " $v plus 1 is $vplus\n"; print " $v2 is regexed\n"; $sum = $sum + $data[2]; } print $sum;

Here is a sample output line. -27.000000 plus 1 is 1 is regexed I am SO CLUELESS. I've used a lot of perl in the past and I can't for the life of me figure out whats going on and I'm going INSANE. Please, someone explain this to my addled brain before I use up all my brain matter on a brick wall.


In reply to Why won't it please be a number? by chuckhazard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.