Trimming Whitespace

2012-06-06 Thread Matt
Looking at some old code I wrote. my @listing; open(IN, list.txt) or die $!; while () { chomp; next if /^\s*$/; next if /^#/; push(@listing, $_); } close IN; I want to trim any new lines off end of data. chomp does that. I want to skip any lines that begin with # and next if /^#

Re: Trimming Whitespace

2012-06-06 Thread Shawn H Corey
On 12-06-06 10:27 AM, Matt wrote: Looking at some old code I wrote. my @listing; open(IN, list.txt) or die $!; while () { chomp; next if /^\s*$/; # skip lines beginning with whitespace next if /^\s/; next if /^#/; push(@listing, $_); } close IN; I want to trim an

Re: Trimming Whitespace

2012-06-06 Thread Ken Slater
On Wed, Jun 6, 2012 at 10:27 AM, Matt wrote: > Looking at some old code I wrote. > > my @listing; > open(IN, list.txt) or die $!; > while () { >    chomp; >    next if /^\s*$/; >    next if /^#/; >    push(@listing, $_); > } > close IN; > > I want to trim any new lines off end of data.  chomp does

Re: Trimming Whitespace

2012-06-06 Thread Matt
> Shawn has already provided an answer, but I wanted to point out what > your regular expression (/^\s*$/) is doing. That expression is > matching any string that is empty or only contains whitespace. > HTH, Ken Thanks. So what happens when you try to 'push' an empty string to an array? I assume

Re: Trimming Whitespace

2012-06-06 Thread Shawn H Corey
On 12-06-06 11:46 AM, Matt wrote: Thanks. So what happens when you try to 'push' an empty string to an array? I assume nothing goes in the array? No, an empty string is added to the end of the array. However, if you push an empty list, (), onto an array, nothing is added. -- Just my 0.000