[Solved] use perl to print text in given commend [closed]


It appears as though you want to simply eliminate duplicate users. Here’s one way. The only difference is that the output is not sorted in the same order it came in from the file.

It uses an external module, Getopt::Long to handle the arguments, then uses a hash to eliminate duplicates:

Code:

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

my $action;

GetOptions("a=s" => \$action,);

if ($action eq 'printing_usage_file'){
    print_usage_file();
}

sub print_usage_file {

    open my $file, '<', 'input.txt'
      or die "Can't open the file!: $!";

    my %user_hash;

    while (my $line = <$file>){
        chomp $line;
        $user_hash{$line} = 1;
    }

    print "\nPrinting users:\n\n";

    for my $user (keys %user_hash){
        print "$user\n";
    }
}

Output:

$ ./printing_summary.pl -a printing_usage_file

Printing users:

john.smith
MarcoRibeiro
lial_chen14

2

solved use perl to print text in given commend [closed]