473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

program for input apple output "apple"

my frogram for it
Expand|Select|Wrap|Line Numbers
  1. #!usr/local/bin/perl
  2. #program practice
  3. $file='input.txt';
  4. open(FH, $file);
  5. @line=<FH>;
  6. open(OUT, ">>output.txt");
  7. foreach $file(@line)
  8. {
  9. $r="#$file#";
  10. print(OUT "$r");
  11. }
  12.  
  13. close(FH);
  14.  
  15.  
  16. input i gave
  17. apple 
  18. peach
  19. orange
  20. watermelon
  21.  
  22. output is coming like this
  23. #apple
  24. #peach
  25. #orange
  26. #watermelon
  27.  
  28. instead i want like this
  29. #apple#
  30. #peach#
  31. #orange#
  32. #watermelon#
  33.  
plz help
plz
Jan 15 '10 #1
1 1537
nithinpes
410 Expert 256MB
when you read from the file, $file contains a newline. Remove the newline before appending the #.

Expand|Select|Wrap|Line Numbers
  1. foreach $file(@line)
  2. {
  3. chomp $r;                         #remove newline
  4. $r="#$file#\n";                    #add newline
  5. print(OUT "$r");
  6. }
  7.  
  8.  
Jan 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

99
by: Jim Hubbard | last post by:
It seems that Microsoft not only does not need the classic Visual Basic developer army (the largest army of developers the world has ever seen), but now they don't need ANY Windows developer at a...
9
by: aden | last post by:
I have read the years-old threads on this topic, but I wanted to confirm what they suggest. . . Can the this pointer EVER point to a type different from the class that contains the member...
0
by: David T | last post by:
Has anyone run across this error? When calling any of several visualization routines from FiPy, Python quits with a Bus Error I'm using MacOS X Tiger 10.4.3, and I've tried several builds...
0
by: U S Contractors Offering Service A Non-profit | last post by:
" Visionary Dreams " " Leaving New york City leaving to go " GOD noes were i Don't "
0
by: U S Contractors Offering Service A Non-profit | last post by:
ALOT of them to pick from... Inbox Reply Craig Somerford to uscosoct24, Matthew, B-eing-I-nstru., Ed, me, New, mw, Natural, (bcc:USA), (bcc:Letters), (bcc:lvargas), (bcc:Le), (bcc:staff),...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Baby steps to the "New" New Orleans Inbox Reply Craig Somerford to Chasing, Donald, me, (bcc:Discovery), (bcc:Beijing) show details 3:55 pm (0 minutes ago) Our Beloved New Orleans needs you...
9
by: Ronald S. Cook | last post by:
Can I write If MyString = "Apple" Or MyString = "Orange" Or MyString = "Pear" Then to something more compact like If MyString In ("Apple", "Orange", "Pear") Then My last line obviously...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.