in reply to Problem with reading multi-line

I put this script together using the solutions given to you by BrowserUk, jwkrahn, and some ideas that I got from searching the monastery. Search can be a powerful tool...
#!/usr/bin/perl use strict; use warnings; print "Enter the number of times : "; my $times= <STDIN>; my $prompt = q{Add values : }; my $maskPrompt = "\r" . ' ' x (length($prompt) + 2) . "\r"; my (@input) = (); print $prompt; chomp @input; print do { local $" = "\n -->"; " -->@input" }, "\n"; my $ascii; foreach $times(1 .. $times) { $ascii .= chr (<STDIN>); } print $ascii, "\n";
Update: Condensed script. It should be:
#!/usr/bin/perl use strict; use warnings; print "Enter the number of times : "; my $times= <STDIN>; my $prompt = "Add values : "; $prompt = "\r" . ' ' x (length($prompt) +2) . "\r"; print $prompt; my $ascii; foreach (1 .. $times) { $ascii .= chr (<STDIN>); } print $ascii, "\n";

Replies are listed 'Best First'.
Re^2: Problem with reading multi-line
by jwkrahn (Abbot) on May 03, 2010 at 02:16 UTC
    my $maskPrompt = "\r" . ' ' x (length($prompt) + 2) . "\r";

    Why do you create this variable if you never use it?

    my (@input) = (); print $prompt; chomp @input;

    Why do you assign nothing to an already empty variable?    And why then do you chomp an empty variable?

    foreach $times(1 .. $times) { $ascii .= chr (<STDIN>); }

    Why are you using the same variable name for the loop creation and for the local variable?    I have been using Perl for many many years and I have never seen anyone do this before and it is very confusing.    It only works because the value stored in $times is local to the loop body but it is not something that you should do because it is very confusing.

      I completely agree with you(jwkrahn) using the same variable name for the loop creation and even i never see such questions in my life. Believe me, all 10 questions which i was attempting to get Perl Certification from Expert Ratings has the same form of reading the input. I attempted test two times but failed.

      http://www.expertrating.com/certifications/PERL-Programming-Skills-Test.asp

      During this test, i tried to represent the code test several ways but nothing works.

      Thanks.

        From the URL mentioned above:

        PERL Programming Skills Test
        (Hands-on programming skills)
        (Leading to ExpertRating PERL Skills Certification)

        You are one of the lucky 500 people who have been given an opportunity to take this PERL Programming Test and attain the coveted ExpertRating Perl Skills Certification.

        There are at least a handful of red flags between the URL, page title, and first paragraph alone.

        i was attempting to get Perl Certification from Expert Ratings has the same form of reading the input. I attempted test two times but failed.

        There are several threads around here that discuss the merits (or lack thereof) of certification programs like these. Before dropping another $25 to take this test, I'd encourage you to read a couple of them. From one Monk to another, I suspect the time you'd spend taking the "PERL Programming Skills Test" (again) would be better spent reading a few selected perldocs and/or Tutorials. Worry not about shiney things; meditate upon the fundamentals and Perl will open itself to you. True masters of the language do not need a $25 piece of paper from some online company to prove their knowledge.

        Best of luck.