[Melbourne-pm] Simple(?) question involving backticks and die

Scott Penrose scottp at dd.com.au
Wed Jan 4 21:41:02 PST 2006

Precedence really.

By doing this... "blah" || "blah"

You are saying you want one or other the scalars above. Therefore it  
returns in scalar context.

By using "or" you are lowering the precedence and thus it no longer  
treats it in scalar, but rather array context.

It is generally safer to use "or" unless you want to return the value.

	my $b = executethis() || "default value";

if you want to die then

	my $b = executethis() or die("ahh, it broke!");


On 05/01/2006, at 16:33, Benji Wakely wrote:

> On Thu, 5 Jan 2006 16:27:29 +1100 (EST),
> Tim Connors <tconnors+pmmelb at astro.swin.edu.au> wrote:
>>>   my @list = `/bin/ls /home` || die ("Couldn't list files");
>> Aren't you meant to use "or" rather than "||" when using die, for
>> precedence reasons?  Could this be what is happening? `` becomes  
>> scalar
>> context when combined with the ||  ?
> That checks out, and now I'll happily use 'or' rather than '||'
> in this situation.
> ...Wish I knew why it was so, though.
> --
> Benji Wakely
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm

* - *  http://www.osdc.com.au - Open Source Developers Conference * - *
Scott Penrose
VP in charge of Pancakes
scottp at dd.com.au

Dismaimer: If you receive this email in error - please eat it  
immediately to prevent it from falling into the wrong hands.

Please do not send me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

Microsoft is not the answer. It's the question. And the answer is no.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/melbourne-pm/attachments/20060105/c756232b/PGP.bin

More information about the Melbourne-pm mailing list