Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

commandline and script behavior differs

by physi (Friar)
on Feb 10, 2003 at 11:25 UTC ( [id://234083]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://234083]
Approved by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-16 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found