Results 1 to 2 of 2

Thread: How to match multiline when reading input file line by line

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    Thumbs up How to match multiline when reading input file line by line

    Dear all,

    I am doing QC Tool for XML Document. I need to generate error log with error(including line#,Col#).

    How I am following is,


    Code:
    while($_ =~ m/<\/h>\n

    /msg) { print "Err/line/Col"; }

    If I use undef $/ or $/="" means Can't get Line no/Col no of the Error. This is my actual Problem.

    It's not working. It matches upto <\/h>\n only. Please suggest how to proceed.

    Thanks in Advance.
    vishwa Ram.


  2. #2
    Junior Member
    Join Date
    Oct 2007
    Answers
    5

    Re: How to match multiline when reading input file line by line

    hi,

    the below attached program resolves your following issue.


    Het blijvend beeld der Hollandse Kunst|1
    De Bijbel in Holland's Schilder-cultuur|25

    Some other text
    Output file:

    Some other text

    Het blijvend beeld der Hollandse Kunst1

    Some other text
    ##########################################
    #!/usr/bin/perl
    use strict;
    use IO::File;

    print "\n File operations";

    my $source_file="/home/myprog/oldfile";
    my $destination_file="/home/myprog/newfile";

    my $input = IO::File->new("< $source_file") # open file in read mode
    or die "Couldn't open $source_file for reading: $!\n";
    my $output = IO::File->new("+> $destination_file") # open file for write mode
    or die "Couldn't open $destination_file for reading: $!\n";

    my $line;

    while (defined($line = $input->getline())) {
    chomp($line);

    if ( $line =~ /^/ ) # if $line contain then only execute following block of code
    {
    print $output " \n"; # write tag in output file
    while ($line !~ /<\/tb>/) {

    $line=$input->getline(); # get next line of

    STDOUT->print($line) if ($line =~ /^\w*\|*/);
    if ($line =~ s/\|/<\/ce>/g) { # search string | and replace with <\ce>
    chomp($line);
    print $output "$line \n" #final string present in between ...
    }
    }
    print $output "
    \n"; # write close
    tag in output file
    }
    else
    {
    print $output "$line \n" # write rest of the code as it is.
    }
    }

    $input->close();
    $output->close();
    ##########################
    output:
    oldfile ===>
    HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

    Het blijvend beeld der Hollandse Kunst|1
    De Bijbel in Holland's Schilder-cultuur|25

    TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

    and
    newfile ===>

    HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

    Het blijvend beeld der Hollandse Kunst1
    De Bijbel in Holland's Schilder-cultuur25

    TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

    Last edited by amitbhosale; 02-07-2008 at 08:47 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact