top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to take multiple lines of input in PERL?

+1 vote
402 views
How to take multiple lines of input in PERL?
posted Jul 13, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You can use perl's $/ variable to define an record separator. The default is "\n", but you can change it, say you want to change it to "#" in a line.

Sample Code

$/ = "\n#\n";

while (<STDIN>) {
    chomp;
    print "You entered: $_\n";
}
answer Jul 13, 2015 by Salil Agrawal
Similar Questions
+1 vote

I'm looking for some good documentation on how to handle multiple TCP connections at the same time. Already have the book Network Programming with Perl (Lincoln D. Stein)

Having a client / server based script that works with a single stream of network data in a single session e.g. a mail server that spawns a new process for every session, I get how that works.

But when I want to do multiple read/write sessions over different sockets I get totally lost.. Looked into IO::select and stuff but I'm just missing some good simple clean examples.

Example.. Client connects to server.. Server keeps sending messages that are passed to the client. Client connects to 2nd source.. And needs to read/write to both the server and to the 2nd source..

+2 votes

I have this simple script to automatically print HTML selection option.

#!/usr/bin/env perl
use strict;
for (reverse(1943 .. 1991)){
  print "$_n";}

I need to print all the years between 18 and 73 without hard coding the range in the for loop as in the above. I am considering the use of localtime to compute the current year as below $yr=(localtime), but I cant think of an easy way to achieved what I want to do.

+1 vote

I'm looking for introductory to advanced examples of RESTful programming in Perl preferably with some good explanations and best practices.

...