How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?
I wonder if I can use the Pythonic practice of inserting:
assert 0, (foo, bar)
to debug scripts in a debuger-less way?
There is a strange scalar variable called $_ in Perl, which is the default variable, or in other words the topic. In Perl, several functions and operators use this variable as a default, in case no parameter is explicitly used.
The \G assertion in Perl allows you to continue searching from the point where the last match occurred.
my keyword in Perl declares the listed variable to be local to the enclosing block in which it is defined. The purpose of my is to define static scoping. This can be used to use the same variable name multiple times but with different values.
A quick CPAN search suggests Carp::Assert.
See Carp::Assert:
use Carp::Assert; $next_sunrise_time = sunrise(); # Assert that the sun must rise in the next 24 hours. assert(($next_sunrise_time - time) < 24*60*60) if DEBUG; # Assert that your customer's primary credit card is active affirm { my @cards = @{$customer->credit_cards}; $cards[0]->is_active; };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With