Perl equivalent of ksh if / echo statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl equivalent of ksh if / echo statement
# 1  
Old 02-17-2005
Question Perl equivalent of ksh if / echo statement

Is there an equivalent perl statement for the following ksh statement ?

example

if [ `echo $ans |wc -c` = 2 ]
then
...
else
...
fi
# 2  
Old 02-17-2005
Hmm ... something along the lines of:

Code:
if (length($ans) == 2) {
# ...
} else {
# ...
}

length() returns the number of characters. If the text is in plain ASCII, this equals the number of bytes. Perl usually treats multibyte string as ASCII so length() on a multibyte string will appear to give you the number of bytes too.

If you really want bytes instead of the number of characters, you can also try this:

Code:
{
require bytes;
if (bytes::length($ans) == 2) {
# ...
} else {
# ...
}
}

# 3  
Old 02-17-2005
In ksh I would just do:
if [[ ${#ans} -eq 2 ]]
anyway.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If echo statement return false

I have this code that sometimes return a false value and the code inside the if statement gets executed and error out. Any idea why? thanks. So I set a debug and see what the value for $ScriptElapsedTime Here is the value I got ScriptElapsedTime='03:20'. Base on this value the if... (10 Replies)
Discussion started by: nugent
10 Replies

2. UNIX for Dummies Questions & Answers

Bash statement equivalent

Hi all, i need a equivalent for the statement i run in bash, so it would also run in other shells. Specially i need it for ksh to run on AIX. Here the statements: exec > >(tee -a $log) exec 2> >(tee -a $log >&2) Thanks. (5 Replies)
Discussion started by: Kosak
5 Replies

3. Shell Programming and Scripting

Perl : Perl equivalent to the ksh | and ;

Ive been trying to move to Perl. It has been a struggle. My question is, is there a good resource that explains nesting statements. As an example. To change primary Factory CTS 1.9.0(46) P1 *Slot 1 CTS 1.10.2(42) P1 To primary *Slot 1 CTS 1.10.2(42) P1 ... (5 Replies)
Discussion started by: popeye
5 Replies

4. Shell Programming and Scripting

Expect : what is the equivalent to ksh if -s

In Ksh to check if file exists and is non zero .. if ; then echo "Error $FILE does not exists!" else echo "$FILE found!" fi Cant seem to find the Expect equivalent .... Any help is greatly appreciated. (2 Replies)
Discussion started by: popeye
2 Replies

5. Shell Programming and Scripting

ksh equivalent to >& in csh

In csh I am using >&. What is the equivalent in ksh?? >& - redirect stdout and stderr (csh,tcsh) (18 Replies)
Discussion started by: kristinu
18 Replies

6. Shell Programming and Scripting

equivalent of backspace in ksh

Hello All, What would be the equivalent of backspace key in the korn shell. My scenario is: I am trying to install a product..and it comes out with a Licence Agreement screen, When I manually enter backspace key..I am able to get out of the whole agreement message to a point to type Agree A) or... (2 Replies)
Discussion started by: solaix14
2 Replies

7. Shell Programming and Scripting

setting width in echo statement

Hello All, I need to set the width or number of columns for my dynamic output in the echo statement. statement is like: echo " <output> " here the <output> is dyamice and can be of any number of characters, the " " should always start in same column everytime it is... (4 Replies)
Discussion started by: s123.radha
4 Replies

8. Shell Programming and Scripting

echo statement issue

Hi All, I am pasting my code below if # e means file exists then echo OFR_Configlist exists >> OFR_Backup_Configfiles.log else echo OFR_Configlist Not exists >> OFR_Backup_Configfiles.log exit fi How can i show the echo message in console also at the same time? I dont want to write... (3 Replies)
Discussion started by: subin_bala
3 Replies

9. Shell Programming and Scripting

what is ksh equivalent of bash echo -n ?

Hi folks, I need to stop printing a new line after echoing a string in KSH. i know bash provides echo -n "string" what is the ksh equivalent for this ? (3 Replies)
Discussion started by: mudhireddy
3 Replies

10. Shell Programming and Scripting

echo statement

Does anyone know the correct syntax for computing arithmetic expressions inside the echo statement? Let me know, thanks (3 Replies)
Discussion started by: circleW
3 Replies
Login or Register to Ask a Question