Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: How should I Extract data from text file. Pattern I have to extract should not repeated one.

by roboticus (Chancellor)
on Feb 04, 2018 at 14:43 UTC ( [id://1208424]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How should I Extract data from text file. Pattern I have to extract should not repeated one.
in thread How should I Extract data from text file. Pattern I have to extract should not repeated one.

jumdesumit:

Well, while you have several lines that match the pattern ([N01]{39}), none of the lines stop after the last [N01] match, they all have a semicolon and more text after them.

Try changing the line to not require that the line end immediately after that, like this:

if ( $line =~ /([N01]{39})/ )

or alternatively, specify that the string should be followed with a semicolon:

if ( $line =~ /([N01]{39});/ )

It would be helpful if you'd re-read perldoc perlre and verify that your expressions are saying what you really mean.

When I have a problem with a pattern, I usually do something akin to putting this at the start of the file:

use strict; use warnings; while (my $line = <DATA>) { if ($line =~ /([N01]{39})$/) { print "line $.: <$1>\n"; } } __DATA__

And then run the file as a perl script. Then you can tweak your regex until you get what you're looking for. For example, when I ran it with the above bit of code on the front, I got this:

Roboticus@Waubli ~ $ perl pm1208422.pl Roboticus@Waubli ~ $

I then removed the '$' from your condition, re-ran it and got:

Roboticus@Waubli ~ $ perl pm1208422.pl line 194: <NN0NNNNNNNNNNN0NNNNNNNNNNNNNNNNNNNNNNNN> line 196: <NN0NNNNNNNNNNN1NNNNNNNNNNNNNNNNNNNNNNNN> line 199: <NN0NNNNNNNNNNN1NNNNNNNNNNNNNNNNNNNNNNNN> line 201: <NN0NNNNNNNNNNN0NNNNNNNNNNNNNNNNNNNNNNNN> line 204: <NN0NNNNNNNNNNNNNNNNN0NNNNNNNNNNNNNNNNNN> line 206: <NN0NNNNNNNNNNNNNNNNN1NNNNNNNNNNNNNNNNNN> line 209: <NN0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN0NN> line 211: <NN00NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN1NN> line 214: <NN0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN0NNN> line 216: <NN0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN1NNN> . . . et cetera . . .

Update: Fixed wording and formatting (code tags so square brackets don't linkify) in first sentence.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

  • Comment on Re^3: How should I Extract data from text file. Pattern I have to extract should not repeated one.
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: How should I Extract data from text file. Pattern I have to extract should not repeated one.
by jumdesumit (Novice) on Feb 05, 2018 at 05:11 UTC

    Thank you so much for your help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found