I am writing a program that is intended to read through a large log file of web server activity. My intent is to have a few different regular expressions that grab specific bits of each line of the log and place them into a hash to keep track of how many times each IP, browser type, etc. appear. The part that is giving me trouble is taking that specific bit of text that matches the regex out of each line so I can analyze it alone. What I have currently is:
my @regexes = (qr/^\S*/);
# Iterate through each line of the data with each regex
foreach my $regex (@regexes) {
# Create an empty hash for all the data
my %dataHash;
foreach my $line (@data) {
# Up to this point I have verified that $line contains the correct line I want to take a "substring" of.
my ($relevantData) = ($line =~ $regex);
#print("$relevantData\n");
Printing $relevantData is not the end goal here of course, but it's to verify that I'm properly getting what I need. I don't think it's relevant but the @data array is just an array of the aforementioned log split at each line.
When I have this print statement active, it just prints "1" over and over again. Currently, The regex I'm using is just meant to take from the start of each line until the first instance of whitespace, so what I'm expecting is that first word. I've tried messing around with parenthesis placement, and what I have seems to match examples I've found online, but I may be misunderstanding them. This is technically a repost due to being a duplicate of this, but I had utilized this post prior to posting, which is what I replicated, but it doesn't seem to be working, so I am unsure what I'm doing wrong. Thank you in advance!