B
B
bergentroll2016-09-03 08:52:01
Perl
bergentroll, 2016-09-03 08:52:01

How to get a password from a file?

I use cmus player and libre.fm service. For scrobbling, I use the post-fm script . I also store my configs, including this script, in a public repository, so I would like to put my password in a separate file. I have tried the following construct:

open my $pass_file, 'password.lst';
my $pass = <$pass_file>;
close $pass_file;

# Globals. {{{
our %rc = (
        ...
  password => $pass,
        ...
);

For some reason this doesn't work, even though print "$rc{password}" returns the correct (seemingly) password to the terminal.
CHADNT?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bergentroll, 2016-09-03
@bergentroll

In general, the problem was in the relative path of the file.

T
targumon, 2016-09-03
@targumon

It is possible that line breaks are slipped into the password:

sub trim($) {
    my $t = shift;

    $t =~ s{^\s+}{}g;
    $t =~ s{\s+$}{}g;

    return $t;
}

$pass = trim $pass;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question