...we're pretty much beyond what split can do...
Mh, we know the format:
use Data::Dump;
use feature qw(say);
my $line =qq(127.0.0.1 - - [22/Apr/2015:13:35:04 +1000] "GET /bin/admi
+n.pl HTTP/1.1" 401 509);
my @bits = split /\s/, $line;
dd\@bits;
say qq(Host: $bits[0]);
say qq(Logname: $bits[1]);
say qq(User: $bits[2]);
say qq(Time: $bits[3] $bits[4]);
say qq(Request: $bits[5] $bits[6] $bits[7]);
say qq(Status: $bits[8]);
say qq(Size: $bits[9]);
__END__
monks>apache.pl
[
"127.0.0.1",
"-",
"-",
"[22/Apr/2015:13:35:04",
"+1000]",
"\"GET",
"/bin/admin.pl",
"HTTP/1.1\"",
401,
509,
]
Host: 127.0.0.1
Logname: -
User: -
Time: [22/Apr/2015:13:35:04 +1000]
Request: "GET /bin/admin.pl HTTP/1.1"
Status: 401
Size: 509
Regards, Karl
«The Crux of the Biscuit is the Apostrophe»
| [reply] [Watch: Dir/Any] [d/l] |
Thanks for your reply!
A quick question dealing with the internal workings of what you wrote:
I understand that the split function can take any expression as its element then operate on the scalar, but what would be the more nuanced differences, particularly with memory usage and processing speed, if any, between using split and a general pattern match?
Thanks!
| [reply] [Watch: Dir/Any] |
You can measure the speed of your code with the time command. Or use Time::HiRes. Or Benchmark. See also Devel::Size and Devel::NYTProf.
And don't forget to try Super Search. I'm sure that you will find many examples that use time, Benchmark, Time::HiRes, Devel::Size and Devel::NYTProf.
Regards, Karl
«The Crux of the Biscuit is the Apostrophe»
| [reply] [Watch: Dir/Any] [d/l] [select] |
I'm not sure I'd want to bet my life that none of logname, user or the request URI can have spaces in them.
| [reply] [Watch: Dir/Any] [d/l] [select] |
| [reply] [Watch: Dir/Any] |
He did ask for a learning exercise; not a pre-solved solution.
Plus, chances are the he'll need to break the composite fields down further anyway, before he can do any analysis or storage.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
| [reply] [Watch: Dir/Any] |
"...He did ask for a learning exercise..."
Yes, but i didn't reply to the OP.
"...break the composite fields down..."
Yes, sure. Perhaps like this:
karls-mac-mini:monks karl$ perl -E ' say split /[\[\]]/, qq([22/Apr/20
+15:13:35:04 +1000])'
22/Apr/2015:13:35:04 +1000
karls-mac-mini:monks karl$ perl -E ' say split /"/, qq("GET /bin/admin
+.pl HTTP/1.1")'
GET /bin/admin.pl HTTP/1.1
karls-mac-mini:monks karl$ perl -E 'say join "\t", split /\s/, qq(GET
+/bin/admin.pl HTTP/1.1)'
GET /bin/admin.pl HTTP/1.1
# usw...
I just wanted to show wrog that a solution that only uses split is possible.
Another question is this it is desirable if this is desirable. I guess some may call it abuse.
Edit: Better wording.
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
| [reply] [Watch: Dir/Any] [d/l] |
Sorry Karl. My reply was intended as a reply to wrog.
I must have clicked the wrong link; which from memory is a first for me. I make plenty of other stupid user errors here, but never (that I recall) replying to the wrong post.
Effectively, I was make the same point as you already did.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
| [reply] [Watch: Dir/Any] |