[comp.lang.perl] sh: foo=${bar-baz}; perl:

maart@cs.vu.nl (Maarten Litmaath) (07/31/90)

Anything better?  Remember, the variables could have looooooooong names
you rather wouldn't retype.
--
 "and with a sudden plop it lands on usenet.  what is it? omigosh, it must[...]
   be a new user! quick kill it before it multiplies!"      (Loren J. Miller)

merlyn@iwarp.intel.com (Randal Schwartz) (07/31/90)

In article <7195@star.cs.vu.nl>, maart@cs (Maarten Litmaath) writes:
| Anything better?  Remember, the variables could have looooooooong names
| you rather wouldn't retype.

Is cheating OK? :-)

$_ = $bar; $foo = (length) ? $_ : "baz";

Your solution fails on $bar = "\n" (at least).

$_ = "Just another "; print $_ .= "Perl hacker,"
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (08/01/90)

In article <7195@star.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
: Anything better?  Remember, the variables could have looooooooong names
: you rather wouldn't retype.

I fail to see the name you had to retype in

	($foo = $bar) =~ s/^$/baz/;

However, if, as is often the case, you know $bar isn't going to have the
value "0", it's shorter and much more intuitive to say

	$foo = $bar || "baz";

as in

	$home = $ENV{'HOME'} || $ENV{'LOGDIR'} || (getpwuid($<))[7] || die;

Larry

maart@cs.vu.nl (Maarten Litmaath) (08/01/90)

In article <8946@jpl-devvax.JPL.NASA.GOV>,
	lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
)In article <7195@star.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
): Anything better?  Remember, the variables could have looooooooong names
): you rather wouldn't retype.
)
)I fail to see the name you had to retype in
)
)	($foo = $bar) =~ s/^$/baz/;

Precisely the point!  I wanted to circumvent some obvious approach like:

	length($foo = $bar) || ($foo = 'baz');

...taking which one has to retype `$foo'.

)However, if, as is often the case, you know $bar isn't going to have the
)value "0", it's shorter and much more intuitive to say
)
)	$foo = $bar || "baz";
)
)as in
)
)	$home = $ENV{'HOME'} || $ENV{'LOGDIR'} || (getpwuid($<))[7] || die;

Thanks for this suggestion.  In general, however, one seems to be stuck
to the `obvious solution'.  (Thanks for pointing out the problem with my
initial hack, Randal.)
--
 "and with a sudden plop it lands on usenet.  what is it? omigosh, it must[...]
   be a new user! quick kill it before it multiplies!"      (Loren J. Miller)