Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: looping with conditions and print newline

by betterworld (Curate)
on Jan 12, 2016 at 14:24 UTC ( #1152564=note: print w/replies, xml ) Need Help??


in reply to looping with conditions and print newline

You didn't show us the parser code that produces $line[0]. The best place for this would be in the parser.

However, here is a quick fix to preprocess the text file while reading it. (I am assuming you read it line by line):

while (my $line = <$fh>) { if ($line =~ tr/"//) { # This block will be executed if there is exactly one double-quote + in the line while (1) { my $nextline = <$fh>; die unless defined $nextline; $nextline =~ s/^\s+/ /; # remove indent $line .= $nextline; # join lines break if ($nextline =~ tr/"//) % 2 == 1; } } # now parse the $line just like you would normally do using the code + that you did not show us ;-) parse_line(); }

Replies are listed 'Best First'.
Re^2: looping with conditions and print newline
by analys (Initiate) on Jan 12, 2016 at 14:41 UTC
    hi betterworld, thanks for the reply. I read the file as the following (read line by line). I didn't parse when I read it, but I check if the line match with pattern and put it in scalar.
    open (INPUT, "<", $file) || die "File read error"; @line=<INPUT>; close INPUT;
    and do while loop as per above code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1152564]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-11-29 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?