Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Python tricks

by rsFalse (Hermit)
on Mar 04, 2019 at 13:22 UTC ( #1230837=note: print w/replies, xml ) Need Help??


in reply to Python tricks

It is better to avoid using special variables '$a' and '$b'.
Use different name, e.g. '$_a', or longer meaningful name, or uppercase letter.
#!/usr/bin/perl -lw use strict; my ($a, $b) = (7, 5); ($b, $a) = ($a, $b); print join ' ', sort { $a <=> $b } qw( 5 28 1 ); print "$b $a";
STDOUT:
5 1 28 7 5
STDERR:
"my $a" used in sort comparison at prog.pl line 8. "my $b" used in sort comparison at prog.pl line 8.
I suggest to update examples with using of different names ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2020-01-21 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?