Sponsored Content
Top Forums Shell Programming and Scripting perl: printf indentation problem Post 302179465 by wolwy_pete on Thursday 27th of March 2008 08:09:00 PM
Old 03-27-2008
sorry about my lack of understanding on how these functions work.
buffoonix`s method also works fine. thankx.
 

10 More Discussions You Might Find Interesting

1. Programming

disturbing problem with PRINTF() !!

hello everybody, here is my problem: ________________________________________ #include <stdio.h> int main() { int i=10; printf("value is %i",i); return 0; } _________________________________________ when i compile and execute, nothing appears on screen!! but if i replace the printf... (2 Replies)
Discussion started by: brain_processin
2 Replies

2. UNIX for Advanced & Expert Users

awk printf problem

Hi Friends, Can anyone guide me how to compute sum of column4 from the below file x using awk command? when i do using awk I'm getting sum 7482350198352648.000000 which is not accurate. $ cat x 56,232,dfgjkhdfj,,56,anand 56,22,dfgjkhdfj,7482347823453123.97834 ,56,Khan 56,23,dfgjkhdfj, ... (6 Replies)
Discussion started by: krishna
6 Replies

3. Shell Programming and Scripting

printf problem

I have the following code: $ awk '{ printf "%-10s %s\n", $1, $2, $3, $4, $5, $5, $6 }' file i can only print the first 2 elements ($1,$2). How can i print all the elements to appear like this: aardvark 5555553 jhfjhfjkg efiigig ejkfjkej wjkdjk alpo-net 5553412 ... (2 Replies)
Discussion started by: DDoS
2 Replies

4. Shell Programming and Scripting

Awk printf problem

Hi, I've got a basic problem using printf statement in awk. I want to write float values with always 8 characters width. Examples : 1.345678 12.45678 123.4567 1234.678 -23.5678 -2.45678 -23456.8 ..... I cannot find the right printf format %8.1f, %7.5f.... Can anyone help ?... (4 Replies)
Discussion started by: cazhot
4 Replies

5. Shell Programming and Scripting

printf vs sprintf - perl

I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns? Here is my code: #!/usr/bin/perl $time = localtime(time);... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

6. Shell Programming and Scripting

Printf problem

I am having a major problem with printf, The more I pad it, the less I see :( The problem is in the first function, report Am I ruining output somewhere? I wont print out the names propely, it cuts them off or deletes them completely :( #!/bin/bash report() { printf "%-10s" STUD# ... (2 Replies)
Discussion started by: L0ckz0r
2 Replies

7. Shell Programming and Scripting

printf problem

In one of the scripts I am using pintf function as following printf "%s%s%s\n" "$f1" "$f2" "$f3" f3 variable contains a string of 10 characters. However it has value first 7 character and last 3 characters are empty. Example Aaaaaaa<3 spaces> bbbbbbb<3 spaces> ccccccc<3 spaces>... (4 Replies)
Discussion started by: varunrbs
4 Replies

8. Shell Programming and Scripting

problem with printf in shell script

i have written small script as follows: name="hi hello" printf "%-20s" $name This gives me strange output. -20s format is applied on both word of string. i.e it displays both word hi and hello in space of 20 length. I want to display entire string "hi hello" in length of 20 space. plz... (2 Replies)
Discussion started by: admc123
2 Replies

9. Shell Programming and Scripting

printf (awk,perl,shell) float rounding issue

Hi guys, could someone throw some light on the following behaviour of printf (I'll start with info about the system and the tool/shell/interpreter versions)?: $ uname -a Linux linux-86if.site 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64... (9 Replies)
Discussion started by: elixir_sinari
9 Replies

10. Programming

[Perl] Different printf formating for different print options

Hi, Struggling with single quotes, double quotes, etc. I want to print a header line, followed by lines with actual values, based on a print option. In real life it is going to be something like 15 print options and 50 values. Output will be 1 header and several value lines. In this example... (5 Replies)
Discussion started by: ejdv
5 Replies
Class::Default(3pm)					User Contributed Perl Documentation				       Class::Default(3pm)

NAME
Class::Default - Static calls apply to a default instantiation SYNOPSIS
# Create the defaulted class package Foo::Base; use base 'Class::Default'; sub new { bless {}, $_[0] } sub show { my $self = shift->_self; "$self"; } # Do something to the default object package main; print Foo::Bar->show; # Prints 'Foo::Bar=HASH(0x80d22f8)' DESCRIPTION
Class::Default provides a mechanism to allow your class to take static method calls and apply it to a default instantiation of an object. It provides a flexibility to an API that allows it to be used more confortably in different situations. A good example of this technique in use is CGI.pm. When you use a static method, like "CGI-"header>, your call is being applied to a default instantiation of a CGI object. This technique appears to be especially usefull when writing modules that you want to be used in either a single use or a persistant envi- ronment. In a CGI like environment, you want the simplicity of a static interface. You can call "Class-"method> directly, without having to pass an instantiation around constantly. USING THE MODULES
Class::Default provides a couple of levels of control. They start with simple enabling the method to apply to the default instantation, and move on to providing some level of control over the creation of the default object. Inheriting from Class::Default To start, you will need to inherit from Class::Default. You do this in the normal manner, using something like "use base 'Class::Default'", or setting the @ISA value directly. "Class::Default" does not have a default constructor or any public methods, so you should be able to use it a multiple inheritance situation without any implications. Making method work To make your class work with Class::Default you need to make a small adjustment to each method that you would like to be able to access the default object. A typical method will look something like the following sub foobar { my $self = shift; # Do whatever the method does } To make the method work with Class::Default, you should change it to the following sub foobar { my $self = shift->_self; # Do whatever the method does } This change is very low impact, easy to use, and will not make any other differences to the way your code works. Control over the default object When needed, Class::Default will make a new instantation of your class and cache it to be used whenever a static call is made. It does this in the simplest way possible, by calling "Class-"new()> with no arguments. This is fine if you have a very pure class that can handle creating a new object without any arguments, but many classes expect some sort of argument to the the constructor, and indeed that the constructor that should be used it the "new" method. Enter the "_create_default_object" method. By overloading the "_create_default_object" method in your class, you can custom create the default object. This will used to create the default object on demand, the first time a method is called. For example, the following class demonstrate the use of "_create_default_object" to set some values in the default object. package Slashdot::User; use base 'Class::Default'; # Constructor sub new { my $class = shift; my $name = shift; my $self = { name => $name, favourite_color => '', }; return bless $self, $class; } # Default constructor sub _create_default_object { my $class = shift; my $self = $class->new( 'Anonymous Coward' ); $self->{favourite_color} = 'Orange'; return $self; } sub name { $_[0]->_self->{name}; } sub favourite_color { $_[0]->_self->{favourite_color}; } That provides a statically accessible default object that could be used as in the following manner. print "The default slashdot user is " . Slashdot::User->name . " and they like the colour " . Slashdot::User->favourite_color; Remember that the default object is persistant, so changes made to the statically accessible object can be recovered later. Getting access to the default object There are a few ways to do this, but the easiest way is to simple do the following my $default = Slashdot::User->_get_default; METHODS
_self Used by methods to make the method apply to the default object if called statically without affecting normal object methods. _class The "_class" method provides the opposite of the "_self" method. Instead of always getting an object, "_class" will always get the class name, so a method can be guarenteed to run in a static context. This is not essential to the use of a "Class::Default" module, but is pro- vided as a convenience. _get_default Used to get the default object directly. _create_default_object To be overloaded by your class to set any properties to the default object at creation time. BUGS
No known bugs, but suggestions are welcome SUPPORT
Bugs should be reported via the CPAN bug tracker at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Default> For other issues, contact the author AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
<http://ali.as/>, Class::Singleton COPYRIGHT
Copyright (c) 2002 - 2006 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.8.8 2008-03-07 Class::Default(3pm)
All times are GMT -4. The time now is 09:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy