Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Get variables from if with regex

by choroba (Cardinal)
on Mar 08, 2013 at 13:51 UTC ( [id://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"; } }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1022424]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found