Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Confused by a couple of idioms

by jwkrahn (Abbot)
on Feb 21, 2019 at 22:23 UTC ( [id://1230337]=note: print w/replies, xml ) Need Help??


in reply to Confused by a couple of idioms

"o|c|out=s" => \my $csv creates $csv at this point as a lexical variable and assigns a reference to it to (I assume) this hash value.

$csv and $xls = $csv; tests if $csv is true, and if it is, assigns its value to $xls.

It's the same as: $csv && ( $xls = $csv );.

Replies are listed 'Best First'.
Re^2: Confused by a couple of idioms
by ateague (Monk) on Feb 21, 2019 at 22:27 UTC

    Here is the code in question in context; it is part of Getopt::Long

    use Getopt::Long qw( :config bundling noignorecase passthrough ); GetOptions ( "help|?" => sub { usage 0; }, "V|version" => sub { print "$cmd [$VERSION]\n"; exit 0; }, "man" => sub { exec "pod2man $0 | nroff -man"; }, "info" => sub { require Pod::Usage; Pod::Usage::pod2usage (VERBOSE => 2); exit; }, "o|c|out=s" => \my $csv, "i|s|in=s" => \my $xls, "f|force!" => \my $opt_f, "A|all!" => \my $opt_a, "N|no-pfx!" => \my $opt_N, ) or usage 1;

    It is assigning the value from the -o, -c, or --out switches to the $csv lexical variable that it is defining in-line

Re^2: Confused by a couple of idioms
by nysus (Parson) on Feb 21, 2019 at 23:54 UTC

    Yeah, I just never knew you could put a backslash before "my." I've never seen that. Is that basically shortcut for:

    my $csv; %hash = { key => $csv };

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found