Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Opinons Please

by Jonathan (Curate)
on Jan 18, 2001 at 18:26 UTC ( [id://52771]=perlquestion: print w/replies, xml ) Need Help??

Jonathan has asked for the wisdom of the Perl Monks concerning the following question:

It was in an item by Dominus (I think) that I found out that the \u and \L operators are interchangeable. i.e
$x = "string"; $x = "\u\L$x"; print $x,"\n"; $x = "string"; $x = "\L\u$x"; print $x,"\n";
Gives
String String
The reasoning behind this being that Perl assumes you made a typo and put them in the wrong order.

Do the Monks think that this is a good idea or not? Should Perl make this assumption?
Are there any other ocasions when Perl will do this sort of thing?

Granted it seems a harmless and reasonable thing to do in this case, but I remember having great 'fun' years ago with a 'C' compiler that when it discovered a undeclared variable would try to pattern match an existing one also assuming a typo.

Look, I'm not much good at big speeches, and I know I haven't always been an easy guy to get on with. And I know that, given the choice, I probably wouldn't have chosen you as friends. But, I just want to say ... that over the years, ... I have come to regard you ... as ... people ... I met. I'd just better go, OK?
Rimmers Farewell speech (one of them) - Red Drawf

Replies are listed 'Best First'.
Re: Opinons Please
by Blue (Hermit) on Jan 18, 2001 at 19:25 UTC
    One of the features of Perl is that it tries to do the right thing. If it didn't, it would be much more of a B&D language. Everything that -w warns you about it wouldn't make the assumptions on and would fail, everythng that use strict complains about wouldn't run.

    Perl doing the right thing is a design by Larry, and usually one of the touted features of Perl. Here at the monastery we espouse using -w and strict because we don't want to force Perl to try and figure out the right thing. Not because it's bad, but because we want to write correct programs from the get-go.

    =Blue
    ...you might be eaten by a grue...

Re: Opinons Please
by btrott (Parson) on Jan 18, 2001 at 22:20 UTC
Re: Opinons Please
by Jonathan (Curate) on Jan 18, 2001 at 19:48 UTC
    Sorry Blue I don't follow you.
    #!/usr/local/bin/perl -w use strict; my $x= "not a strict issue"; $x= "\L\u$x"; print $x,"\n";
    Not a strict issue <CODE>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found