in reply to localtime array slice problem

#!/usr/bin/perl -w use strict; my @List=(localtime)[1,3]; print @List;
result: 3311

your code with 'use strict':
Ambiguous use of @{localtime} resolved to @localtime at ./tmp line 6. Global symbol "@localtime" requires explicit package name at ./tmp lin +e 6. Execution of ./tmp aborted due to compilation errors.

Start with using strict... build from there, it will tell you
when you are REALLY messing up

GreetZ!,

print "profeth still\n" if /bird|devil/;

Replies are listed 'Best First'.
Re: Re: localtime array slice problem
by InfiniteSilence (Curate) on Jan 12, 2001 at 00:32 UTC
    Good point about trying new things out inside of a script with warnings and use strict on. In this case, since I already knew that localtime is a function, I was able to use the following to get right past both -w and use strict:
    #!/usr/bin/perl -w use strict; print @{localtime()}[1,3]; 1;
    Running this as
    perl -c ltimetest.pl
    checks out okay, but running it tells me that I "Can't use string ("Thu Jan 11.... as an ARRAY ref while in strict subs..."

    Quick question: Why did -c pass where running the script generates the uncaught exception?-

    Celebrate Intellectual Diversity

      Can't use string %s as %s ref while "strict refs" in use is a runtime error. -c is only for catching compile-time errors.

      There are many, many errors that can occur when a script is running but don't prevent the script from compiling. Here's another example:

      $x = 0; $y = 7 / $x;