in reply to Re: how to split based on new line or others ?
in thread how to split based on new line or others ?
Ok... This is my code:-
#!/usr/bin/perl use Getopt::Std; use vars qw /%opt/; my %fldinfo; my $options = 'h:i:o:'; getopts("$options", \%opt) or usage(); sub usage { print "Usage: $0 -[h] -i <input_file>\n"; if ($opt{h}) { print " -h : help\n"; print " -i : input value to be created\n"; print " -o : output-file\n"; } } sub chk_info { while (my ($fldname, $fldvalues) = each (%fldinfo)) { print "<$fldname>$fldvalues</$fldname>\n"; } } main { if ($opt{h}) { usage(); } open(DATA, "$opt{i}"); while (my $data = <DATA>) { next if $data =~ /^#/; foreach (split(/\n/,$data)) { my ($fldname, $fldvalue) = (split(/:/,$_))[0,1 +]; $fldinfo{$fldname} = $fldvalue; } } close(DATA); chk_info(); exit(); }
I have tried to open and split the input data based on the new line. But the program did not captured or print out all the input data of th +e input file. It only print out the last record of the files. As example:- name:00 00 30 mobile:6575758
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to split based on new line or others ?
by prasadbabu (Prior) on Nov 08, 2006 at 07:29 UTC | |
by bh_perl (Monk) on Nov 08, 2006 at 07:41 UTC | |
by prasadbabu (Prior) on Nov 08, 2006 at 09:44 UTC | |
|
Re^3: how to split based on new line or others ?
by swampyankee (Parson) on Nov 08, 2006 at 17:42 UTC |