in reply to Can't get data out of array
Always use strict; and use warnings; if you are developing, helps a lot:
This a little bit "strictified" version of your code
yields:#!/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");
I guess you mean tmpa in both cases, but I may be wrong...[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.
regards,
tomte
An intellectual is someone whose mind watches itself.
-- Albert Camus
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't get data out of array
by hisnewbness (Initiate) on Aug 05, 2004 at 16:40 UTC |