Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: s/// operator and binding

by ibanix (Hermit)
on Jan 28, 2003 at 00:27 UTC ( [id://230420]=note: print w/replies, xml ) Need Help??


in reply to Re: s/// operator and binding
in thread s/// operator and binding

D'OH! That's so obvious!

Thanks. Why do you find it ugly? Is there a better way to do it?

Cheers,
ibanix

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Replies are listed 'Best First'.
Re: Re: Re: s/// operator and binding
by sauoq (Abbot) on Jan 28, 2003 at 00:39 UTC

    I don't want to answer for Ovid but I especially dislike mixing the declaration with that kind of assignment. I'd prefer

    my $foo; ($foo = $bar) =~ s/baz/qux/;
    but if you are going to separate them anyway, it makes perfect sense to do it in a way that makes all the steps blindingly obvious such as this:
    my $foo = $bar; $bar =~ s/baz/qux/;
    There's rarely a good reason to sacrifice clarity for brevity.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Re: s/// operator and binding
by Cat (Initiate) on Jan 28, 2003 at 00:45 UTC
    Well it's ugly to me because it's not immediately apparent what you're trying to do. Why not just do this
    my($path) = $logfilepath; $path =~ s/$ref_srv/$server/i;
    Choosing between the two, I'd go with the simpler. Just because you can do something doesn't mean you should ;)

    update (broquaint): changed <pre> to <code>

Re: Re: Re: s/// operator and binding
by Ovid (Cardinal) on Jan 28, 2003 at 00:45 UTC

    For me, this is an aesthetic thing that you can safely ignore. If I want extra parentheses, I'd code in Lisp :)

    If you like them, however, it's not a problem, so don't worry about my blather.

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found