Hi,
What i find challenging in perl is the automagic that enables a
little code to do a lot. I was looking at a book Data Munging with
Perl by David Cross. I've used perl in the past but I forget most of
it after a while and then relearn it when I need to use it again...In
any event (I wish I retained knowledge better) the very first script
in the book would be used on a file like, (assume tab delimited)
band1 song1 aaa 1999
band2 song2 bbb 1966
band3 song3 1988
band4 song4 1964
band5 song5 eee 1988
and the given code to get the number of CDs per year is:
my %years;
open FILE, untitled or die $!;
while (FILE) {
chomp;
my $year = (split /\t/)[3];
$years{$year}++;
}
foreach (sort keys %years) {
print In $_, $years{$_} CDs were released.\n;
}
So my $year = (split /\t/)[3]; knows that it's input parameter is a
line from FILE it doesn't have to told. The [3] obviously says give
me the 4th element in the tab delimited line. The $_ var is well
documented. Again the minimal code approach is challenging for me. And
this can probably condensed even more ?!
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/