bailybj has asked for the wisdom of the Perl Monks concerning the following question:

I apologize for not suppling the info you all needed so lets try this again.....the data reads:
2001/03/12 time>Event [21]Alert Completed (34562), Status: [22] Alert Completed,MN_netware-support
I need to divide the line into 4 variables: $date_stamp, $event, $alert_id, and $status. I am using: ($date_stamp,$event,$alert_id,$status)=split(>) for code and this will pull the $date_stamp out. This will pull the first variable: 2001/03/12 time. Var#2 runs from Event to the first word ending in "ed" and although this one always ends in "ed" the wording varies. Var #4: is always a number in () but it can vary from 1-5 digits. Var#4 is from the , to the end.

I have two questions: How do I list more than one delimiter? and How do I list [ or ) as a delimiter?
Thank You!*!*!*!*!

Edit 2001-03-26 by tye

Replies are listed 'Best First'.
Re: split delimiters #2
by wardk (Deacon) on Mar 27, 2001 at 04:59 UTC

    Bailybj, a more reasonable solution is located at: split delimiters II, but this uses split, per your request(s).

    but in the spirit of TIMTOWTDI, here is my entry for knuckleheaded-code-of-the-day (hey, it's monday but fun is still allowed, eh?)

    again, you may just want to do it smarter than this :-)

    #!/bin/perl while (<DATA>) { my $line = $_; $line =~ s/[A-Z,a-z,\>,\(,\),\-,\[,\],\:\_]/ /g; # remove stuff my ($dt,$ev,$id,$st) = split(/\s+/,$line); # split on spac +es print "Date:$dt\nEvent:$ev\nId:$id\nStatus:$st\n"; # tada! } __DATA__ 2001/03/12 time>Event [21]Alert Completed (34562), Status: [22] Alert +Completed,MN_netware-support

    which outputs:

    xdev$ ./split.pl Date:2001/03/12 Event:21 Id:34562 Status:22

    have fun!

Re: split delimiters #2
by dvergin (Monsignor) on Mar 27, 2001 at 05:13 UTC
    This begs for a regular expression. But it's dicey to build a regex based on only one example. Here's a bit of code that you might start with:
    my ($date_stamp,$event,$alert_id,$status); my $str = '2001/03/12 time>Event [21]Alert Completed (34562), Status: +[22] Alert Completed,MN_netware-support'; ($date_stamp,$event,$alert_id,$status) = $str =~ /^([\d\/]+).*?(Event.*?ed) \((\d+)\), (.*)$/; print "[$date_stamp]\n"; print "[$event]\n"; print "[$alert_id]\n"; print "[$status]\n";
    Which prints out:
    [2001/03/12] [Event [21]Alert Completed] [34562] [Status: [22] Alert Completed,MN_netware-support]
    This may well break depending on what variation there is in the rest of the data, but it may serve to get you started.
    ^ start at the beginning of the line ([\d\/]+) match and save a bunch of digits and /'s .*? lazily match and ignore stuff until... (Event.*?ed) match and save of 'Event...ed' match but ignore the following space \( match a literal paren (\d+) match and save a bunch of digits \), match and ignore literal paren, comma, and space (.*) match and save anything until... $ the end of the string