On 13 Jul 2014, at 23:48, ESChamp <esch...@gmail.com> wrote:

> John Delacour has written on 7/13/2014 5:31 PM:
>> 
>> On 13 Jul 2014, at 21:43, ESChamp <esch...@gmail.com> wrote:
>> 
>>> ...lastname firstname other other other ... emailaddress
>>> 
>>> I wish to write a new file that contains only the emailaddress field
>>> contents.
>> 
>> Here’s an easily-understood way of doing it:
>> 
>> #!/usr/bin/perl
>> use strict;
>> while (<DATA>){
>>  chomp;
>>  @_ = split / /;
>>  print $_[-1] . $/;
>> }
>> __DATA__
>> x x x a@b
>> x x x x c@d
>> x x e@f
> 
> That's great! How do I get it to read the data from a file?

Like this:

#!/usr/bin/perl
use strict;
my $filepath = "$ENV{HOME}/temp/a.txt";
open my $fh, "<$filepath" or die $!; 
while (<$fh>) {
 chomp;
 @_ = split / /;
 print $_[-1] . $/;
}


# JD


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to