Well, you can but it won't return what you expect.
So I assume you didn't actually do that, post the actual code you tried because if you split those lines using '$' as the argument you will get what you expect.
I never seem to give enough information when I post.. sorry about that.
The test string, if I ever got it to seperat correctly, was going to seperat the dollar amount and assigne it to an array and then have the money value added for a total.
$test="This is a test $6.56 $5.7";
print split(/\$/, $test);
which resulted the
This is a test .56 .7
This was a simple design to see why my split did not work correctly.
With your snipit all came together:
open(FILE, "<", "stamp_list");
my @stampItem;
my @stampPrice;
while(<FILE>) {
chomp;
my ($stampItem, $stampPrice)=split(/\$/);
push @stampItem, $stampItem;
push @stampPrice, $stampPrice;
}
here's another way.. you don't split on $ but split normally on spaces. then go through each element and check for dollar sign. add them to get total
$test="This is a test \$6.56 \$5.7";
@a=split /\s+/,$test;
$total=0;
foreach my $item (@a){
if ( $item =~ /\$/){
$item=~s/\$//;
$total=$total+$item;
}
}
print $total;
Thank you for taking the time explain what now seems such a simple question. These basic exercises do prove challenging for new students to the perl language. But with the help of the great world of the internet even us newbies don't have to feel like idiots when learning the fundamentals. Can�t wait to take the class on Advanced Unix and Shell scripting.
BTW.. I did run your script and it worked as advertised... just did not understand why my script didn't.. Thanks for your help.