At 10:22 PM 6/7/01 +0200, M.W. Koskamp wrote:

>----- Original Message -----
>From: Peter Scott <[EMAIL PROTECTED]>
>To: Byron Rendar <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
>Sent: Thursday, June 07, 2001 9:11 PM
>Subject: Re: double quotes around a variable
>
>
> > At 09:50 AM 6/7/01 -0700, Byron Rendar wrote:
> > >my $input    = <STDIN>;
> > >  my $username = chop( $input );
> > >print "$username";
> > >
> > >Why are double quotes around $username a "bad" thing in the print
>statement?
> >
> > They're bad mainly because they suggest that the author doesn't understand
> > Perl well.  So if I see code like that, my spidey sense starts tingling
>and
> > I wonder how good the code is.  Why would someone type unnecessary quotes
> > unless they were confusing Perl with the Bourne shell, in which case they
> > may well have made some real mistakes?
>
>I dont agree with that.
>Using quotes in print statements is a good habit. It makes code more
>readble, since it is clear that the intention is to print a scalar value as
>a string.
>Without quotes the scalar value could also be a FileHandle instance or a
>subroutine reference.
>So i think proper quoting is not making your code bad.

We're going to have to agree to disagree then, because I don't see a 
problem with either of those two examples:

# Subref won't be used without & or ->() to dereference:
$ perl -wle '$r = sub { "foo" }; print $r'
CODE(0x8105988)

# Scalar FileHandle won't do the right thing unless it's followed by
# an argument list in which case the indirect object syntax will be clear:
$ perl -MFileHandle -wle '$fh = FileHandle->new; $fh->fdopen(STDOUT,">"); 
$_ = "foo"; print $fh'
FileHandle=GLOB(0x8122a20)
$ perl -MFileHandle -wle '$fh = FileHandle->new; $fh->fdopen(STDOUT,">"); 
$_ = "foo"; print $fh $_'
foo



--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to