Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: If statement not working

by AnomalousMonk (Bishop)
on Jun 25, 2020 at 18:44 UTC ( #11118544=note: print w/replies, xml ) Need Help??


in reply to Re: If statement not working
in thread If statement not working

This is an assignment (using =) clobbering $_ with an empty array. An assignment of an undefined ... Similar to if ($_ = ()) or if ($_ = undef).

$_ is clobbered with the true/false result of evaluating the match of the regex against $_:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "print 'Enter a string and I will determine the data type: '; chomp($_ = <STDIN>); dd 'A:', $_; ;; if ($_ = (m/^[\$]\w/)) { print qq{\n'$_' is a scalar data type\n}; } dd 'B:', $_; ;; if ($_ = (m/^[\@]\w/)) { print qq{\n'$_' is an array data type\n}; } dd 'C:', $_; " Enter a string and I will determine the data type: $scalar ("A:", "\$scalar") '1' is a scalar data type ("B:", 1) ("C:", "") c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "print 'Enter a string and I will determine the data type: '; chomp($_ = <STDIN>); dd 'A:', $_; ;; if ($_ = (m/^[\$]\w/)) { print qq{\n'$_' is a scalar data type\n}; } dd 'B:', $_; ;; if ($_ = (m/^[\@]\w/)) { print qq{\n'$_' is an array data type\n}; } dd 'C:', $_; " Enter a string and I will determine the data type: @ra ("A:", "\@ra") ("B:", "") ("C:", "")


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

Replies are listed 'Best First'.
Re^3: If statement not working
by perlfan (Priest) on Jun 25, 2020 at 19:59 UTC
    ty fixed

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2020-09-27 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (142 votes). Check out past polls.

    Notices?