Hi,
Is there an equivalent to the perl command chomp in C? And if there is
no exact equivalent command, how would I go about removing the "\n" at
the end of a stdin?
Thank you,
Natalie
Nov 3 '06
35 19488
james of tucson <jmcgill@[go_ahead_and_sp am_me].arizona.eduwri tes:
Keith Thompson wrote:
>If you happen to know what Perl's chomp function does
It removes zero or more instances of a globally defined character
equivalence from the end each element of an input list or each element
of the list of values of a hash.
You obviously don't want to deal with the details of an off-topic
language, but you were inaccurate in your description.
In the article to which you're replying, I did not attempt to fully
describe what Perl's chomp function does. I inferred what the OP was
trying to do from his description and from the subset of chomp's
behavior of which is easily translated to C. Elsethread, I quoted the
actual definition of chomp from the camel book.
BTW, your description is ambiguous. I don't know what you mean by
"character equivalence", and your description could easily be read to
imply that chomp applied to "hello\n\n" will remove both newline
characters. chomp removes zero or one character from each string.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
james of tucson <jmcgill@[go_ahead_and_sp am_me].arizona.eduwri tes:
Jordan Abel wrote:
>Are you sure? chomp is used for a specific purpose, which is removing the newline from a whole line read from input.
That's like saying printf(...) is used for a specific purpose, which is
putting the characters "Hello, world!" on the console.
Not really. Probably 99% of calls to chomp in Perl programs do
exactly that (though it's certainly far more versatile). Similarly,
printf() can do far more that print "Hello, world!"; the difference is
that in real programs it usually does.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
[with respect to perl chomp]
>and your description could easily be read to imply that chomp applied to "hello\n\n" will remove both newline characters. chomp removes zero or one character from each string.
$ perldoc -f chomp
"When in paragraph mode ($/ = ""), it removes all trailing newlines
from the string."
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
In article <Fl************ ********@newsfe 10.phx>,
james of tucson <jmcgill@[go_ahead_and_sp am_me].arizona.eduwro te:
[perl chomp]
>I would almost bet that chomp() is implemented as a specialization of map{}, which doesn't *have* a day job, but is pretty much the most powerful thing in perl.
You'd lose that bet, at least in perl 5.8.4 (and probably much the
same for all earlier versions.) Source file doop.c about lines 1004
to 1139, Perl_do_chomp() routine. It is clearly its own routine,
not a calling upon map and clearly not being a degenerate version
of map. Quite a bit of of the routine is preoccupied with utf8 handling.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
In article <i9************ ********@newsfe 10.phx>,
james of tucson <jmcgill@[go_ahead_and_sp am_me].arizona.eduwro te:
[perl chomp]
>It removes zero or more instances of a globally defined character equivalence from the end each element of an input list or each element of the list of values of a hash.
It does not, at least not at perl 5.8.4.
$ perldoc perlvar
$/ [...] You may set it to a multi-character string
to match a multi-character delimiter,
[...] Remember: the value of $/ is a string, not a regexp.
AWK has to be better for something :-)
Not, in other words, a character equivilance: it is a literal match,
except in its treatment of "", undef, and "\n\n" .
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
[with respect to perl chomp]
>>and your description could easily be read to imply that chomp applied to "hello\n\n" will remove both newline characters. chomp removes zero or one character from each string.
$ perldoc -f chomp
"When in paragraph mode ($/ = ""), it removes all trailing newlines
from the string."
Ok, I missed that (even though I recently posted it myself). But
that's not the way it's usually used, and I don't believe it's what
the OP was looking for.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fernando Armenta |
last post by:
How you cut off the ^M at the end of a line? rstrip is not working.
string.rstrip(build_number)
thanks,
|
by: Edward WIJAYA |
last post by:
Hi,
I am new to Python, and I like to
learn more about it. Since I am
used to Perl before, I would like
to know what is Python equivalent
of Perl code below:
$filename = $ARGV;
|
by: Caj Zell |
last post by:
Hello,
I am looking a little bit at python and am curious of one thing I
often use in perl. Suppose, I want to change the string
"best_composer" to "Zappa" in a document called facts.txt, then in
perl I would do
perl -pi.bak -e "s/best_composer/Zappa/;" facts.txt
Can I do that with python from the command line so easily?
|
by: Aaron Powell |
last post by:
I am writing a program for a study I am doing where I must contact several
different organisations stored in a database I compiled, but I need to send
each email one at a time so they don't know who else I sent to.
I tested my sendmail and it works well, but I am having a problem with chomp
in the case I am using it. When getting $email, if I do not say $email\n,
nothing will be displayed to the command prompt. This leads me to believe...
|
by: Matt Taylor |
last post by:
I have this piece of code:
$/ = ' ';
$test = "abc ";
chomp $test;
print $test;
which prints spaces at the end of the line. Shouldn't chomp strip the spaces
off the end of my scalar $test?
| |
by: mrmattborja |
last post by:
I have the following lines in a simple for() loop:
time_t rightnow;
(void) time(&rightnow);
fprintf(fp, " waited for pass %d to finish", asctime(localtime(&rightnow)), i)
However, when I pull up the file that it's writing to (run.log), or even printing to STDOUT, it appears that asctime() or localtime() is adding an extra newline character because the result is...
waited for pass 0 to finish
|
by: adriaan |
last post by:
I'm having this weird problem with chomp
I want to get all the numbers out of a file that looks like this
1,2
4,3,2
and have the first number point to an array of the others in a hash
I'm almost able to do this except for the fact that a '\n'
get ad to the last number,
I'm trying to get rid of it but somehow chomp just won't work
code :
open (DataBase,"voorwaardelijk.txt");
|
by: Beany |
last post by:
Hi,
Probably a very simple question for the experienced Perl programmers....
Im new to the language of Perl and at the moment im studying the function Chomp!
for some strange reason i cant figure this out? Chomp deletes \n off a string but i dont get it!
Can someone please show me a simple example and an outcome? and explain to me the purpose of this and why it's used?
|
by: ezechiel |
last post by:
Hi, while testing the program (runs in DOS), I thought "if someone hits enter without typing a letter before, what happens?"
I tested and the script ends.. Is this normal, or how can I avoid this?
print "To which analytical division is the study belonging to?\n\n";
print "\ti: Immunology\n";
print "\tc: Chemistry\n";
print "\tq: Quit\n";
print "\n\tYour choice: ";
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |