In perl you can think more like human, not like programmer... what you need to do? Take lines from logfile, look for names ending in "js" and list them... so you can process it like this:
#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; my %h = map { ($_, 1) } grep { $_ } map { /([^\/]*\.js)/ && $1 } `cat /var/log/apache2/access.log.1`; print map { "$_\n" } sort keys %h;
this is less readable:
#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; print map { "$_\n" } sort keys %{{ map { ($_, 1) } grep { $_ } map { /([^\/]*\.js)/ && $1 } `cat /var/log/apache2/access.log.1` }};
and use Path::Tiny if failure on file open is important:
#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; use Path::Tiny; my %h = map { ($_, 1) } grep { $_ } map { /([^\/]*\.js)/ && $1 } path('/var/log/apache2/access.log.1')->lines_utf8(); print map { "$_\n" } sort keys %h;
In reply to Re: Building ARRAY with grep expression NOT working
by leszekdubiel
in thread Building ARRAY with grep expression NOT working
by denting24by7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |