Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using lc within declaration 2

Status
Not open for further replies.

1DMF

Programmer
Joined
Jan 18, 2005
Messages
8,795
Location
GB
Hello peeps,

Like usual i'm trying to cut corners and define a whole load of stuff on one line, only I get the following error...
Can't declare lc in "my"
So is there a way to use the following code correctly?
without using 2 lines of code - i know but hey i'm bored and thought I'd ask!
Code:
my ($fn,lc($ext)) = split(/./, $img);

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Can't declare lc in "my"

I think perl thinks that you think that you want to redefine the lowercase function, hence borkage ;-)

--Paul
Code:
my ($fn,$ext);
($fn,lc($ext)) = split(/./, $img);
should work

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
but that's using 2 lines of code so doesn't meet my criteria :-P and there was a typo in the code, forgot to escape the period!
Code:
my($fn,$ext) = split(/[b]\[/b]./, $img);
I know, this was just one of those stupid questions , when i got an error tying to be smart! I ended up going for
Code:
my ($fn,$ext) = split(/\./, $img);
lc($ext);

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Your use of lc there won't do anything. It doesn't affect the variable passed to it, just returns a lowercased version of it, so you have to assign it somewhere:
Code:
$ext = lc $ext;
 
doh - but i'm suprised ishnid, a man of your calibre not able to give me the 1 liner I wanted :-P


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
About as contrived a one-liner I can think of:

Code:
my ( $fn, $ext ) = map /\./ ? substr( $_, 0, -1 ) : lc, split /(?<=\.)/, $img;

Seriously, though. Do it in two lines ;-)
 
I knew you had it in you :-)

and you're right like hell am I using that, talk about making your PERL code difficult to read!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top