http://qs321.pair.com?node_id=1067945


in reply to Re^6: difference between two files
in thread difference between two files

"I have some code on my home-node to automatically do that."

With respect, I didn't know about that until you told me. Do you think varalaxmibbnl knows this is here or how to use it? Do you believe this code you have on your homenode is better to give to those wishing to learn perl than the built in, cross platform features? This seems system specific (you use cat).

I clicked the download link, ran your code and got this:

Unrecognized character \xE2; marked by <-- HERE after $s<-- HERE near +column 3 at ./foo.pl line 3.

I've downloaded thousands of code examples from this site and never hit this problem. hexdump -C foo.pl:

bash-4.2$ hexdump -C foo.pl 00000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 70 |#!/usr/bi +n/env p| 00000010 65 72 6c 0a 0a 24 73 e2 80 8e 63 72 69 70 e2 80 |erl..$s.. +.crip..| 00000020 8e 74 20 3d 20 73 68 69 66 74 3b 0a 24 5f 20 3d |.t = shif +t;.$_ =| 00000030 20 60 24 5e 58 20 2d 4d 73 74 72 69 63 74 20 2d | `$^X -Ms +trict -| 00000040 63 20 24 73 e2 80 8e 63 72 69 70 e2 80 8e 74 20 |c $s...cr +ip...t | 00000050 32 3e 26 31 60 3b 0a 77 68 69 6c 65 20 28 2f 5e |2>&1`;.wh +ile (/^| 00000060 47 6c 6f 62 61 6c 20 73 79 6d 62 6f 6c 20 22 28 |Global sy +mbol "(| 00000070 2e 2b 3f 29 22 2f 67 6d 29 20 7b 0a 20 20 20 20 |.+?)"/gm) + {. | 00000080 24 6d 79 73 7b 24 31 7d 20 3d 20 31 3b 0a 7d 0a |$mys{$1} += 1;.}.| 00000090 24 6d 79 73 20 3d 20 6a 6f 69 6e 20 27 2c 27 2c |$mys = jo +in ',',| 000000a0 20 6b 65 79 73 20 25 6d 79 73 3b 0a 24 5f 20 3d | keys %my +s;.$_ =| 000000b0 20 60 24 5e 58 20 2d 4d 77 61 72 6e 69 6e 67 73 | `$^X -Mw +arnings| 000000c0 20 24 73 e2 80 8e 63 72 69 70 e2 80 8e 74 20 32 | $s...cri +p...t 2| 000000d0 3e 26 31 60 3b 0a 77 68 69 6c 65 20 28 2f 5e 55 |>&1`;.whi +le (/^U| 000000e0 73 65 20 6f 66 20 75 6e 69 6e 69 74 69 61 6c 69 |se of uni +nitiali| 000000f0 7a 65 64 20 76 61 6c 75 65 20 28 5b 5c 24 5c 25 |zed value + ([\$\%| 00000100 5c 40 5d 5c 53 2b 29 2f 67 6d 29 20 7b 0a 20 20 |\@]\S+)/g +m) {. | 00000110 20 20 69 66 20 28 73 75 62 73 74 72 28 24 31 2c | if (sub +str($1,| 00000120 20 30 2c 20 31 29 20 65 71 20 27 24 27 29 20 7b | 0, 1) eq + '$') {| 00000130 0a 20 20 20 20 20 20 20 20 24 73 74 75 66 66 20 |. +$stuff | 00000140 2e 3d 20 22 24 31 20 3d 20 27 27 3b 5c 6e 22 3b |.= "$1 = +'';\n";| 00000150 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 |. } el +se {. | 00000160 20 20 20 20 20 20 24 73 74 75 66 66 20 2e 3d 20 | $st +uff .= | 00000170 22 24 31 20 3d 20 28 29 3b 5c 6e 22 3b 0a 20 20 |"$1 = (); +\n";. | 00000180 20 20 7d 0a 7d 0a 70 72 69 6e 74 20 22 75 73 65 | }.}.pri +nt "use| 00000190 20 73 74 72 69 63 74 3b 5c 6e 75 73 65 20 77 61 | strict;\ +nuse wa| 000001a0 72 6e 69 6e 67 73 3b 5c 6e 5c 6e 6d 79 20 28 24 |rnings;\n +\nmy ($| 000001b0 6d 79 73 29 3b 20 24 73 74 75 66 66 5c 6e 22 3b |mys); $st +uff\n";| 000001c0 0a 73 79 73 74 65 6d 20 22 63 61 74 20 24 73 e2 |.system " +cat $s.| 000001d0 80 8e 63 72 69 70 e2 80 8e 74 22 3b 0a |..crip... +t";.| 000001dd

I have confirmed with others (here) that they experience the same problem. Once I've fixed each instance of $script I get the output from your program, run against the code provided by varalaxmibbnl:

use strict; use warnings; my ($line,@cnt_file,$cnt); #!/usr/bin/perl open (FILE,"file1"); @cnt_file = <FILE>; $cnt = @cnt_file; print "$cnt\n"; open (MYFILE,"file2"); $line = <MYFILE>; foreach $line (<MYFILE>) { print "$line" if $. >= $cnt; }

Piping the output to a file and making said file executable results in:

./xx.pl: line 1: use: command not found ./xx.pl: line 2: use: command not found ./xx.pl: line 4: syntax error near unexpected token `$cnt,$line,@cnt_f +ile' ./xx.pl: line 4: `my ($cnt,$line,@cnt_file); '

Due to the shebang line is on line 5.

To summarise, currently there's an issue with downloading the code as provided on your homenode, the output from your suggested solution is (IMHO) not ideal.

"It has nothing to do with any problems the OP has"

I guess that depends on what you consider the "problems" to be. Trying things at random, copying and pasting code found online without knowing what it does (which can be a dangerous), then asking others to fix it when it doesn't do what they want? If you consider the goal to give advice which when starting out will be helpful, regardless of platform then I think my advice is sound. From a lot of experience here simply fixing or providing code on request more often than not results in subsequent posts of the same quality. I think it may be the exception where the users in question make some effort to learn from the code/explanation they've been given, we just end up with posts often emails from their employer/boss or exam/homework questions copied verbatim.

I don't agree that beginners should avoid using strict/warnings for the reasons mjd has illustrated in that document. They quite clearly have an advanced knowledge of the language and tools they are using. This is precisely what new users don't have. IMHO beginners need a gentle introduction strict/warnings more often than not give them the feedback they need to work out how to resolve their problems, or at least where to look and what questions to ask, which boosts confidence. Strict/warnings as with any tool, be it a soldering iron, 3D printer or a piece of software, the user need to spend time to learn what it does and how to use it.

Update: Added last sentence.