[kw-pm] conditionals and the comma operator
Robert P. J. Day
rpjday at crashcourse.ca
Mon Jan 5 06:39:16 PST 2009
On Mon, 5 Jan 2009, Fulko Hew wrote:
> On Mon, Jan 5, 2009 at 7:41 AM, Robert P. J. Day <rpjday at crashcourse.ca> wrote:
> >
> > i'm sure i'm about to embarrass myself with how much i've forgotten
> > my perl, but i'm reading a perl program and, early on, it sets default
> > command line args thusly:
> >
> > ================================
> > my ($input,$vm_output,$rfs_output) = @ARGV;
> >
> > $vm_output = cwd . '/vmlinux',
> > if (! defined ($vm_output) || $vm_output eq '');
> > $rfs_output = cwd . '/initramfs.cpio.gz',
> > if (! defined ($rfs_output) || $rfs_output eq '');
> > ...
> > ================================
> >
> > i know what that early processing is meant to do -- assign default
> > values to $vm_output and $rfs_output unless the user has specified
> > those values on the command line. but how is that being done above?
> >
> > i vaguely recall that there was a perl idiom that involved the comma
> > operator to do something like that, but i don't see how that's being
> > done above. can someone refresh my memory? thanks.
>
> I can't help on your comma question, but I'd say in the above case...
> that the comma is irrelevant
ah, i remember the idiom that i was thinking of:
$var = $var || new_value;
as in (from my example above):
$vm_output ||= cwd . '/vmlinux'; (the short form)
isn't that the idiom? if the variable is set, it stays set to that
value. if it's not set, it will be assigned the given value. am i
remembering that right?
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.
http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================
More information about the kw-pm
mailing list