Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Conditional continued matching with regexes

by bart (Canon)
on Feb 06, 2007 at 08:11 UTC ( [id://598495]=note: print w/replies, xml ) Need Help??


in reply to Re: Conditional continued matching with regexes
in thread Conditional continued matching with regexes

Wah, this is clever... I'd never have thought of that! Well, I will, in the future! ;-) (n.b. you need to add the /g modifier)

BTW, there's a syntax for tr that serves to just count occurrences, without changing anything. Just leave the RHS empty, which is like replacing characters by themselves while counting, but which is optimizined to skip the replacing.

tr/"//

You still need to cater for the abnormal case where the file contains an odd number of quotes, thus, check for eof.

Update Judging by the tests I've done, the next snippet will work excellently for reading and processing data from <>, and includes processing for the final record for each file, even if incomplete:

while(<>) { while(!eof and tr/"// % 2) { $_ .= <>; } # ... do stuff with each record in $_ }

Replies are listed 'Best First'.
Re^3: Conditional continued matching with regexes
by dah (Sexton) on Feb 07, 2007 at 08:13 UTC
    Hurrah!
      So you don't have embedded " within fields?
      "foo"ba
      r",1231

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-19 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found