Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Comparing arrays

by muba (Priest)
on Jun 27, 2012 at 12:28 UTC ( #978637=note: print w/ replies, xml ) Need Help??


in reply to Re: Comparing arrays
in thread Comparing arrays

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>;


Comment on Re^2: Comparing arrays
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-07-28 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls