in reply to Comparing arrays

<i> while (<INPUT1>) { my $line = $_; chomp $line; my @words = $line; } while (<INPUT2>) { my $line2 = $_; chomp $line2; my @words2 = $line2; } </i>

can be replaced with:

my @words1 = <INPUT1> my @words2 = <INPUT2>

Coming to matching strings you can use ^(match at beginning) and $(match at end of string) according to requirement. so that partial matching is done.

Life is a box of chocolates.. Perhaps you get to eat very few best ones!!

Replies are listed 'Best First'.
Re^2: Comparing arrays
by muba (Priest) on Jun 27, 2012 at 12:28 UTC

    Can it?

    use strict; use warnings; my @words1 = <INPUT1> my @words2 = <INPUT2> __END__ syntax error at G:\x.pl line 5, near "my " Global symbol "@words2" requires explicit package name at G:\x.pl line + 5. Execution of G:\x.pl aborted due to compilation errors.

    It's not even complaining about trying to read from unopened filehandles, because the error occurs at compile time - even before perl realizes that the read operation would fail. The solution is obvious - you forgot a semicolon. But even then, will it hold?

    use strict; use warnings; open INPUT1, "<", "x.pl"; my @words1 = <INPUT1>; print "<$_>\n" for @words1; __END__ <use strict; > <use warnings; > < > <open INPUT1, "<", "x.pl"; > <my @words1 = <INPUT1>; > <print "<$_>\n" for @words1;>

    That doesn't look right. And no wonder - your replacement doesn't do the chomping as it happens in OP's code.

    Surely you meant

    my @words1 = map {chomp; $_} <INPUT1>; my @words2 = map {chomp; $_} <INPUT2>;

Re^2: Comparing arrays
by zeni (Beadle) on Jun 27, 2012 at 09:34 UTC
    Btw where is your regular expression(code) to match strings?