Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Noob's question

by Don Coyote (Hermit)
on Sep 27, 2014 at 12:18 UTC ( [id://1102219]=note: print w/replies, xml ) Need Help??


in reply to Noob's question

I agree with ww, it does work as expected, you are concatenating the newline character. trizen suggests a solution to remove that character. However I think the issue here is how to exit the while loop. If you assign and concatenate you attach the exit keystroke onto the variable you are processing. Mixing your control with your data.

There are also modules such as IO::Prompter which can handle a lot of this for you.
#!/usr/bin/perl -wl use strict; my $s; my $chomp = 1; # actually I do want to remove the newline; while(<STDIN>){ chomp if $chomp; unless( /^q$/i ){ # exit from inputting is 'q' or 'Q' $s .= $_; # concatenate print $s; }else{ last } } print $s; exit 0;

nice trick though, hadn't thought of using operators other than simple assignment

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1102219]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found