in reply to Need help to make correction in a perl script
Notice how easier it is to read when you indent if and while statements? No wonder you missed the final }.#!/usr/bin/perl use strict; use warnings; my $found_f = 0; my ($lastline, $line); open (INPUTFILE, "test.txt") or die "Unable to open test.txt: $!"; # 'or die' Added while (<INPUTFILE>) { chomp; if (/^[A-Z]{2}:\s/) { $lastline = $line; $line = $_; $found_f = 1; } elsif ($found_f) { s/^ {4}/ /; $line .= $_; } elsif (/^$/) { $lastline = ' '; $found_f =0; } } # Added $lastline .= $line; # Added - this was your main problem print "$lastline\n"; close (INPUTFILE); # Added
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need help to make correction in a perl script
by srsahu75 (Initiate) on Mar 20, 2009 at 11:13 UTC |