Andy Bastien wrote:
> 
> There's a technique that I've been using for a while to set default
> values for variables, along the lines of:
> 
> my $foobar = (shift or 42);
> 
> I am correct in thinking that the '(shift or 42)' part creates an
> array slice with a single value, and that the assignment to $foobar
> converts that to a scalar? If so, is there a better way to do this
> that doesn't involve this conversion?

The parens in this case merely group the 'shift or 42'.

Other ways of writing the same:

# given...
@ARGV = (1 .. 3);

# equivalent
$foo[0] = (shift or 42);
$foo[1] = shift || 42;
$foo[2] = ($ARGV[0]) ? shift : 42;

# test
print map {"$_\n"} @foo;

Results:
1
2
3

HTH
-- 
I am following my fish.
    -- Delirium, The Sandman
_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to 
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users

Reply via email to