Hi Chad. Chad Kellerman wrote: > Hello everyone, > > I want to clean this bit of code up. It looks really messy. I > am in a mental block. Any suggestions? > > @userInfo = split /\s+/, $buffer;
Use a single space here to split on. @userInfo = split ' ', $buffer; It's a special case that splits on contiguous whitespace like your expression, but discards a null first field if there are leading spaces in the object string. > #insert home users & quota in the db > foreach $userInfo ( @userInfo ) { > > ( $name, $quota ) = split /\|/, $userInfo; > # get rig of the header info from repquota I hope you have used 'strict' and 'warnings'? I haven't seen any declarations! > next if ( ( $name =~ /Block/ ) or ( $name =~ /nobody/ ) or ( > $name =~ /User/ ) or ( $name =~ /^\d/ ) or ( $name =~ /www/ ) or ( > $name =~ /backup/ ) or ( $name =~ /ftp/ ) or ( $name =~ /httpd/ ) > or ( $name =~ /root/ ) or ( $name =~ /netop/ ) or ( $name =~ /sysop/ > ) or ( $name =~ /users/ ) or ( $quota !~ /\d+/ ) or ( $name =~ /^#/ ) > or ( $quota <= 8 ) or ($name =~ /bill/) ); > > Is there an easier way to loop thru a bunch of regex? You could do: next if $name =~ /Block/; next if $name =~ /nobody/; : next if $name =~ /bill/; which looks a lot better (and shouldn't be any slower). Note that you're finding these strings anywhere in the object string. Is that what you want? Also, have you considered whether you need a case-sensitive match? The checks on $quota aren't quite right. The test next if $quota !~ /\d+/ will pass the string 'B52s' no problem, but the test next if $quota <= 8 will give you a warning unless you have: no warnings 'numeric'; and will evaluate the object string as zero anyway. You might like: next unless $quota =~ /(\d+)/ and $1 > 8; which will check that the string contains a number, and if so that it's more than eight, but I don't know what your data looks like. This code should do the trick. foreach my $userInfo ( split ' ', $buffer ) { my ( $name, $quota ) = split /|/, $userInfo; next if grep $name =~ /$_/, qw( ^# ^\d backup bill Block ftp httpd netop nobody root sysop User users www ); next unless $quota =~ /(\d+)/ and $1 > 8; } but remember the provisos above. I can't help thinking though, that there's probably a better set of criteria to 'get rid of the header info'. Let us see your data format if yu need any further help. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]