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)