Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

split and lc or \L in one statement

0 views
Skip to first unread message

Thomas Glanzmann

unread,
Dec 17, 2009, 6:57:56 AM12/17/09
to
Hello,
is it possible to write split and lc() or \L in one statement?

so makeing out of these three lines, one?

my ($snummer, $maschinenname, $prozess) = (split(/;_,?/))[0,1,14];
$snummer = lc($snummer);
$maschinenname = lc($maschinenname);

Thomas

J�rgen Exner

unread,
Dec 17, 2009, 7:22:27 AM12/17/09
to

I'd expect a simple

my ($snummer, $maschinenname, $prozess) =

(split(/;_,?/, lc))[0,1,14];

should work just fine because your RE doesn't discriminate on upper or
lower case.

jue

Peter J. Holzer

unread,
Dec 17, 2009, 1:16:00 PM12/17/09
to
On 2009-12-17 12:22, J�rgen Exner <jurg...@hotmail.com> wrote:

> Thomas Glanzmann <tho...@glanzmann.de> wrote:
>>is it possible to write split and lc() or \L in one statement?
>>
>>so makeing out of these three lines, one?
>>
>>my ($snummer, $maschinenname, $prozess) = (split(/;_,?/))[0,1,14];
>>$snummer = lc($snummer);
>>$maschinenname = lc($maschinenname);
>
> I'd expect a simple
>
> my ($snummer, $maschinenname, $prozess) =
> (split(/;_,?/, lc))[0,1,14];

That converts $prozess to lower case, which the original code doesn't.

I don't see a simple way to convert only $snummer, $maschinenname to
lowercase.

hp

J�rgen Exner

unread,
Dec 17, 2009, 2:20:30 PM12/17/09
to

You are right, my mistake. And because lc doesnt' accept a list as
argument I don't see any easy way, either. I guess you could try
something with map, but I seriously doubt it's worth the effort.

jue

Ben Morrow

unread,
Dec 17, 2009, 3:45:39 PM12/17/09
to

Quoth J�rgen Exner <jurg...@hotmail.com>:

my ($snummer, $maschinenname, $prozess) = split...;
$_ = lc for $snummer, $maschinenname;

is a least simpler than the original. For my taste I would want local
temporaries like that to have shorter names, as well.

Ben

Marc Girod

unread,
Dec 17, 2009, 4:01:41 PM12/17/09
to
On Dec 17, 11:57 am, Thomas Glanzmann <tho...@glanzmann.de> wrote:

> my ($snummer, $maschinenname, $prozess) = (split(/;_,?/))[0,1,14];
> $snummer = lc($snummer);
> $maschinenname = lc($maschinenname);

my ($snummer, $maschinenname, $prozess) =

grep{$_ = $c++<2 ? lc : $_}(split(/;_,?/))[0,1,14];

Marc

Uri Guttman

unread,
Dec 17, 2009, 11:30:47 PM12/17/09
to
>>>>> "MG" == Marc Girod <marc....@gmail.com> writes:

MG> On Dec 17, 11:57�am, Thomas Glanzmann <tho...@glanzmann.de> wrote:
>> my ($snummer, $maschinenname, $prozess) = (split(/;_,?/))[0,1,14];
>> $snummer = lc($snummer);
>> $maschinenname = lc($maschinenname);

MG> my ($snummer, $maschinenname, $prozess) =
MG> grep{$_ = $c++<2 ? lc : $_}(split(/;_,?/))[0,1,14];

that should be map. grep won't return the value if it is false and maybe
the split results has a null string in there.

also $c is undeclared and could be set to something other than 0 by
other code. so this is longer and noisier than it has to be.

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

0 new messages