Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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
Node Status?
node history
Node Type: note [id://978603]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2018-03-23 12:04 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (292 votes). Check out past polls.