![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with perl | ali560045 | Shell Programming and Scripting | 6 | 05-29-2008 08:26 AM |
| Problem with "printf" | Lokesha | UNIX for Dummies Questions & Answers | 1 | 02-07-2008 10:20 AM |
| A question of indentation | Michael Iatrou | High Level Programming | 1 | 12-23-2006 05:29 PM |
| awk printf problem | krishna | UNIX for Advanced & Expert Users | 6 | 11-18-2003 11:59 PM |
| disturbing problem with PRINTF() !! | brain_processin | High Level Programming | 2 | 03-10-2002 09:03 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
hi all, im having a problem with using perl printf. my requirement is to print a string (like [OK]) at the right most end of the screen. i tried this perl script, but it fails with an error; Code:
#!/usr/bin/perl use strict; use warnings; my $scrW = 0; my $str = `stty size`; # get the screen character width $str =~ m/(\d+)\s*$/; # extract the char width $scrW = eval($1); # put the char width in a varable $scrW $scrW -=10; # reduce the char width by 10 printf "%($scrW)s\n", "abcde"; tried to use printf with a variable as indentation length, but fails. this type of method works in bash. does anyone have an idea ? thankx. |
|
||||
|
You don't need the eval, just assign $1 to $scrW. And take out the parentheses in the printf. You then need braces around the variable name to disambiguate the variable name from the traliing s, like ${scrW}s
If you subtract ten, you obviously don't use the entire screen width, but I guess you know that. |
|
||||
|
Quote:
i subtracted ten thinking that the length of the string im gonna print is 10. ![]() what u said worked anyway, thankx for the solution. |
![]() |
| Bookmarks |
| Tags |
| bash, bash eval, eval |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|