LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2012, 11:05 PM   #1
Venkadesh
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
Print output in a single line in perl script


I need to create a single line of output from multiple and variable lines of input in a Linux bash perl script.

My Program is :

#!/usr/local/bin/perl

printf(" Enter the Multiplied Number : " );
$get = <STDIN>;
printf(" Enter the Limitation : " );
$get1 = <STDIN>;
printf("\n");
for ( $i=1; $i <= $get1; $i++)
{
$Ans = $i * $get;
print ( $i, " * ", $get, " = ", $Ans, "\n" );
}

Actual Output is : 1 * 5 = 5
But i got o/p is : 1 * 5
= 5

So Please Guide me how to print the output in a single line

Thanks in Advance
 
Old 01-27-2012, 11:39 PM   #2
eeekster
Member
 
Registered: Oct 2011
Posts: 163

Rep: Reputation: Disabled
Quote:
Originally Posted by Venkadesh View Post
I need to create a single line of output from multiple and variable lines of input in a Linux bash perl script.
Is it bash or is it perl?

Quote:
So Please Guide me how to print the output in a single line
Are you wanting us to do your homework?
 
Old 01-28-2012, 05:38 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Use chomp function on $get and $get1
 
Old 01-28-2012, 08:34 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Also, when posting code here, please put it between [code] and [/code] to aid readability and preserve formatting.
 
Old 01-28-2012, 12:52 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
As already mentioned, please read the chomp documentation.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Print output of a script to screen using Perl/Multiple installation of Perl Modules metallica1973 Linux - General 1 02-17-2011 06:59 PM
want to list output in single line (space separated) saini_mw Linux - Newbie 8 02-01-2011 11:02 PM
how to create a single line of output from multiple variable lines of input steven.c.banks Linux - General 2 02-03-2010 04:09 PM
How to print a given line from a file on the standard output Fond_of_Opensource Linux - Newbie 1 08-24-2006 03:45 AM
PERL editing single line in file with regex indiescene Programming 0 04-14-2004 09:18 AM


All times are GMT -5. The time now is 09:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration