Home  |  Linux  | Mysql  | PHP  | XML
From:FrankCai Date:Thu Feb  4 17:29:41 2010
Subject:Re: 1-line text file with numbers, need to add to them
For instance, here is your data file. data.txt

12~s1~s314~s5677~s899~s0~s

Then, here is the code.
#!/usr/bin/perl
open(DATA,"data.txt");
while(<DATA>) {
$number=$_;
# print $number;
while ($number =~ /([0-9]+)~s/g){
printf ("%d\n","$1");
}
}
close(DATA);




> I need some help with this problem.
> I've got a text file datafile with 1 line of data comprised of 30
> different numbers delimited with ~s.
>
> I need to open this file, grab this line of data, split it into
> individual numbers, perform some simple math (addition) on each
> number, and then put the new values back into the datafile, replacing
> the original data that was there.
>
> I have tried for two days to figure out what I'm doing wrong, but I
> keep getting "needs a package name" errors for every variable
> nomenclature I try to work with. I've declare arrays and variables
> until my fingers are numb and nothing is working. I'm using Perl 5.008
> if that matters.
>
> Can somebody please help?

Navigate in group perl.beginners at sever nntp.perl.org
Previous Next


Your recent visits
Re: 1-line datafile, need data for another routine
LMPX.COM :: Linux, Mysql, Php, Xml
no lstat happens
New on http://perl-begin.org/ - more topical pages and pages for Perl uses
Re: running stats on a file



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants