Hi Ian and Prashant and all,

On Mon, 19 Oct 2015 09:28:15 -0500
Ian <pcs...@gmail.com> wrote:

> Take a look at File::Slurp.
> 

Just for the record, using File::Slurp is no longer recommended and one should
be using https://metacpan.org/pod/Path::Tiny or perhaps
https://metacpan.org/pod/File::Slurper instead.

Finally, a few notes on the code exercpt:

> Regards
> 
> On Mon, Oct 19, 2015 at 9:18 AM, Prashant Thorat <thorat.prash...@gmail.com>
> wrote:
> 
> > Hi All,
> >
> > I have a file with multiple lines ,I want to assign all content to
> > variable & then want to work on it.
> > Like want to match pattern /window/ from it.
> > how can it is possible ?
> > for example -
> >
> > open ( F1 ,"file.txt") || die "$!";
> >
> > $a=<F1>;
> >
> > if (/window/i){print
> > "it is present\n";
> > }
> >

1. Use three-args-open.

2. Use lexical filehandles.

3. Add "use strict;" and "use warnings;".

4. Don't abuse the "$a" variable.

5. Format/indent the code correctly.

6. You should bind the regular expression match to a lexical variable using:

if ($str =~ /window/i) {
        ...
}

For more info, see:

http://perl-begin.org/tutorials/bad-elements/

Regards,

        Shlomi Fish

> >
> >  
> 
> 



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Beginners Site for the Vim text editor - http://vim.begin-site.org/

<rjbs> sub id { my $self = shift; $json_parser_for{ $self }
    ->decode($json_for{ $self })->{id} } # Inside‐out JSON‐notated objects

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to