Good morning Monks!
Help.....
My goal here is to get an input from a variable like:
my $test = "Joe's Store"; as
an example and print its name first and how many times it showed in the data file like:
Joe's Store N1:
Log in activity: 4
DI Activity: 3
DX Activity: 1
I am trying to log every transaction an user do in my program.
The code below does sort of what I want but it doesn't do by item,
there is a better way of doing this? I sure it is, can someone help me with that?
Thanks a lot!!!!
The code:
my $test = "Joe's Store";
my $log_file = "c:\log.txt";
open(LOGFILE, "$log_file") or die("Could not open log file.");
while(<LOGFILE>){
my ($item) = $1 if /(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?
+)\*(.*?)$/;
next if $seen{$item};
print "$item<br>";
print "$seen{$1}";
$seen{$item}++;
}
____DATA__FILE
Joe's Store N1*002113*pw12613x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N2*002113*pw12613x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N1*002113*pw12613x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N1*002113*pw12613x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N5*002113*pw12613x*DI*4/15/2004*11:58:46*1510043*1
Rental Company N1*002113*pw126513x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N6*002113*pw126513x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N1*002113*pw126513x*DX*4/15/2004*11:58:46*1510043*1
Joe's Store N8*002113*pw126513x*DI*4/15/2004*11:58:46*1510043*1
Joe's Store N9*002113*pw126513x*DI*4/15/2004*11:58:46*1510043*1
Rental Company N1*002113*pw126513x*DI*4/15/2004*11:58:46*1510043*1
Rental Company N2*002113*pw126513x*DI*4/15/2004*11:58:46*1510043*1
Travel X*003443*pw126513x*DI*4/15/2004*11:58:46*1510043*1
___END_DATA__FILE
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.