Re: Capture nth element of a file

2011-01-21 Thread jet speed
On Fri, Jan 21, 2011 at 5:35 PM, jet speed wrote: > > > On Fri, Jan 21, 2011 at 5:18 PM, Jim Gibson wrote: > >> On 1/21/11 Fri Jan 21, 2011 8:43 AM, "jet speed" >> scribbled: >> >> > Hi All, >> > I need some help with the blow. >> > >> > I have a an input file with the below data >> > >> > 18

Re: Capture nth element of a file

2011-01-21 Thread Jim Gibson
On 1/21/11 Fri Jan 21, 2011 8:43 AM, "jet speed" scribbled: > Hi All, > I need some help with the blow. > > I have a an input file with the below data > > 1835 > 1836 > 1837 > 1838 > 1839 > 183A > 183B > 183C > 183D > > > #!/usr/bin/perl > use strict; > use warnings; > > my $filename; > $f

Re: Capture nth element of a file

2011-01-21 Thread Rob Coops
On Fri, Jan 21, 2011 at 5:57 PM, Rob Coops wrote: > > > On Fri, Jan 21, 2011 at 5:43 PM, jet speed wrote: > >> Hi All, >> I need some help with the blow. >> >> I have a an input file with the below data >> >> 1835 >> 1836 >> 1837 >> 1838 >> 1839 >> 183A >> 183B >> 183C >> 183D >> >> >> #!/usr/bin

Re: Capture nth element of a file

2011-01-21 Thread Rob Coops
On Fri, Jan 21, 2011 at 5:43 PM, jet speed wrote: > Hi All, > I need some help with the blow. > > I have a an input file with the below data > > 1835 > 1836 > 1837 > 1838 > 1839 > 183A > 183B > 183C > 183D > > > #!/usr/bin/perl > use strict; > use warnings; > > my $filename; > $filename = "input.

Re: Capture nth element of a file

2011-01-21 Thread jbiskofski
sorry! $line_count at the end of the while block should be $line_count++ On Fri, Jan 21, 2011 at 10:54 AM, jbiskofski wrote: > my $line_count = 1; > my @captured_elements; > > open(FILE, $filename) || die 'cant open file'; > while () { > chomp; > push(@captured_elements, $_) unless ($li

Re: Capture nth element of a file

2011-01-21 Thread jbiskofski
my $line_count = 1; my @captured_elements; open(FILE, $filename) || die 'cant open file'; while () { chomp; push(@captured_elements, $_) unless ($line_count % 4); $line_count; } close(FILE); --- % is the modulus operator, it returns the remainder of a division so ... 6 % 4 = 2, 7

Capture nth element of a file

2011-01-21 Thread jet speed
Hi All, I need some help with the blow. I have a an input file with the below data 1835 1836 1837 1838 1839 183A 183B 183C 183D #!/usr/bin/perl use strict; use warnings; my $filename; $filename = "input.txt" ; open (FILE, "< $filename" ) or die "Could not open $filename: $!"; while () { chomp