Always use strict; and use warnings; if you are developing, helps a lot:

This a little bit "strictified" version of your code

#!/bin/env perl #Look in daily syslog file and grab the #user, group, connection duration, bytes xmt and bytes rcv #Stick this data into a daily report in .csv format # use warnings; use strict; #TIME & DATE STUFF my $stime = localtime; my @time1 = split(' ', $stime); my $mon = $time1[1]; my $day = $time1[2]; my $year = $time1[4]; my $filename = "dailyreport-$mon-$day-$year.csv"; #Open the log file for reading open (LOG, "</var/log/ciscon.log") || die "Couldn't open log file $!"; open (TMP, ">>tmpfile.txt") || die "Couldn't open tmp file $!"; open (DREPORT, ">>/root/reports/$filename") || die "Couldn't open csv +$!"; print DREPORT "DAILY LOG FOR $mon $day $year\n"; print DREPORT "\n"; print DREPORT "USERNAME,GROUP,DURATION,BYTES XMT,BYTES RCV,\n"; print DREPORT "\n"; #Pump data into array and parse for usefull data #Usefull data goes into tmpfile while( <LOG>) { my @tmp = grep {/disconnected/} $_; print TMP "@tmp"; } #Close stuff we dont need close TMP; close LOG; #Open temp file and stuff into array by spaces print data we #want into the daily csv file open (TMP1, "<tmpfile.txt") || die "Can't read from tmpfile $!"; while( <TMP1> ) { chomp $_; my @tmpa = split(' ', $_); print DREPORT "$tmpa[15],$tmpa[17],$tmpa[20],$tmp[23],$tmp[26] +\n"; } close TMP1; unlink ("tmpfile.txt");
yields:
[1823]tom@margo perl $ perl -c test3.pl Global symbol "@tmp" requires explicit package name at test3.pl line 5 +0. Global symbol "@tmp" requires explicit package name at test3.pl line 5 +0. test3.pl had compilation errors.
I guess you mean tmpa in both cases, but I may be wrong...

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus


In reply to Re: Can't get data out of array by Tomte
in thread Can't get data out of array by hisnewbness

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.