Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: = rather than =~ ?

by Anonymous Monk
on Jan 01, 2004 at 17:17 UTC ( #318132=note: print w/replies, xml ) Need Help??


in reply to = rather than =~ ?

It depends. I don't know what $input is, but that code is matching against $_. If the match fails, the match fails. Such code should always be written something like $foo = $1 if /(foo)/;

Replies are listed 'Best First'.
Re: Re: = rather than =~ ?
by tachyon (Chancellor) on Jan 02, 2004 at 03:17 UTC
    my $foo = m/(foo)/ ? $1 : '';

    cheers

    tachyon

Re: Re: = rather than =~ ?
by ysth (Canon) on Jan 02, 2004 at 04:11 UTC
      If you feel the need point that one out, you should probably also explain why that is.. :)

      Makeshifts last the longest.

        $foo = $1 if /(foo)/; may very well be the expected behaviour in certain situations where we want to modify $foo if the match is successfull or leave it otherwise. Using it when declaring a variable is not desirable however. If there is no match, then $foo will not be declared and any attempt to read the scalar later will result in a "variable not declared" error. Of course, this is why we use strict;. Without it, we won't get an error :) defined.

        Basically, $foo = $1 if /(foo)/; should really only be used where we might otherwise do a $foo = /(foo)/ ? $1 : $foo; (which is just programatically ugly).

        Update: Whoa, was I off base. Read the replies to this node to see the reason :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318132]
help
Chatterbox?
[Discipulus]: who make the invitation? the program?!?
[choroba]: it's historical
[erix]: pull requests
[choroba]: originally, you sent a pull request to someone by email, i.e. you asked them to pull from your repo
[Discipulus]: if is the author of a patch, is more like a 'request to push' into rather than a pull request..
[choroba]: as it's considered unpolite to push to someone else's repo
[choroba]: and in fact, you don't push into the target repo, you push into your branch of your fork
[choroba]: the maintainer of the upstream repo than "merges" the pull request, i.e. they pull from your fork into the upstream
[Discipulus]: ' i.e. you asked them to pull from your repo' =~ I (subj) want to push
[Discipulus]: chorobayour words are reasonable

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-05-27 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?