On Mon, 2003-11-17 at 06:19, R. Joseph Newton wrote: > Guardian Angel wrote:
> > But now... i want to be more precise with my script. > > So i made 2 extra if loops, 1 is looking for errors, and if so, also > > check if there is no 127.0.0.x adres in it anymore (works so far :D) > > Whoa! This is not the way to get a programming job done. Rambling does not get you > there. > Before you can write effective code, you have to focus your thinking process. Don't > get > caught up in fascination with coding tricks. Look for tools to accomplish clearly > defined > purposes. Express those purposes, and the steps to achieve them, in plain language. > > Most important, take a breath. > > Joseph > Uhm... lol... i get it. But this *is* working (although it will not be the best code you ever seen ;)) Ofcourse i can better make a complete plan of what i want, but that is too much atm. I have *no* experience with coding at all, and it's a bit overwhelming for now :) ( a lot of statements, loops, array's, hashes etc) So i was just trying to make my scripts step by step more difficult, so i can understand *why* Perl is doing things, and what it is doing. That way i can better understand what happends, and then (ofcourse) I have to find out exactly what i want, and how i want it... but for now that is too much. So i prefer little parts (which i can understand) and then step by step learning more. ie. i see a lot of ppl who start with (for me) heavy scripts (used with 2 or 3 modules) while they have not really a clue of what they are doing... copy/ paste will work, but it will definitly not *learn* to write code yourself :D And now i will take a deep breath.....aaahhhhhh (nice) I've putted my last reply here, since it was only send to Joseph (by accident), and not to the mailinglist. On Sun, 2003-11-16 at 16:52, Rob Dixon wrote: > Hi Sander. First of all, I guess this will feel like I'm ripping > your code apart. Try to imagine me as your best-friend > cardboard-cutout programmer with nothing but your interests > at heart. :) I'll do my best to see you as my best-friend, while you strip my 1st code ;) But thanx (also to the pther ppl) for pointing me to some things. > Few people know what to make of Perl the first time they see > it. People try to force it into either C or shell, but it's > neither. Take a look at what I've written below, and keep an > open mind! > It's hard to start (as always), but it will work...some day :) I have some knowledge about the shell and linux, but i don't write code in any other language, so it's all new to me. > > use strict; # Always > use warnings; # Usually (same as -w qualifier but portable) i will do that, "use warnings;" gave me more (human readable) errors, so better to understand for me. I was looking for the > and < operators. I had used them with backticks (but gave a error message, because it was a "greater then" value, because i left spaces like print $a > $b instead of print $a>$b .... But now... i want to be more precise with my script. So i made 2 extra if loops, 1 is looking for errors, and if so, also check if there is no 127.0.0.x adres in it anymore (works so far :D) then i want to sort the ip's ....and that's what dazzling me now... This is what i want: I Look in the (newly) written error.log, and see immediatley that someone with ip 123.45.6.7 has tried 1x to login. But 123.45.6.8 has tried to login 50x in the last 6 days... Now my thought was that i made an array to put everything from while <ER>, and when it's an error message and *not* 127.0.0.x in the array, then sort, and put it in the error.log.... unfortunatly it's not working.... so i looked for the subroutines in Learning Perl... but i don't get it *how* you can get these values.... Thanx a lot Sander #!/usr/bin/perl use strict; use warnings; open (ER, "</home/unicorn/Plscripts/error_log") || die "can't open ER, $!\n"; #opening error_log for ReadNow all the advice helped me out, open (EL, ">>/home/unicorn/Plscripts/error.log") || die "can't open EL, $!\n"; #opening ERROR.LOG for Write while (<ER>) { #as long as ER is open, read.... if (/error/) { #if there is any errormessage in the file if (!/127.0.0.*/) { #and it's not local 127.0.0.x @sorted_list = sort by_ip (ER) ; #the inputfile is sorted by ip in @sorted_list print EL $_; #print output to ERROR.LOG #was print EL $_; } } } #sub by_ip { # @sorted_list = sort { $a <=> $b } EL; # } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]