Last active
October 7, 2015 16:16
-
-
Save Shevviakov/fdc5f431f021a818f4af to your computer and use it in GitHub Desktop.
Perl Lecture 1 Tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir /A-D | perl -lnaF"\s+" -e "BEGIN {$n = 0; $m = 0} $F[2] =~ s/\D//g; $n++; if ($F[2] > 1048576) {$m++; print $F[3]} END {print qq{\nFiles total: }.($n - 7).qq{\nNumber of files greater than 1Mb: $m}}"\ | |
#!!!-----dir output (/A-D disable directories)-----!!! | |
C:\Users\Dima\Downloads>dir /A-D | |
Том в устройстве C не имеет метки. | |
Серийный номер тома: 6C3F-B12A | |
Содержимое папки C:\Users\Dima\Downloads | |
04.10.2015 23:49 0 0) | |
08.08.2015 16:04 1 008 506 168 android-studio-bundle-141.2117773-windows.exe | |
07.09.2015 15:30 136 732 106 Apache_OpenOffice_4.1.1_Win_x86_install_ru.exe | |
11.08.2015 21:53 931 408 ChromeSetup.exe | |
11.08.2015 21:57 105 122 348 codeblocks-13.12mingw-setup-TDM-GCC-481.exe | |
07.08.2015 16:41 282 desktop.ini | |
04.10.2015 23:48 0 dir | |
08.08.2015 16:02 132 197 656 genymotion-2.5.3-vbox.exe | |
08.08.2015 16:02 184 570 456 jdk-8u51-windows-i586.exe | |
08.09.2015 12:55 1 501 344 magistry.pdf | |
08.09.2015 12:55 8 495 959 rasselenie_2015.pdf | |
11.09.2015 17:46 586 807 Volf_Science.pdf | |
12 файлов 1 578 644 534 байт | |
0 папок 392 434 417 664 байт свободно | |
#!!!-----dir output with Perl oneliner-----!!! | |
C:\Users\Dima\Downloads>dir /A-D | perl -lnaF"\s+" -e "BEGIN {$n = 0; $m = 0} $F[2] =~ s/\D//g; $n++; if ($F[2] > 1048576) {$m++; print $F[3]} END {print qq{\nFiles total: }.($n - 7).qq{\nNumber of files greater than 1Mb: $m}}" | |
android-studio-bundle-141.2117773-windows.exe | |
Apache_OpenOffice_4.1.1_Win_x86_install_ru.exe | |
codeblocks-13.12mingw-setup-TDM-GCC-481.exe | |
genymotion-2.5.3-vbox.exe | |
jdk-8u51-windows-i586.exe | |
magistry.pdf | |
rasselenie_2015.pdf | |
Files total: 12 | |
Number of files greater than 1Mb: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -lnaF: -e "BEGIN {$str=0} $str++; for ($col = 0; $col<scalar @F; $col++) {if ($F[$col] > 10) {push @strings, $str; push @columns, $col+1;}} END{print '(str:col)'; for ($col=0; $col<scalar @columns; $col++) {print '('.$strings[$col].':'.$columns[$col].')'}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use DDP; | |
my @F; | |
my @AoA; #array of arrays | |
while (<>) { | |
@F = split(':'); | |
push @AoA, [@F]; | |
} | |
p @AoA; | |
# ---oneliner--- | |
# perl -lnaF: -MDDP -e "push @AoA, [@F]; END {p @AoA}" | |
# oneliner Deparse | |
BEGIN { $/ = "\n"; $\ = "\n"; } | |
use DDP; | |
LINE: while (defined($_ = <ARGV>)) { | |
chomp $_; | |
our @F = split(/:/, $_, 0); | |
push @AoA, [@F]; | |
sub END { | |
&p(\@AoA); | |
} | |
} | |
-e syntax OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v | |
c 8 | |
w @F | |
s | |
s | |
s | |
s | |
s | |
s | |
s | |
q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment