if statement - Perl: foreach line, split, modify the string, set to array. Opendir, next if files=modified string. Unlink files -
i'm having issues following block of code: $output netstat -lnt | grep ":::60". section under comment #create filename format
my @lines = split /^/, $output; foreach $line (@lines) { ($garb, $long_ports) = (split /\s*:::\s*/, $line); #get last 2 digits of 60xx port number ($garb2, $ports) = (split /60/, $long_ports); #split values numbers 0-9 correct filename format if ($ports < 10) { ($garb3, $ports2) = (split /0/, $ports); #add 0 since 0 port split empty string if (length($ports2) == 0){ $ports2 = "0$ports2"; } #create file name format @locked_ports = ".x$ports2-lock"; } } %h = map {$_ => 1 } @locked_ports; #open /tmp , find .x*-lock files not match locked_ports opendir (dir, $tmp ) or die "error in opening dir $tmp\n"; while (my $files = readdir(dir)) { if (exists $h{$files}){ next} unlink $files; } closedir(dir);
i've tried:
#create file name format @locked_ports = ".x$ports2-lock"; } } #open /tmp , find .x*-lock files not match locked_ports opendir (dir, $tmp ) or die "error in opening dir $tmp\n"; while (my $files = readdir(dir)) { next if $files =~ @locked_ports; unlink $files; } closedir(dir);
and:
#create file name format $locked_ports = ".x$ports2-lock"; } } #open /tmp , find .x*-lock files not match locked_ports opendir (dir, $tmp ) or die "error in opening dir $tmp\n"; while (my $files = readdir(dir)) { next if $files =~ $locked_ports; unlink $files; } closedir(dir);
each time error similar to: global symbol "@locked_ports" requires explicit package name
, global symbol "$locked_ports" requires explicit package name
how can have while "next" on filenames equal lines of locked_ports?
any appreciated.
thanks.
my
scopes variable inner-most block (curlies) in located.
{ $foo; ... } # $foo not accessible here.
the block ends on line after 1 create variable. move variable's declaration has sufficiently large scope.
Comments
Post a Comment