in reply to Reaped: Re^2: case sensitive addition
in thread case sensitive addition

Nathan_84,
I didn't provide any code - only the suggestion that you read the documentation. I probably would not write a perl program to do what you are doing, but if I were to modify your code - it would be something like the following (untested):
#!/usr/bin/perl use warnings; use strict; print 'Enter a File name: '; chomp (my $file = <STDIN>); print 'Enter a search pattern: '; chomp (my $pattern = <STDIN>); open (my $fh, '<', $file) or die "Unable to open '$file' for reading: +$!"; my $found = 0; while (<$fh>) { if (/\Q$pattern\E/i) { print; $found++; } } print "\nTotal lines matched: $found\n";

Cheers - L~R

Replies are listed 'Best First'.
Re^4: case sensitive addition
by Nathan_84 (Acolyte) on May 14, 2010 at 23:49 UTC
    Hey I just wanted to say thanks for the quick response. Just tried your code and it worked a treat! Thanks again. My next challenge is to display a time and date when the search was carried out. Thanks again sir! :)
Re^4: case sensitive addition
by Nathan_84 (Acolyte) on May 15, 2010 at 01:56 UTC
    Hi Limbic Region,
    I've been racking my brains out to just to add a simple data and time to script so that user can see when the search was performed.
    I found the script below as a standalone and worked perfectly fine. However trying to integrate it failed miserably!
    ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); printf "%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hour,$min,$sec;

    Please could you advise.
    Thanks

      Please, read some docs. Expend some effort on something other than asking questions already answered in those docs.

      Then, show some effort - read the key docs about PM:

      It is gratifying that you do appear to have read one usual element of a message such as this... that is, the admonition to use <code> tags. ++ for that; not so for the rest of your post.