in reply to How to find empty in empty

Hi, some remarks:
- use "use strict"
- initialize your data before using it ($l is not initialized)
- you don't need rows, row1, row2 as temporary variables

The following script checks for an empty line with the
mighty regexp /^[\s]+$/ instead of
comparing with "".

#!/usr/local/bin/perl -w use strict; my (@names, @versions,$l,$e); $l=0; $e=0; while (<DATA>) { chomp; if (! /^[\s]+$/) { ($names[$l],$versions[$l])=split(/[\s]+/); $l++; } else { $e++; } } $,=", "; print "@names @versions\n"; print "empty lines=$e\n"; __DATA__ jan 2.76 feb 3.20 mar 1.6 apr 4.00

Replies are listed 'Best First'.
Re: Re: How to find empty in empty
by petral (Curate) on Nov 19, 2002 at 15:44 UTC
    Um, '+' means at least one (and you don't need the box): ! /^\s*$/ Anyway, it's even easier just to check for a non-space: /\S/ But, as long as we're at it, why not accept only well-formed lines:
    if ( /^(\w+)\s+([\d.]+)/ ) { ($names[$l],$versions[$l])=($1,$2); ++$l; else { . . .

      p