in reply to passing a scalar to a function

Arguments to subroutines are passed in the array @_, not in $_.

You could do something like this:

sub mycheck { my $db = shift || ""; } # or sub mycheck2 { my $db = @_ ? $_[0] : ""; }

Replies are listed 'Best First'.
Re^2: passing a scalar to a function
by linuxer (Curate) on May 19, 2008 at 11:07 UTC

    I want to point out, that we should be aware of the difference in those two solutions:

    The first solution will set $db to "", when the argument evaluates to FALSE.
    This will happen, when the argument is undef, empty string or 0 [zero]).

    So if undef and zero are wanted and valid values, the second solution should be used.

Re^2: passing a scalar to a function
by nsupathy0 (Initiate) on May 19, 2008 at 13:02 UTC
    Thank you for your wisdom. That was really helpful. $_ was a typo. I thought there was a "perl" way of doing this. The idiom  @_ ? $_[0] : "" was a better one.