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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

some questions about manipulating a $

Status
Not open for further replies.

rtb1

IS-IT--Management
Jul 17, 2000
73
ES
I have some questions about manipulating the contents of a $:

- I’m trying to standardize the look of a nummeric variable field.

The input can be for example:

1000000
1.000.000
1,000,000

they all should finally look like:

1.000.000

I can only think of getting the length of the string and use substring to clear potential dots etc. then reverse the string and insert dots after every 3 digits and reverse it again but probably this is much easier done in Perl?

- What is the quickest way to clear all characters except the digits from a string?

- Let’s say you have a datafile with a nummer of fields seperated by “:”. You don’t want to store a new record to this file with a variable with “:” in it as it will mess up the record when reading it from the datafile. What is the fastest way to check all fields for “:” and replace it with for example “;” before saving it?

Raoul
[sig][/sig]
 
' sounds to me like you need a little regex replacement stuff......

Code:
$str = '10,000,000';
$str =~ s/\D//g; # replace all non-digits with null


Second item,
Code:
$str = 'some text with : colons embedded : ';
$str =~ s/:/\;/g; # replace all ':'s with ';'s.  
              # Must escape ';' to keep Perl from 
              # ending statement on ';'.


'hope this helps. [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
Hai!

I hope this too help you .

$number=1000000;
$number= reverse($number);
$number=~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
$number=reverse($number);
print $number;


:)
[sig][/sig]
 
Thanks both. Works great!

Does anybody knows a good site for more info about this sort of stuff. I checked some documentation but what I found was totally not useful.

I would like to get more info about this for doing a search through a data file with fields that match a certain number of characters and that sort of stuff.

Raoul [sig][/sig]
 
At via their search, choosing 'regular expressions' from the pull down, you get this list of resources.....


The last link on that page, 'Regular Expressions', is a pdf of a chapter from a book that does a pretty good job.

Additionally, if you have some specific regex problem, feel free to post it. I'm sure some one will find one of the 'more than one ways to do it'.

'hope this helps. [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top