http://www.perlmonks.org?node_id=976698


in reply to I am geting an unhelpful error message. Not sure how to debug it.

When learning is a good time to get into good habits. A few things have been pointed out by previous posters, but lets look at your whole sample and see where it can be improved.

First, using strictures is highly recommended - well done. But it is more conventional now to use use warnings; instead of -w on the command line to enable warnings.

Don't "pre-declare" variables. Declare them where you first need them and generally initialise them at the same time. Get into the habit of using sensible variable names. Short names are ok where they are only used in a small scope, but even then meaningful names can help a lot in understanding code. In particular avoid $a and $b because they have special meaning in the context of sort.

Rolling these suggestions into those from previous replies and applying the scalar fix suggested elsewhere your sample code turns into something like:

#!/usr/bin/perl -w use strict ; my ($a, @line) ; print "Please specify a file." ; chomp ($a = <STDIN>) ; open ($a) ; foreach @line ($a) { print reverse(@line); }

Prints (given the script file as input):

Please specify a file: noname.pl lrep/nib/rsu/!# ;tcirts esu ;sgninraw esu ;" :elif a yficeps esaelP" tnirp ;)>NIDTS< = emanelif$ ym(pmohc ;"n\!$ :emanelif$ nepo t'naC" eid ro emanelif$ ,'<' ,nIelif$ ym nepo { )>nIelif$< = enil$ ym( elihw ;)enil$(esrever ralacs tnirp }
True laziness is hard work