Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Declaring with my, assigning, and testing in same line

by ww (Archbishop)
on Dec 11, 2015 at 17:46 UTC ( [id://1150055]=note: print w/replies, xml ) Need Help??


in reply to Declaring with my, assigning, and testing in same line

Seems to me the issue is the way doublequotes are interpolated. So...
      mayybe simpler still, but -- admittedly -- not one line:

#!/usr/bin/perl -w use 5.018; use strict; # 1150034 my %foo = ("do"=> "done", "eggs" =>"green ham", "was" => "were",); my @v; (@v = keys %foo) == 1 or warn "Got more than one: " . @v . "\n"; print "V:@v\n";

OUTPUT:

Got more than one: 3 V:was do eggs

Replies are listed 'Best First'.
Re^2: Declaring with my, assigning, and testing in same line
by AnomalousMonk (Archbishop) on Dec 11, 2015 at 18:56 UTC
    ... the issue is the way doublequotes are interpolated.

    No, per tye above, the problem is with scoping within a statement:

    c:\@Work\Perl\monks>perl -wMstrict -le "my %foo = qw(do done eggs ham was were); ;; my @v; (@v = keys %foo) == 1 or warn qq{Got more than one: @v}; print qq{V:@v}; " Got more than one: eggs was do at -e line 1. V:eggs was do


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found