Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Can't get data out of array

by Tomte (Priest)
on Aug 05, 2004 at 16:27 UTC ( [id://380317]=note: print w/replies, xml ) Need Help??


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

#!/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

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
    Ok, I'm a moron for missing that. You can bet I'll have use strict and warnings from now on. Sheesh. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://380317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found