#!/usr/bin/perl use strict; use warnings; use Switch; my $srcdir = "D:/source/"; my $srcfile = $srcdir."money.dat"; open (READ, "< $srcfile") || die "Can't find the dat file\n"; my ($date, $expense, $income); my $epochToday = time; my $last30days = $epochToday - 2592000; my ($year, $month, $day) = (localtime($last30days))[5,4,3]; $month++; $year+=1900; my $mon; switch ($month) { case [1] {$mon="Jan"} case [2] {$mon="Feb"} case [3] {$mon="Mar"} case [4] {$mon="Apr"} case [5] {$mon="May"} case [6] {$mon="Jun"} case [7] {$mon="Jul"} case [8] {$mon="Aug"} case [9] {$mon="Sep"} case [10] {$mon="Oct"} case [11] {$mon="Nov"} case [12] {$mon="Dec"} } my $lastdate = $day."-".$mon."-".$year; my $read; my $total; while (<READ>) { chop; ($date, $expense, $income) = split(/,/,$_); $total = $expense+$income; @data_date = ($date); MY PROBLEM STARTS HERE!!!!! if($lastdate =~ /^@data_date/) { } @data = ($total); push @data, [@data_date]; push @recent, [@data]; $read++; } close READ || die "Couldn't close the dat file"; my $desdir = "D:/target/"; my $desfile = $desdir."total.csv"; open (WRITE, "< $desfile") || die "Can't find the csv file.\n"; my $y=0; foreach(@recent) { $printout .= "$recent[$y][0],$recent[$y][1]\n"; $y++; } print WRITE $printout; close WRITE || die "Couldn't close the csv file.\n"; exit ;

In reply to Re^2: copying records from one file to another with filter. by avanta
in thread copying records from one file to another with filter. by avanta

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.