Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > problem when using <STDIN>

Reply
Thread Tools

problem when using <STDIN>

 
 
Paul
Guest
Posts: n/a
 
      07-13-2005
hi, there,

I met a wired problem when using <STDIN>, here is my script,

use Mail:OP3Client;
use strict;
use warnings;

my $pop;
my $username;
my $password;
my $hostname;
my $SSLFag;

print "Input your username:\n";
$username=<STDIN>;
print "Input your password:\n";
$password=<STDIN>;
print "Input your hostn:\n";
$hostname=<STDIN>;
print "Input your username:\n";
$username=<STDIN>;
print "Using SSL? 1 or 0:\n";
$SSLFlag=<STDIN>;

$pop = Mail:OP3Client->new(USER => $usernane',
PASSWORD => $password,
HOST => $hostname,
USESSL => $SSLFlag);

#$pop = Mail:OP3Client->new(USER => 'myname',
# PASSWORD => 'password',
# HOST => 'mail host name',
# USESSL => 1);
if(!$pop)
{
print "Canot log in the pop3 server\n";
die ;
}

The problem is that if I use <STDIN> to get all four parameters and
pass them to the new function, this script will not work and no error
report. If I direct use the parameters like in the commented scripts,
it works very well.

Can you guys answer me?

Paul

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-13-2005
Paul wrote:
> I met a wired problem when using <STDIN>, here is my script,


<snip>

> my $pop;
> my $username;
> my $password;
> my $hostname;
> my $SSLFag;


You don't need that section with variable declarations, but you'd better
declare respective variable the first time it's used.

> print "Input your username:\n";
> $username=<STDIN>;


my $username = <STDIN>;
chomp $username;

or written directly:

chomp( my $username = <STDIN> );

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Stephane Zuckerman
Guest
Posts: n/a
 
      07-13-2005
> use Mail:OP3Client;
> use strict;
> use warnings;
>
> my $pop;
> my $username;
> my $password;
> my $hostname;
> my $SSLFag;
>
> print "Input your username:\n";
> $username=<STDIN>;

I'd say that your script doesn't like the final '\n' when you ask for
input (I may be wrong, however). Try using chomp :

chomp($username = <STDIN>);
# ... and so on with the other variables.
> print "Input your password:\n";
> $password=<STDIN>;
> print "Input your hostn:\n";
> $hostname=<STDIN>;
> print "Input your username:\n";
> $username=<STDIN>;
> print "Using SSL? 1 or 0:\n";
> $SSLFlag=<STDIN>;
>


--
"Je deteste les ordinateurs : ils font toujours ce que je dis, jamais ce
que je veux !"
"The obvious mathematical breakthrough would be development of an easy
way to factor large prime numbers." (Bill Gates, The Road Ahead)
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-13-2005
"Paul" <(E-Mail Removed)> wrote in news:1121267080.661220.294660
@g43g2000cwa.googlegroups.com:

> print "Input your username:\n";
> $username=<STDIN>;


As Gunnar pointed out, you need to chomp the input obtained, because it
contains the platform specific end of line character sequence by the
time it is stored in $username.

Also, do declare variables in the smallest applicable scope.

> print "Input your password:\n";
> $password=<STDIN>;


I have been using:

use Term::ReadKey;

sub prompt_password {
print 'Password: ';
ReadMode 2;
my $pass = ReadLine 0;
ReadMode 0;
chomp $pass;
return $pass;
}

for the purpose of asking for passwords. With a straightforward read
from STDIN, I found that the password was being stored in the history
buffer of cmd.exe (probably applies to other shells, too.)

> The problem is that if I use <STDIN> to get all four parameters and
> pass them to the new function, this script will not work and no error
> report.


Well, you can diagnose issues like this by taking a look at the variable
to see what it contains:

print "$username:\n";

If you did that, you would see:

sinan
:

indicating that $username has a newline at the end.

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      07-13-2005
You need to call "chomp" to get rid of the newline at the end of each
user response.

You can do it in 1 command, as in:
chomp($username=<STDIN>);

or in 2 commands:
$username=<STDIN>;
chomp $username;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using problem reporting Kue2 Windows 64bit 3 01-15-2010 08:07 PM
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM
Problem connecting to https using ZSI (openssl problem) - python2.3 Adil Hasan Python 3 01-29-2004 12:27 AM
Using GetOleDbSchemaTable to get SQL Server Field Description - using pete ASP .Net 1 08-29-2003 10:50 AM
Re: MVP? Index error on nested element using System.xml but NOT using msxml??? William F. Robertson, Jr. ASP .Net 1 06-25-2003 08:08 PM



Advertisments