[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [Fun With Perl] Does this count as a one-liner?




> For compactness, I believe it could be written as:
> 
>     $query = (unindent ($quantity < 1) ? <<""
>         DELETE FROM Contents
>         WHERE cartnum = '$cartnum'
>           AND itemid = '$itemid';
> 
>     : <<"");
>         UPDATE Contents
>         SET quantity = $quantity
>         WHERE cartnum = '$cartnum'
>           AND itemid = '$itemid';
> 
> Of course that is a bit more dangerous since the dangling ); visually
> closed the line. 

I agree.  I would suggest:

     $query = (unindent ($quantity < 1) ? <<""  : <<"");

         DELETE FROM Contents
         WHERE cartnum = '$cartnum'
           AND itemid = '$itemid';
 
         UPDATE Contents
         SET quantity = $quantity
         WHERE cartnum = '$cartnum'
           AND itemid = '$itemid';
 


It's funny how people always forget that the <<TAG doesn't have to be
the last thing on the line.  They always write

	print (...., <<EOM
	..
	..
	..
	EOM
	);

When they should have written

	print (...., <<EOM);
	..
	..
	..
	EOM



> I suppose I could eliminate cut-and-pasted redundancy with the
> more-entertaining:
> 
>     $query = (unindent ($quantity < 1)
>     ? <<''
>         DELETE FROM Contents
> 
>     : <<""
>         UPDATE Contents
>         SET quantity = $quantity
> 
>     . <<""
>         WHERE cartnum = '$cartnum'
>           AND itemid = '$itemid';
> 
>     );

Try this:

     $query = (unindent ($quantity < 1) ? <<'' : <<"") . <<"";

         DELETE FROM Contents
 
         UPDATE Contents
         SET quantity = $quantity
 
         WHERE cartnum = '$cartnum'
           AND itemid = '$itemid';
 

> Also, do I really save any CPU time with the <<'' rather than <<"" in
> the first part of this last example?

I humbly suggest that if you're really worried about that, you're
programming in the wrong language.


==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org