Sponsored Content
Top Forums Shell Programming and Scripting perl: simple question on string append Post 302117481 by jim mcnamara on Monday 14th of May 2007 05:09:26 PM
Old 05-14-2007
Code:
$result = sprintf("%.2f", $number);

 

10 More Discussions You Might Find Interesting

1. Programming

simple question on string concat

This is a simple question... char *str = NULL; int num = 0; scanf ("%d", &num); str = ??? I want str to point to the string num.txt For e.g: If user enters num = 5, str should point to "5.txt" How do I do that ? Thanks (2 Replies)
Discussion started by: the_learner
2 Replies

2. Shell Programming and Scripting

PERL: simple comparing arrays question

Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example my @array1 = ("gary" ,"peter", "paul"); my @array2 = ("gary" ,"peter", "joe"); I have two arrays above, and i want to something like this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

3. Shell Programming and Scripting

Simple perl question

I am totally new to perl. I am modifying someone else's script. I have the following output: # ./some-perlscript A B C D E B - E, is generated through the print command that I put in the script. I want to remove A, it seems it is generated automatically by a custom OS it is querying when... (3 Replies)
Discussion started by: streetfighter2
3 Replies

4. Shell Programming and Scripting

how to append a string to next line in perl

hi all , i have a requirement like this.. this just a sample script... $ cat test.sh #!/bin/bash perl -e ' open(IN,"addrss"); open(out,">>addrss"); @newval; while (<IN>) { @col_val=split(/:/); if ($.==1) { for($i=0;$i<=$#col_val;$i++) { ... (2 Replies)
Discussion started by: tprayush
2 Replies

5. Shell Programming and Scripting

Simple Question about Reading file by Perl

Hi , I just write a simple function to read the file line by line. But when I run it it says out of memory. I am not sure about the root cause, Can someone help me out of this? :D #! /usr/bin/perl use strict; sub checkAPs{ my $NDPDir = "/home/eweiqqu/NCB/NDP_files/"; ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

6. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

7. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

8. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

9. Shell Programming and Scripting

Simple Perl question

Hello, I'm completely new to Perl and I'm just looking for a quick answer to some code I'm trying to come up with. I'm trying to access a website, part of the URL I want the user to be able to define via standard input. As you can see below I'm still trying to get the syntax. ... (2 Replies)
Discussion started by: wxornot
2 Replies

10. Shell Programming and Scripting

Perl String Replacement Syntax Question . . .

Greetings! I've been tooling about with Perl to make a few string replacements in some files; and seem to have run into a bit of a squeeze :) Beginning with a simple text file, test.txt, we have the following content to be worked:Now, not wanting to have anyone feel left out, I decided that... (6 Replies)
Discussion started by: LinQ
6 Replies
explain_sprintf(3)					     Library Functions Manual						explain_sprintf(3)

NAME
explain_sprintf - explain sprintf(3) errors SYNOPSIS
#include <libexplain/sprintf.h> const char *explain_sprintf(char *data, const char *format, ...); const char *explain_errno_sprintf(int errnum, char *data, const char *format, ...); void explain_message_sprintf(char *message, int message_size, char *data, const char *format, ...); void explain_message_errno_sprintf(char *message, int message_size, int errnum, char *data, const char *format, ...); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the sprintf(3) system call. explain_sprintf const char *explain_sprintf(char *data, const char *format, ...); The explain_sprintf function is used to obtain an explanation of an error returned by the sprintf(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. data The original data, exactly as passed to the sprintf(3) system call. format The original format, exactly as passed to the sprintf(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = sprintf(data, format, ...); if (result < 0) { fprintf(stderr, "%s ", explain_sprintf(data, format, ...)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_sprintf_or_die(3) function. explain_errno_sprintf const char *explain_errno_sprintf(int errnum, char *data, const char *format, ...); The explain_errno_sprintf function is used to obtain an explanation of an error returned by the sprintf(3) system call. The least the mes- sage will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. data The original data, exactly as passed to the sprintf(3) system call. format The original format, exactly as passed to the sprintf(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = sprintf(data, format, ...); if (result < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_sprintf(err, data, format, ...)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_sprintf_or_die(3) function. explain_message_sprintf void explain_message_sprintf(char *message, int message_size, char *data, const char *format, ...); The explain_message_sprintf function is used to obtain an explanation of an error returned by the sprintf(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. data The original data, exactly as passed to the sprintf(3) system call. format The original format, exactly as passed to the sprintf(3) system call. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = sprintf(data, format, ...); if (result < 0) { char message[3000]; explain_message_sprintf(message, sizeof(message), data, format, ...); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_sprintf_or_die(3) function. explain_message_errno_sprintf void explain_message_errno_sprintf(char *message, int message_size, int errnum, char *data, const char *format, ...); The explain_message_errno_sprintf function is used to obtain an explanation of an error returned by the sprintf(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. data The original data, exactly as passed to the sprintf(3) system call. format The original format, exactly as passed to the sprintf(3) system call. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = sprintf(data, format, ...); if (result < 0) { int err = errno; char message[3000]; explain_message_errno_sprintf(message, sizeof(message), err, data, format, ...); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_sprintf_or_die(3) function. SEE ALSO
sprintf(3) formatted output conversion explain_sprintf_or_die(3) formatted output conversion and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_sprintf(3)
All times are GMT -4. The time now is 08:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy