#!/usr/bin/env perl use strict; use warnings; use autodie qw(open close); use 5.012;
open my $fh, '<', '/etc/passwd'; open my $fh2, '>', '/tmp/newpasswd'; my $uid; my %h; while(<$fh>){ $uid = (split /\:/, $_)[0]; $h{$uid} = $_; } print $fh2 map "$h{$_}", sort keys %h; close($fh); close($fh2); On Thu, Mar 29, 2012 at 8:27 AM, my <bart4...@gmail.com> wrote: > The goal of this assignment is to put in practice the list and I/O > functionalities implemented by Perl. > > > > Write a program that will read a list from a file (input), will sort > the list in lexical order and write back the sorted list to another > file (output). You can use arrays and any of the Perl built-in > functions learned so far to solve this problem. > > > > this it what i have > > #!/bin/perl > > > open ( PWFILE, "/etc/passwd" ) ; > open ( NEWPWFILE , "> /tmp/newpasswd" ) ; > > @lines = <HELLO> ; this is how you sort the line; > > while ( $line = <PWFILE> ) { > print NEWPWFILE "@line" ; > print @lines > } > > close ( PWFILE ) ; > close ( NEWPWFILE ) ; > > need help finish it and need how to with the sort code and finish it > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/