David vd Geer Inhuur tbv IPlib wrote: > Hello, > > Last time I got so much feedback that I will try it again. I learned a lot of > the last recommendations, but the next issue could not be made more efficient by > me. Can you ? > > #!/usr/local/bin/perl > # > my $base = "/user/IPlib/IPlib/Analog_CMOS/Camera"; ## Set temporarily for this test, >normaly the user switches the $base depended on which folder he clicks. > my $href = "comic_a2"; ## Set temporarily for this test, normaly this is a >foreach of a directory($base) content, only if ( -d ...) are used. > > if ( -e "${base}/${href}/user.perm" ) { > open(USERS, "< ${base}/${href}/user.perm");
Check if open fails > > while(<USERS>) { The multiple if statements can be avoided here if you use a hash my %grp_users; while (<USERS>) { if (m/^(\w+): (.*)$/) { $grp_users{$1} = [split (/,/, $2)]; } Each hash key (with your example file) 'user', 'group' and 'descr' contains a reference to an array of users that belong to them. > > if ( m/^user:/ ) { > my $user = (split, /:\s*/)[1]; > our @users = split(/,/, $user); > next; > } # End if $user > if ( m/^group:/ ) { > my $grp = (split, /:\s*/)[1]; > our @grp = split(/,/, $grp); > next; > } # End if $user > if ( m/^descr:/ ) { > my $dgrp = (split, /:\s*/)[1]; > our @dgrp = split(/,/, $dgrp); > next; > } # End if $user > } # End while > > } # End if -e > else { > @users = "niets"; > @grp = "niets"; > @dgrp = "niets"; > } > close(USERS); > > # ---- > user.perm: > > user: one,two,three > group: grp1,grp3 > descr: grp1,grp2,grp3 > #--- > > > > Regs David > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]