Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Some assistance with splitting variables

by ww (Archbishop)
on Apr 05, 2013 at 21:53 UTC ( [id://1027224]=note: print w/replies, xml ) Need Help??


in reply to Some assistance with splitting variables

  1. Sometimes, using multiple regexen is easier or clearer than trying to do all the work with one (more complex) regex
  2. Captures the first element OP wanted; also perhaps somewhat easier to read.
#!/usr/bin/perl use 5.016; # 1027211 use Data::Dumper; my @info; my $info = '19476 2013-04-05,12:10:51.909293 host:internal.machine44.c +ompany.net main INFO Running normally with ACTION=<processing> FAN_A= +<OK> FAN_B=<OK> SEND=<Sent mail (221 2.0.0 Service closing transmissi +on channel)> FAILURE=<2> '; if ($info =~ /\d+\s(\d\d\d\d-\d\d-\d\d,\d\d:\d\d:\d\d\.\d+) / ) { # ex +cessively detailed. push @info, $1; # A +well written # ch +ar_class would be # an + improvement, as } # wu +d using quantifiers while ( $info=~ /(\w+=<.*?)>/g) { push @info, $1; } say Dumper @info;
output:
$VAR1 = '2013-04-05,12:10:51.909293'; $VAR2 = 'ACTION=<processing'; $VAR3 = 'FAN_A=<OK'; $VAR4 = 'FAN_B=<OK'; $VAR5 = 'SEND=<Sent mail (221 2.0.0 Service closing transmission chann +el)'; $VAR6 = 'FAILURE=<2';

If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1027224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found