CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Pattern Matching to first character

 



joshuamhenrich
New User

Sep 27, 2011, 8:18 AM

Post #1 of 2 (856 views)
Pattern Matching to first character Can't Post

Hey All;

I am trying to input data from a file that had formatted printing.
Sometimes the amount of spaces between items is NOT equal.
I want to write an until loop that will strip the first character (a space) until a number is the first character. I know the until loop, and the stripping of the first character command, but what pattern matching situation should i use for this?

Thank you!


BillKSmith
Veteran

Oct 3, 2011, 1:03 PM

Post #2 of 2 (811 views)
Re: [joshuamhenrich] Pattern Matching to first character [In reply to] Can't Post

Use a regular expression to remove whitespace.


Code
use strict; 
use warnings;
my $tax_rate = .0625;
while (my $cost = <DATA>) {
chomp $cost;
$cost =~ s/^\s*//;
my $tax = $cost * $tax_rate;
my $total_cost = $cost + $tax;
print $cost, ' ', $total_cost, "\n";
}
__END__
1.74
21.56
100000.00
3983.12

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives