Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: I am geting an unhelpful error message. Not sure how to debug it.

by GrandFather (Sage)
on Jun 18, 2012 at 00:22 UTC ( #976698=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976698]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-01-21 01:40 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.