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

Re^7: The $_ Special Variable

by wind (Priest)
on Jun 21, 2011 at 19:43 UTC ( #910796=note: print w/replies, xml ) Need Help??


in reply to Re^6: The $_ Special Variable
in thread The $_ Special Variable

What do the strict and warnings commands do?

use strict requires that all variables be declared with either my or our. This is the number one thing you can do to ensure you're code is well made and without errors. use warnings is essentially an extension that monitors your code for unintended errors.

And what is the purpose of my before the objects? What does it do?

First of all, those aren't objects, they're simple variables. my is used to declare your variables and is useful for limiting their scope. If you were to mistype a variable or use the wrong type, use strict would alert you to the error

Also, what is the purpose of my $string = shift;?

If you read the documentation for shift, you'll see that in this instance it's equivalent to:

my $string = shift @ARGV;

Previously, you hardcoded $ARGV[0] in multiple places. It's much better to assign your script's parameters to variables as a way of documenting your code.

I don't understand the if (s/\Q$string\E/($string)/g) { conditional either.

\Q...\E is a shortcut syntax for quotemeta. This escaped any regex special characters in your $string, so that it would be treated as a literal value.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://910796]
help
Chatterbox?
[Mr. Muskrat]: (considered) Re^3: Please help with Regexp::Common needs to be reparented to Re^2: Please help with Regexp::Common
[Mr. Muskrat]: Is it just me or does that timeout issue seems to be happening more often lately?
[Corion]: Mr. Muskrat: I'm not sure if it really happens more often, but I don't exactly know either
[LanX]: yep
[LanX]: more often for some weeks now
[Corion]: I think I'll have to manually (as god) intervene with that node, as the simple reparenting didn't seem to fix the parent/child relationship of the nodes
[Corion]: I think I have an idea but I'll have to open a ticket with Pair.com on that - hopefully I get to that on the weekend
LanX imagines a burning thorn bush
[Mr. Muskrat]: Thank you!
[Mr. Muskrat]: Oh that is odd. I got the message that it was reparented but yeah, it didn't actually do it. lol

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-01-19 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.