On Dec 15, 5:17 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
> Uri Guttman wrote:
> >>>>>> "SHC" == Shawn H Corey <shawnhco...@gmail.com> writes:
> >   SHC> Try:
> >   SHC> my $month = '';
> >   SHC> $month = $ARGV[0] if $ARGV[0];
>
> > or just use ||:
>
> >    my $month = $ARGV[0] || '' ;
>
> $ cat myscript.pl
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $month = $ARGV[0] || '';
> print "month = '$month'\n";
> $ ./myscript.pl 0
> month = ''
>
> Doesn't always work right.
>

A slight change should work right:

  my $month    =  defined $ARGV[0] ? $ARGV[0] : '';
  # my $month = $ARGV[0] // '';     # 5.10

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to