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

Re^3: Get variables from if with regex

by choroba (Canon)
on Mar 08, 2013 at 13:51 UTC ( #1022424=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Get variables from if with regex
in thread Get variables from if with regex

Do you really need to split the paragraph into lines? You can match a multiline string against a regex, too:

#!/usr/bin/perl use warnings; use strict; $/ = "\n\n"; while (<>) { my @result; if ( /objectClass:\s+account/ and /objectClass:\s+ifastUser/ and my ($prods) = /ifastProducts:\s+(.+?)\s*$/mg # The /m is +important here. and my ($user) = /dn: uid=(\w+?),./g) { push @result, $prods, $user; print join '|', @result; print "\n"; } }

But if you need the array, you can have it. The , $_) part of your code does nothing, so remove it. Here is my attempt to do what you need:

#!/usr/bin/perl use warnings; use strict; $/ = "\n\n"; while (<>) { my @result; my @lines = split /\n/; if ( ( grep /objectClass:\s+account/, @lines) and (grep /objectClass:\s+ifastUser/, @lines) and (my ($prods) = map /ifastProducts:\s+(.+?)\s*$/g, @lines) and (my ($user) = map /dn: uid=(\w+?),.+/g, @lines +)) { push @result, $prods, $user; print join '|', @result; print "\n"; } }
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^3: Get variables from if with regex
Select or Download Code
Re^4: Get variables from if with regex
by Saved (Beadle) on Mar 08, 2013 at 14:08 UTC
    Looking Good so far! Thanx a bunch

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (17)
As of 2015-07-06 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (79 votes), past polls