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);
--
Joi Ellis
[EMAIL PROTECTED]
No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried. Anything
that kicks a monopoly in the pants has got to be good for something.
- Chris Johnson
_______________________________________________
Perl-Unix-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs