[LA.pm] Spam:***, Re: little help??

Mike Dillon md5 at embody.org
Wed Sep 28 20:36:18 PDT 2005


begin Mike Dillon quotation:
> The comma after split is the problem. Using split with no arguments is
> basically the same as doing "split ' ', $_". Since $_ is undefined,
> you're getting a warning.
> 
> Really, though, you shouldn't be trying to split the string returned
> from localtime. You should use it in list context like so:
> 
>     my $hour = (localtime)[2];
> 
> In list context, localtime returns a numeric list of the parts of time.
> This avoids putting localtime into scalar context where you are forced
> to have to parse it with split.
> 
> Many built-in Perl functions have this dual mode of operation in scalar
> versus list mode. A good explanation can be found at
> <http://perl.plover.com/context.html>.

Looks like I was a little confused.

To be clear, you weren't actually using localtime in scalar context,
although with correct split syntax you would have been.

In your case, split was returning an empty list in front of the list
returned by localtime, making it so that that part actually worked the
same as my suggestion, just with a warning.

-md


More information about the Losangeles-pm mailing list