473,383 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

ActivePerl ~s/ / / and ~tr/ / / and lc() not working

Hi,
I am using Activeperl 5.10.

Its replace methods or functions do not seem working.

I need to replace every uppercase letter by its corresponding lowercase.
I used $str=~ s/A-Z/a-z/; $str=lc($str); and $str=~ s/[A-Z]/[a-z]/;

Could you help, please?

thank you

Fernando
Nov 11 '09 #1
6 2864
numberwhun
3,509 Expert Mod 2GB
Instead of using the substitution, you want to use translate. Substitue, the way you are using it, looks for a pattern (on the left) and then replaces it with a replacement (on the right).

You want something like this:

Expand|Select|Wrap|Line Numbers
  1. $str=~ tr/A-Z/a-z/;
  2.  
Also,with the lc() function, I find it better to put the output into a new variable, instead of the one you are reading from. Here is an example:

Expand|Select|Wrap|Line Numbers
  1. my $newstr = lc($str);
  2.  
That should work much better for you.

Regards,

Jeff
Nov 12 '09 #2
Hi Jeff,
Thank you for your answer.

I had tried your tips without success.

Probably my perl interpreter is corrupted.

I will tell you.

best regards

Fernando
Nov 12 '09 #3
numberwhun
3,509 Expert Mod 2GB
Do us a favor and post your code, enclosed in code tags, and we will have a look at it and see if it works.

Regards,

Jeff
Nov 13 '09 #4
Hi,
Thank you for your help.

I am using Windows7 and also tried another computer with Windows XP
getting the same result, an empty string.

Here is the code I used ( 3 options) for testing purposes:
Expand|Select|Wrap|Line Numbers
  1. INICIO: if (defined($_ = <STDIN>)) {$t=$_;if($_==0){exit;}}
  2. print$t."\n";
  3.  
  4. #my $t1=lc($t);
  5.  
  6. #$t1=~ s/A-Z/a-z/g;
  7.  
  8. $t1=~ tr/A-Z/a-z/;
  9.  
  10.  
  11. print $t1;
  12.  
  13. goto INICIO;
  14.  
Thank you again and best regards

Fernando
Nov 13 '09 #5
RonB
589 Expert Mod 512MB
EVERY Perl script you write should load the warnings and strict pragmas. If you had done so, then they would have informed you that $t1 was never defined.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
Don't use the goto. That's a holdover from perl 4 and nowdays is only used in very rare cases, which you will probably never come across. Instead, you should be using a while loop.

Do not put multiple statements on a single line.

You need to chomp $t

This looks like a homework assignment, so I won't provide the complete solution, but the clues I gave should help to solve the problem.
Nov 13 '09 #6
Hi,
Thank you.
Your remarks helped me to find a serious error:

Using '==' instead of 'eq' stoped the script too earlier.

Thank you again,

Best regards

Fernando
Nov 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bryan | last post by:
i thought that LC and genexp were supposed to be faster than map. i also thought i read somewhere in this group that the slowest looping mechanism in 2.4 is 20% faster than the fastest looping...
32
by: Xah Lee | last post by:
is it possible to write python code without any indentation? Xah xah@xahlee.org http://xahlee.org/PageTwo_dir/more.html
0
by: WS | last post by:
Hello, I am trying to tidy up my ActivePerl installation by refreshing the packages. Everything works fine except for perl-ldap. Whenever I check for a new version (upgrade --install) a new one...
3
by: Skybuck Flying | last post by:
Hi, I download some perl source code and the manual says: perl Makefile.PL make make install The first line went ok.
2
by: bbxrider | last post by:
i'm new at this so, please bear with me win2k adv serv, iis5.0, front page extensions installed, activeperl installed can asp and activeperl coexist on the same iis server? the install for the...
1
by: kenneth kahn | last post by:
I've installed ActivePerl on my AIX 5.1 system using the following install file ActivePerl-5.8.7.813-aix-5.1-cc-151115.tar.gz By install, all I did was to gunzip/tar the file. Everything seems...
0
by: Aaron Heusser | last post by:
I have observed a problem with .NET 2.0 where lc.exe throws an OutOfMemoryException when I run it under a VS2005 .NET Command Prompt. If I take the exact same lc.exe statement and run it under a...
0
by: OverTheTop | last post by:
All the usual Newbie stuff applies... I have a Windows2000 Server with ActivePerl and a module (DBD-Interbase) that worked fine. Trying to duplicate the environment on Windows2003 Server for...
2
by: sbettadpur | last post by:
Hello Team I am trying to install Bugzilla on Windows 2003 Bugzilla version: bugzilla-3.0.5 and ActivePerl Version : v5.8.8.864 The problem is When I tryied...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.