Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: Multiple strings in a file

by vinoth.ree (Monsignor)
on Feb 10, 2015 at 18:34 UTC ( [id://1116218]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Multiple strings in a file
in thread Multiple strings in a file

Hi,

Let see this code,

use strict; use warnings; my $firstString='Trap'; my $secondString='hair'; open my $text, "<test.txt" or die "Dead"; while(<$text>){ print if (m/($firstString|$secondString)/i) }
file:
Transformers robots in disguise
I whip my hair back and forth
I will catch a dog with a trap

It prints the output as,

I whip my hair back and forth
I will catch a dog with a trap

But as you want to match the 'Trap' first which is in the third line, should be printed first and 'Hair' should be printed next. Is that you wanted?


All is well

Replies are listed 'Best First'.
Re^6: Multiple strings in a file
by The_Last_Monk (Novice) on Feb 10, 2015 at 18:37 UTC
    Yes, that is exactly what i wanted!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-28 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found