in reply to Re: Re: Getting info with a small flatfile db.
in thread Getting info with a small flatfile db.

There are a bunch of different ways: count the number of pipes in the line, and add one. You can use tr/|// for this (returns the number of |s).

Second way store the results from split in an array:

my @parts = split /\|/, $line;

Perl will grab all the bits there are to grab. As chromatic mentioned, you can evaluate that array in scalar context to find out how many parts there are. You can also use a list assignment to nab, say, only the first five:

my ($first, $second, $third, $fourth, $fifth, undef) = split /\|/, $st +ring,6;

HTH

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'