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

Re: extracting data

by mirod (Canon)
on Jun 27, 2012 at 09:33 UTC ( #978603=note: print w/replies, xml ) Need Help??

in reply to extracting data

Do you really need to use split? Why not match exactly what you want in the main loop?

#!/usr/bin/perl use strict; use warnings; use feature 'say'; while (<DATA>) { # should you need it, the value is in $2, undef if not present say $1 if m{^ \s* \#define \s+ (\S+) (?:\s+ (0|1))? \s* $}x; } __DATA__ #define thread 1 #define flag #define code 0 #define const (100/5) #define flag_condn 1

A couple of notes: if you are using an ancient (pre 5.10) perl, then don't use use feature 'say'; and say, instead use print $1, "\n";. The /x modifier allows nicer formating for the regexp: whitespace is ignored, comments are allowed (hence the \# here, since it's not a comment) and the regexp can be spread over several lines.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-09-19 00:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found