physi has asked for the wisdom of the Perl Monks concerning the following question:

Dear Sisters & Brothers

I've got a in my eyes strange behavior:
This small line works on the commandline:

perl -e '@a=(a..z,A..Z); print $a[rand @a]'
but within a script I have to write:

#!/usr/bin/perl use strict; use warnings; my @a = ('a'..'z','A'..'Z'); print $a[rand @a];

Can anyone explain it, why I have to quote the letters in the script, while I haven't on the commandline ?

Cheers
physi

-----------------------------------
--the good, the bad and the physi--
-----------------------------------

Replies are listed 'Best First'.
Re: commandline and script behavior differs
by fruiture (Curate) on Feb 10, 2003 at 11:30 UTC

    You don't use strict on the commandline, that's why. Try:

    perl -Mstrict -we '@a=(a..z,A..Z); print $a[rand @a]'
    --
    http://fruiture.de
      ohhh my god !!!!

      Thanks for that ;-)

      -----------------------------------
      --the good, the bad and the physi--
      -----------------------------------
      
Re: commandline and script behavior differs
by broquaint (Abbot) on Feb 10, 2003 at 11:39 UTC
    Can anyone explain it, why I have to quote the letters in the script, while I haven't on the commandline ?
    Because you're using strict and it doesn't allow you to leave barewords about at your leisure. Also strict and warnings aren't required for scripts, they're just an awfully good idea.
    HTH

    _________
    broquaint