Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: need help understanding perl syntax

by phaylon (Curate)
on Jun 17, 2006 at 14:50 UTC ( [id://555972]=note: print w/replies, xml ) Need Help??


in reply to Re: need help understanding perl syntax
in thread need help understanding perl syntax

That depends (as always). The difference is, yours is "better" because it just does more. It makes sure to only do something if the environment variable has a proper value. If you "feel" you'd have to do something if the value is incorrect, like emitting a warning or an error, the if version is great. If you have built or validated your string beforehand, or got it out of a data store where only valid strings are, you can just use the assignment. If you're not sure that you'll remember what it does (because you're not using it very often, for example) just add a comment that explains it. When in doubt, I'd recommend your version though.

hth, p

Ordinary morality is for ordinary people. -- Aleister Crowley
  • Comment on Re^2: need help understanding perl syntax

Replies are listed 'Best First'.
Re^3: need help understanding perl syntax
by holli (Abbot) on Jun 20, 2006 at 08:52 UTC
    You can have both:
    if ( ($host, $port) = ( $ENV{"http_proxy"} =~ /^(\S+)\:(\d+)$/ ) ) { print $host, "/", $port; } else { print "warning"; }


    holli, /regexed monk/

Log In?
Username:
Password:

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

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

    No recent polls found