in reply to Re^3: how to split based on new line or others ?
in thread how to split based on new line or others ?

Yes... you are right.. Do you have any ideas how to solved it ?
  • Comment on Re^4: how to split based on new line or others ?

Replies are listed 'Best First'.
Re^5: how to split based on new line or others ?
by prasadbabu (Prior) on Nov 08, 2006 at 09:44 UTC

    bh_perl, You have not shown your exact requirement. So by assuming your required output as:

    <name>00 00 0D</name> <mobile>123455</mobile> <name>00 00 30</name> <mobile>6575758</mobile>

    Here is one way to achieve this.

    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 "<name>$fldname</name>\n<mobile>$fldvalues</mobi +le>\n\n"; } } main { if ($opt{h}) { usage(); } open(DATA, "$opt{i}"); my $data = do {local $/, <DATA>}; + while ($data =~ /name\:([^\n]*)\nmobile\:([^\n]*)\n?/g) { my $fldname = $1; $fldvalue = $2; $fldinfo{$fldname} = $fldvalue; } close(DATA); chk_info(); exit(); }

    Prasad