[Chicago-talk] A CLUE @ARGV while(<>)

Ted Zlatanov tzz at lifelogs.com
Tue Jan 8 15:57:38 PST 2008


On Tue, 8 Jan 2008 06:55:49 -0800 (PST) Richard Reina <richard at rushlogistics.com> wrote: 

RR> Progress, maybe.  I believe this script is hanging at the line push(@lines, $_) unless (/espf\[/); 
RR> I believe this because in cases when it hangs, if I do a Cntl-C I get:

RR> Not a subroutine reference at ./file_delimiter.pl line 24, <> line3.

RR> This is turning out to be a disruptive problem here.  Any help would be greatly appreciated.

RR> #!/usr/bin/perl5 -w 

RR> use warnings;
RR> use strict;

RR> sub delimit {

RR> my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_;

RR> if (defined $in_file) { # file submited 

RR> @ARGV = $in_file;

RR> $body = "";  

RR> while(<>) {

RR> push(@lines, $_) unless (/espf\[/);  # hangs here sometimes

RR> } # end of while

RR> } # end of if    

RR> } # end of sub

It's unlikely this is your script, since line 24 is at the end and
@lines is not declared, which wouldn't work under `use strict'.  Can you
please post your actual code that hangs?  Also try some debugging output
(or the Perl debugger with a watch).

FWIW, I'd write delimit() like this (untested):

sub delimit {
 my ($tos, $ccs, $rp, $sb, $body, $in_file) = @_;

 return unless defined $in_file;
 open IN, '<', $in_file or warn "Could not open $in_file: $!";
 my @lines;

 while (my $line = <IN>)
 {
  next if $line =~ m/espf\[/;
  push(@lines, $line);
 } 
}

Note how the open() will tell you if it couldn't open the input file,
which could be one of your problems.  Anyhow, don't post broken code, no
one can help you fix it.

Ted


More information about the Chicago-talk mailing list