Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:29:00+00:00 2026-05-24T12:29:00+00:00

This is what an entry looks like: Jan 26 20:53:31 hostname logger: System rebooted

  • 0

This is what an entry looks like:

Jan 26 20:53:31 hostname logger: System rebooted for hard disk upgrade

I’m writing a small application to parse entries like this and email a nicely formatted message to the admin. I’m writing in Perl and found the split() function which is exactly what I’m looking for:

my @tmp = split(/ /, $string, 4);
@tmp = {$date, $hostname, $facility, $message)

That’s what I’m hoping to get. Split() can handle the spaces in the $message part because I limit the amount of “words” to split off. However, the spaces in the $date part throw it off. Is there a clean way I can get these variables to represent what they’re supposed to?

I know I could use substr() to grab the first 15 characters (the date), then use split() and limit it to 3 words instead of 4, then grab all my strings from there. But is there a more elegant way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:29:01+00:00Added an answer on May 24, 2026 at 12:29 pm

    If one-lined-ness is important to elegance, split on spaces that are not followed by a digit:

    my ( $time, $hostname, $facility, $message ) = split /\s+(?=\D)/, $string, 4;
    

    But it makes more sense to use a combination of split and unpack to address the need:

    my ( $timeStamp, $log ) = unpack 'A15 A*', $string;
    
    my ( $host, $facility, $msg ) = split /\s+/, $log;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows CE console application that's entry point looks like this int
I have a CSS entry that looks like this: .header { background-image: url(./images/embouchure.jpg); background-repeat:
I'm trying to create an xml entry that looks like this using python and
I've got a MongoDB collection that looks something like this: [ { title: Entry
I have an entry in my crontab that looks like this: 0 3 *
I have an array of hashes. Each entry looks like this: - !map:Hashie::Mash name:
I have cron entry that looks like this which works: (passing in 5 inputs)
I've got a section of XML that looks like this: <entry> <id>tag:example.com,2005:Release/343597</id> <published>2012-04-10T11:29:19Z</published> <updated>2012-04-10T12:04:41Z</updated>
My Tree structure looks like this, containing three classes Index,Key,Value Index1 | -- Key1
The error entry looks like: 2011/06/10 13:30:10 [error] 23263#0: *1 directory index of /var/www/ssl/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.