Hi John, On Mon, 14 Jul 2014 04:15:39 +0100 John Delacour <johndelac...@gmail.com> wrote:
> > 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; Also add "use warnings;". > my $filepath = "$ENV{HOME}/temp/a.txt"; > open my $fh, "<$filepath" or die $!; don't use two-args open > while (<$fh>) { It is better to use an explicit variable intead of $_; > chomp; > @_ = split / /; Don't use @_ for that - use a lexical array. > print $_[-1] . $/; > } > > Regards, Shlomi Fish > # JD > > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Freecell Solver - http://fc-solve.shlomifish.org/ <rindolf> RESOLVED / WONT_FIX / FUCK_YOU … story of my life. — http://www.shlomifish.org/humour/fortunes/sharp-perl.html Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/