The responses are great. $Bill showed an example that I didn't even consider which was to simply shift the array *after* the assignment. Whats good though is that I can use all these ideas as needed and where appropriate. I appreciate everyone's feedback.

Joi Ellis wrote:
On Tue, 30 May 2006, listmail wrote:

Untested, off-the-cuff suggestion...

This looks suspiciously like a homework assignment. ;)


#!/usr/local/bin/perl -w
use strict;

my @data = ('NUMBERS: ONE TWO THREE',
            'WORDS: CAT MOUSE DOG');
my (@numlist, @wordlist);

foreach my $line (@data) {
        print "$line\n";
        if ($line =~ /^NUMBERS:/) {

         if ($line =~ /^NUMBERS:\s*(.+)\s*$/) {
            $line = $1;
            @numlist = split(/\s+/, $line);

                #
#Need to shift $line so $line becomes only ONE TWO THREE or the assigment to @numlist will
                #only be ONE TWO THREE
#perhaps something equivalent to shift @{$line}; although shift wants array
                #What are my options ??
                #
                @numlist=split ' ', $line;
        } elsif ($line =~ /^WORDS:/) {

         } elsif ($line =~ /^WORDS:\s*(\s+)\s*/) {
           $line = $1;
           @wordlist = split(/\s+/, $line);

                #similar need to above comments
                @wordlist=split ' ', $line;
        }
}

[EMAIL PROTECTED], @wordlist should not contain first value of NUMBERS: or 
WORDS:
print "\n";
print "$_\n" foreach (@numlist);
print "\n";
print "$_\n" foreach (@wordlist);


_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to