On December 5, 2003 12:53 pm, [EMAIL PROTECTED] wrote:
> Help. I'm a frustrated newbie who wants to use Perl to make my life easier.
>
> The following simple task is only one small part of a program I'm trying to
> put together to automate some things I currently do manually.
>
> I have a file whose format looks like this:
>
> name1 name2 name3
> name4 name5 name6, etc.
>
> The names are separated by spaces. I need the names to be one name per
> line, like this:
>
> name1
> name2
> name3, etc.
Try the following. It should get you on your way.
#!/usr/bin/perl -w
use strict;
my @array;
my $array_element;
open(FH,"<$ARGV[0]");
while(<FH>) {
@array = split;
foreach $array_element (@array) {
print $array_element, "\n";
}
}
To sort the resulting list, I would first save the output and pipe it into
another script.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>