Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Some assistance with splitting variables

by ww (Bishop)
on Apr 05, 2013 at 21:53 UTC ( #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!


Comment on Re: Some assistance with splitting variables
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2014-04-16 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (427 votes), past polls