Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Regex Issue

by choroba (Chancellor)
on Aug 01, 2013 at 15:53 UTC ( #1047479=note: print w/replies, xml ) Need Help??

in reply to Regex Issue

If there is a record delimiter, use it! Read the file record by record, and output only those that contain the wanted ID:
#!/usr/bin/perl use warnings; use strict; { local $/ = "==========\n"; while (<DATA>) { print "$/$_" if /ID: 3$/m; } } __DATA__ ========== Name: blah ID: 2 ========== Name: blah ID: 2 ========== Name: here ID: 3 ========== Name: blah ID: 2 ==========
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Regex Issue
by bluesplay106 (Novice) on Aug 01, 2013 at 16:01 UTC
    Would that work if there were multiple instances of ID: 3?
      Why don't you try it?


      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

      Hi bluesplay106,
      You wouldn't break a thing by trying out the solution you have been given by choroba. Change some of the ID given in that solution to 3 and try it out.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047479]
[Corion]: Meh. I need to find myself a better "programming" feed than r/programming (which is just HackerNews reposts and advertisements, very little code). Maybe I should select a list of links that I liked on r/programming and then google for ...
[Corion]: ... an aggregator site that also listed (ideally) all of these links once. And maybe also have an exclude list to blacklist some of the most spammy links that the site may have never mentioned at all
[marto]: I gave up reading HN at all, and feel much better for it :P

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-07-24 13:19 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (354 votes). Check out past polls.