in reply to Re: i dont like the way my code looks but work
in thread i dont like the way my code looks but work

thank you guys! I have modified my script
I am trying to make my script look better and also trying to get use to put things in subroutines(because I will need to start building larger scripts
thank you!
use strict; use diagnostics; sub init { my %total; while (<DATA>) { #my %total; #why doesn't this work?????? next if /^#/; next if /^$/; next if ! /(server[1-4])\s+(proc[A-Z]+)\s+(proc\.[0-9]+)\s+[0- +9]+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:?[0-9]{4}?)\s+.+$/; $total{join ("\@", $3,$1)} = "$4"; } return \%total; } sub do_something { my $do_it = shift; while (<>) { chomp; my $item = $_; for (keys %{$do_it}) { print "$_ ===> $$do_it{$_}\n" if $_ eq "$item"; } } } do_something(init());

Replies are listed 'Best First'.
Re^3: i dont like the way my code looks but work
by moritz (Cardinal) on Jan 27, 2008 at 19:03 UTC
    If you declare my %total inside the loop, it will be only be visible inside the loop - and reset every time the loop starts over. Certainly not what you want.