http://www.perlmonks.org?node_id=963950

Ekimino has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to parse an RTF file as plain text, I have succeded in separating things, but I've been going around in circles with the output, which doesn't seem to work the way I want to. I think the abnormal behaviour comes from the RTF file. The output should go like this: $user:$hash . But it will only output $hash\n unless I separate them with a \t. Here goes the code:

#!/usr/bin/perl use strict; use warnings; chomp(my @file = <>); my @users; my @hashes; #sub listar{ # while(@file){ # if($_ =~ /Data Found/g){ # $_ =~ s/\\par//g; # $_ =~ s/Data Found: //g; # printf "$_\n"; # } # } #} # Separate Users and add each one @users. foreach(@file){ chomp $_; if($_ =~ /User=/g){ $_ =~ s/Data Found: //g; $_ =~ s/\\par//g; $_ =~ s/User=//g; unless($_ =~ /magela/){ push(@users, $_); } } } # Separate Hashes and add each one to array @hashes foreach(@file){ chomp $_; if($_ =~ /Pass=/g){ $_ =~ s/Data Found: //g; $_ =~ s/\\par//g; $_ =~ s/Pass=//g; push(@hashes, $_); } } pop @users; my $n = @users; printf "Numero de Usuarios: $n\n"; my $h = @hashes; printf "Numero de Hashes: $h\n"; my $f = 0; while($f < $n){ <b>printf "$users[$f]\t$hashes[$f]\n"</b>; $f += 1; }

Output with \t:

marianonc624d56fbf18eb79236e942c1478bc4e fermins 8e6c5623ad9a544731661e3f872bb5f2 monicar 1cf5bd31c0bf0cb33eae5d75adfc2094

Output without \t

:5c0b18186c48d9e29f773cca0939b9c1 :c624d56fbf18eb79236e942c1478bc4e :8e6c5623ad9a544731661e3f872bb5f2 :1cf5bd31c0bf0cb33eae5d75adfc2094

How I want it

username:hash

Before suspicious minds come along, Yes, this are passwords hashes from a VM inside my lab. How should I handle RTF without using a module? Thank you.