On Apr 8, Bryan R Harris said:

>$file = "somefile.dat";
>open (FILE, $file)  || die("Couldn't open $file: $!\n");
>@_ = <FILE>;
>close(FILE);
>while ($_[1] =~ /^[#\n]/) { push(@comments, shift(@_)); }
>print "@comments";

This is a rather bizarre way to do this task, by the way.  It also fails
in some cases -- if the FIRST line of the file starts with a # or is
blank, it gets pushed to @comments, even though you're trying to prevent
that.

Here's how I would write the code:

  open FILE, "< $file" or die "can't read $file: $!";
  while (<FILE>) {
    print unless /^[#\n]/;
  }
  close FILE;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to