Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Newbie Q - Nicer way to lc something?

Reply
Thread Tools

Newbie Q - Nicer way to lc something?

 
 
Chris Smith
Guest
Posts: n/a
 
      10-01-2003
Hi,

Is there a nicer way of doing the following?

$a = lc($a);

Doesn't look "perlish" if you know what I mean.

Cheers,

--
Chris Smith
http://www.infinitemonkeys.org.uk/
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      10-01-2003
On Wed, 01 Oct 2003 13:41:02 +0100, Chris Smith wrote:
> Is there a nicer way of doing the following?
>
> $a = lc($a);
>
> Doesn't look "perlish" if you know what I mean.


No. I don't know what you mean. What do you mean? Do you find solutions
like this one more "perlish"?

$a =~ tr/A-Z/a-z/;

If so, you shouldn't be using Perl.


--
Tore Aursand <>
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      10-01-2003
Chris Smith wrote:
> Is there a nicer way of doing the following?
>
> $a = lc($a);
>
> Doesn't look "perlish" if you know what I mean.


I don't know that. Looks nice enough to me.

You'd better avoid using $a (as well as $b) outside the sort()
function, though.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      10-01-2003
Tore Aursand wrote:

> On Wed, 01 Oct 2003 13:41:02 +0100, Chris Smith wrote:
>> Is there a nicer way of doing the following?
>>
>> $a = lc($a);
>>
>> Doesn't look "perlish" if you know what I mean.

>
> No. I don't know what you mean. What do you mean? Do you find solutions
> like this one more "perlish"?
>
> $a =~ tr/A-Z/a-z/;
>
> If so, you shouldn't be using Perl.


I'm talking more like:

lc $a;

And return the value in $a rather than $_

$a=lc($a);

is very BASIC-like if you know what I mean.

Perhaps it's just me being fussy :/

--
Chris Smith
http://www.infinitemonkeys.org.uk/
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      10-01-2003
Gunnar Hjalmarsson wrote:

> Chris Smith wrote:
>> Is there a nicer way of doing the following?
>>
>> $a = lc($a);
>>
>> Doesn't look "perlish" if you know what I mean.

>
> I don't know that. Looks nice enough to me.
>
> You'd better avoid using $a (as well as $b) outside the sort()
> function, though.


Have done - the real code is:

$article = lc($article);

Just shortening it for the example.

Thanks for the tip though - didn't know $a and $b were "recommended
avoidables".

--
Chris Smith
http://www.infinitemonkeys.org.uk/
 
Reply With Quote
 
Robert Szczygiel
Guest
Posts: n/a
 
      10-01-2003
Chris Smith wrote:
> $a=lc($a);
> is very BASIC-like if you know what I mean.


Does :

$a=lc$a;

look better? )

RobTM
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      10-01-2003
Robert Szczygiel wrote:

> Chris Smith wrote:
>> $a=lc($a);
>> is very BASIC-like if you know what I mean.

>
> Does :
>
> $a=lc$a;
>
> look better? )


Even worse. I get your point

--
Chris Smith
http://www.infinitemonkeys.org.uk/
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-01-2003
Chris Smith <> wrote:

> Is there a nicer way of doing the following?



Maybe.


> $a = lc($a);



Show us where $a _first_ gets its value.

You can lowercase it there without needing a separate step.

eg:

$a = lc $1;

$a = "\Qother $1 stuff"; # OTHER $1 STUFF

$a = "other \Q$1 stuff"; # other $1 STUFF

$a = "other \Q$1\E stuff"; # other $1 stuff


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      10-01-2003
>>>>> "CS" == Chris Smith <> writes:

CS> lc $a;

CS> And return the value in $a rather than $_

what return value in $_??


in general the only things that implicitly set $_ are loop contructs
(for, while( <FH> ), map, grep). i can't think of any function that will
just set $_ (i could be wrong). many functions use $_ as a default arg
which is not the same as a default return.

CS> $a=lc($a);

CS> is very BASIC-like if you know what I mean.

CS> Perhaps it's just me being fussy :/

yes.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
 
Reply With Quote
 
Tore Aursand
Guest
Posts: n/a
 
      10-01-2003
On Wed, 01 Oct 2003 14:51:05 +0100, Chris Smith wrote:
>>> Is there a nicer way of doing the following?
>>>
>>> $a = lc($a);
>>>
>>> Doesn't look "perlish" if you know what I mean.


>> No. I don't know what you mean. What do you mean? Do you find
>> solutions like this one more "perlish"?
>>
>> $a =~ tr/A-Z/a-z/;
>>
>> If so, you shouldn't be using Perl.


> I'm talking more like:
>
> lc $a;
>
> And return the value in $a rather than $_


Sure, but what happens when you _want_ to check the return value of lc()?

my $str = "Don't mess with this text";
if ( lc( $str ) eq "don't mess with this text" ) {
# I'm not messing
}

> Perhaps it's just me being fussy :/


Yup.


--
Tore Aursand <>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nicer way to remove prefix of a string if it exists News123 Python 3 07-14-2010 01:40 PM
is there an nicer way for this expression? Remco Hh Ruby 17 11-21-2007 05:04 PM
Is there a nicer way to do this? Stefan Arentz Python 12 10-05-2007 04:27 PM
nicer way to convert array of int to array of string S Kanakakorn Ruby 3 02-09-2007 08:28 PM
Nicer way of strip and replace? Markus Rosenstihl Python 6 10-12-2005 09:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57