sun# pwd
/home/leo/work
sun# ls -la
total 7
drwxr-xr-x 3 root wheel 512 Dec 22 17:00 .
drwxr-xr-x 29 r_leo wheel 3072 Dec 22 16:43 ..
-rw-r--r-- 1 root wheel 245 Dec 22 16:59 1
-rwxr-xr-x 1 root wheel 503 Dec 22 17:29 1.pl
drwxr-xr-x 7 root wheel 512 Dec 22 17:01 a
sun# /bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'.
..
co
foo
leo
leopeter
peter
sun#@dir=split(/\n/,`/bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'`);
Срабатывает только /bin/ls -la /home/leo/work/a, часть с awk не срабатывает
>
>@dir=split(/\n/,`/bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'`);
>
>Срабатывает только /bin/ls -la /home/leo/work/a, часть с awk не срабатывает
а зачем тебе awk?
@array=split(/\s),<>);print $array[8] ломает написать?
>sun# pwd
>/home/leo/work
>sun# ls -la
>total 7
>drwxr-xr-x 3 root wheel 512 Dec
>22 17:00 .
>drwxr-xr-x 29 r_leo wheel 3072 Dec 22 16:43 ..
>
>-rw-r--r-- 1 root wheel 245 Dec
>22 16:59 1
>-rwxr-xr-x 1 root wheel 503 Dec
>22 17:29 1.pl
>drwxr-xr-x 7 root wheel 512 Dec
>22 17:01 a
>sun# /bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'
>
>.
>..
>co
>foo
>leo
>leopeter
>peter
>sun#
>
>@dir=split(/\n/,`/bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'`);
>
>Срабатывает только /bin/ls -la /home/leo/work/a, часть с awk не срабатывает1 #!/usr/local/bin/perl -w
2
3 opendir FHDIR,"<directory>";
4 while ($file=readdir FHDIR){
5 print $file,"\n";
6 }
7 close FHDIR;
>>sun# pwd
>>/home/leo/work
>>sun# ls -la
>>total 7
>>drwxr-xr-x 3 root wheel 512 Dec
>>22 17:00 .
>>drwxr-xr-x 29 r_leo wheel 3072 Dec 22 16:43 ..
>>
>>-rw-r--r-- 1 root wheel 245 Dec
>>22 16:59 1
>>-rwxr-xr-x 1 root wheel 503 Dec
>>22 17:29 1.pl
>>drwxr-xr-x 7 root wheel 512 Dec
>>22 17:01 a
>>sun# /bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'
>>
>>.
>>..
>>co
>>foo
>>leo
>>leopeter
>>peter
>>sun#
>>
>>@dir=split(/\n/,`/bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'`);
>>
>>Срабатывает только /bin/ls -la /home/leo/work/a, часть с awk не срабатывает
>
> 1 #!/usr/local/bin/perl -w
> 2
> 3 opendir FHDIR,"<directory>";
> 4 while ($file=readdir FHDIR){
> 5
> print $file,"\n";
> 6 }
> 7 close FHDIR;
prostite:*** 0044.pl.bad 2004-12-22 17:07:49.000000000 +0200
--- 0044.pl 2004-12-22 17:07:58.000000000 +0200
*************** opendir FHDIR,"/root/perl";
*** 4,7 ****
while ($file=readdir FHDIR){
print $file,"\n";
}
! close FHDIR;
--- 4,7 ----
while ($file=readdir FHDIR){
print $file,"\n";
}
! closedir FHDIR;
Эта фенька сработала, вот скрипт
sun# cat 1.pl
#!/usr/bin/perl@dir=split(/,/,`/bin/ls -m /home/leo/work/a`);
foreach $d (@dir)
{
$d=&despace ($d);
}
@users=(leo,peter,foo,boo,bubu,sex,sush,blabla);
foreach $u (@users)
{
chomp;
$i=0;
foreach $d (@dir)
{
print "$u, $d,";
chomp;
if ($u ne $d)
{
$i += 0;
print "$i\n";
}
else
{
$i=1;
print "$i\n";
}
}
if ($i==0)
{
`mkdir a/$u`;
}
else
{
}
}sub despace{
my $str = shift;
$str =~ s/[ \t]+/ /g;
$str =~ s/^[ \t]//;
$str =~ s/[ \t]$/\n/;
$str =~ s/\n+/\n/;
$str =~ s/<!--(.*)?--\s*>//g;return ($str =~ /\S/) ? $str : "";
}
sun#Все работает но возникает ошибка, когда доходит до последнего элемента массива @dir
sun# ./1.pl
leo, blabla,0
leo, boo,0
leo, bubu,0
leo, foo,0
leo, leo,1
leo, peter,1
leo, sex,1
leo, sush
,1
peter, blabla,0
peter, boo,0
peter, bubu,0
peter, foo,0
peter, leo,0
peter, peter,1
peter, sex,1
peter, sush
,1
foo, blabla,0
foo, boo,0
foo, bubu,0
foo, foo,1
foo, leo,1
foo, peter,1
foo, sex,1
foo, sush
,1
boo, blabla,0
boo, boo,1
boo, bubu,1
boo, foo,1
boo, leo,1
boo, peter,1
boo, sex,1
boo, sush
,1
bubu, blabla,0
bubu, boo,0
bubu, bubu,1
bubu, foo,1
bubu, leo,1
bubu, peter,1
bubu, sex,1
bubu, sush
,1
sex, blabla,0
sex, boo,0
sex, bubu,0
sex, foo,0
sex, leo,0
sex, peter,0
sex, sex,1
sex, sush
,1
sush, blabla,0
sush, boo,0
sush, bubu,0
sush, foo,0
sush, leo,0
sush, peter,0
sush, sex,0
sush, sush
,0
mkdir: a/sush: File exists имеено с последним элеметом массива?!
~~~~~~~~~~~~~~~~~~~~~~~~~~
blabla, blabla,1
blabla, boo,1
blabla, bubu,1
blabla, foo,1
blabla, leo,1
blabla, peter,1
blabla, sex,1
blabla, sush
,1
sun#
>>>sun# pwd
>>>/home/leo/work
>>>sun# ls -la
>>>total 7
>>>drwxr-xr-x 3 root wheel 512 Dec
>>>22 17:00 .
>>>drwxr-xr-x 29 r_leo wheel 3072 Dec 22 16:43 ..
>>>
>>>-rw-r--r-- 1 root wheel 245 Dec
>>>22 16:59 1
>>>-rwxr-xr-x 1 root wheel 503 Dec
>>>22 17:29 1.pl
>>>drwxr-xr-x 7 root wheel 512 Dec
>>>22 17:01 a
>>>sun# /bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'
>>>
>>>.
>>>..
>>>co
>>>foo
>>>leo
>>>leopeter
>>>peter
>>>sun#
>>>
>>>@dir=split(/\n/,`/bin/ls -la /home/leo/work/a | /usr/bin/awk '{print $9}'`);
>>>
>>>Срабатывает только /bin/ls -la /home/leo/work/a, часть с awk не срабатывает
>>
>> 1 #!/usr/local/bin/perl -w
>> 2
>> 3 opendir FHDIR,"<directory>";
>> 4 while ($file=readdir FHDIR){
>> 5
>> print $file,"\n";
>> 6 }
>> 7 close FHDIR;
>
>
>prostite:
>
>*** 0044.pl.bad 2004-12-22 17:07:49.000000000 +0200
>
>--- 0044.pl 2004-12-22 17:07:58.000000000 +0200
>*************** opendir FHDIR,"/root/perl";
>*** 4,7 ****
> while ($file=readdir FHDIR){
> print $file,"\n";
> }
>! close FHDIR;
>--- 4,7 ----
> while ($file=readdir FHDIR){
> print $file,"\n";
> }
>! closedir FHDIR;
1 #!/usr/local/bin/perl -w
2
3 use strict;
4
5 my (@dir,@users,$user,$file,$flag);
6
7 opendir DIRH,"/root/perl" || die "Can't open directory";
8 while ($file=readdir DIRH){
9 next if ($file eq "." or $file eq "..");
10 push @dir,"$file";
11 }
12 closedir DIRH || die "Can't close directory";
13 @users=('leo','peter','foo','boo');
14 foreach $user (@users){
15 $flag=0;
16 foreach $file (@dir){
17 printf "%s, %s, ",$user,$file;
18 if ($user ne $file){;
19 $flag+=0;printf "%s\n",$flag;
20 } else {
21 $flag=1;printf "%s\n",$flag;
22 }
23 }
24 mkdir "/tmp/$user",0770 if ($flag==0);
25 }
26 exit;