Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Pattern String Matching while parsing a file

by pawarr (Initiate)
on Jul 07, 2016 at 09:35 UTC ( #1167359=perlquestion: print w/replies, xml ) Need Help??

pawarr has asked for the wisdom of the Perl Monks concerning the following question:

I wanted to add the code of string matching for the string 'EDA' to this code of file parsing. The code is provided below. Please Help.

#!/usr/bin/perl use strict; use warnings; open(my $fh,'data4.txt'); while(my $row = <$fh>){ chomp $row; print "$row \n"; }

Replies are listed 'Best First'.
Re: Pattern String Matching while parsing a file
by Laurent_R (Canon) on Jul 07, 2016 at 12:25 UTC
    For a simple literal match in a string, look at the index builtin function.

    As a side note, please note that it is probably unnecessary to chomp your input line if you're just going to add "\n" to it immediately after.

Re: Pattern String Matching while parsing a file
by Anonymous Monk on Jul 07, 2016 at 09:38 UTC
Re: Pattern String Matching while parsing a file
by pme (Prior) on Jul 07, 2016 at 13:47 UTC
    #!/usr/bin/perl use strict; use warnings; open(my $fh,'data4.txt'); while(<$fh>){ print if /EDA/; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1167359]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2019-12-10 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?