Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: contextual substitution with s///?

by mbethke (Hermit)
on Feb 01, 2013 at 16:33 UTC ( #1016581=note: print w/replies, xml ) Need Help??

in reply to contextual substitution with s///?

What choroba said. Your problem is the missing /m on the substitution so it only tries the first line in the string where it doesn't match.

If you want to split the line into space-separated fields later regardless of their meaning), couldn't you just use split /\s+/? When I have a task like this, I usually write a regex that captures a bunch of fields and ignores others, like this:
my $re = qr{ ^ (\S+ \s+ \S+ \s+ \S+) \s+ # time_stamp: Sep 18 00:00:58 (\S+) \s+ # host: mailgate04 [[:alpha:]]+/([[:alpha:]]+) # process: postfix/smtp: \S+ \s+ # PID: [29259]: (.*) # rest }ox; while(<$log>) { my ($time, $host, $rest) = /$re/o; ... }

In case you're interested in the timestamp field and few other things, you could also think about a simple substr(). The spaces are there just to make it easy to work with fixed field widths.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016581]
[Corion]: Oh, a test failure... Just force-install it then? --force and potentially --notest to skip the tests alltogether ?
[ambrus]: thezip: is Activestate Perl usable for your scenario instead?
[MidLifeXis]: Yeah, --notest is good, not sure I would do --force.
[thezip]: It fails 2/10 tests in that group. What are the ramifications if I force it? What should I look for for?
[thezip]: I've migrated from ActiveState to Strawberry. No going back...
[thezip]: I'll try the --notest arg first when I get back from meetings (after lunch).
[thezip]: Thanks guys for your comments! :-)
[1nickt]: Quick survey: has anyone used or even heard of autobox?
[Corion]: thezip: I would expect some (fancier?) numeric formatting to fail from these test failures
[1nickt]: ( Sometimes when idle I browse remote corners of the code repo at $work ... usually this yields knowledge of projects to decline and coworkers to avoid ... )

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2017-03-23 17:20 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (290 votes). Check out past polls.