[lug] perl question

Timothy C. Klein teece at silverklein.net
Sun Jun 9 18:22:27 MDT 2002


* j davis (davis_compz at hotmail.com) wrote:
> hello,
> 
>  I have a small perl script that can be passed 2 args. before i made
> the script take args it worked great , now that it takes args i am
> having to rewrite the scrip because everytime i request user input with..
> $foo = <>;
> it gets messed up and doesent ask for user input and just keeps going 
> assinging
> $foo odd stuff. Before user input went smooth. the request for user input is
> in a while loop nested in a else. Dont know if that makes a diff but thought
> i should mention it. If this is not enough info or just plain dumb , i'm 
> sorry.
> i will gladley post the scrip its very small.

Doesn't the <> operator mean, read from all files provided on the
command line, if given, if no files are given, read from STDIN?  I
believe that is how it is supposed to work.  Your script probably worked
sort of by accident before.  You should read from the user explicitly
from standard in, as the <> operator is too smart, it is turning a
DWIMmer acpect of Perl into a poorly incanted Dweomer.  (He
he, I just love Wall's humor.  DWIM - Do What I Mean, requires a lot of
behind the scenes magic.  Dweomer, an incantation or spell.  Thus, it
often takes dweomer to get the dwimmer to work.  Here, it ain't.
Working, that is).

You would be better off getting info from the user thus:

chomp($tmp=<STDIN>);

Kill the chomp if you really want the extra line feed that might
(probably) be there at the end.

HTH,

Tim
--
==============================================
== Timothy Klein || teece at silverklein.net   ==
== ---------------------------------------- ==
== "Hello, World" 17 Errors, 31 Warnings... ==
==============================================



More information about the LUG mailing list