String question

S

Santana

Hei all,
i'am a newbie in PERL and i find a solution for this problem :

I have a string "xxxxxxx" , i want put ones("1") on left of string, if
this string dont have a length of 20 character.

Example :

if i have th string "HELLO" and woul like get this ;

"111111111111111HELLO"


How i can this ???



Thanks,
Paulito
 
J

John W. Krahn

Santana said:
Hei all,
i'am a newbie in PERL and i find a solution for this problem :

I have a string "xxxxxxx" , i want put ones("1") on left of string, if
this string dont have a length of 20 character.

Example :

if i have th string "HELLO" and woul like get this ;

"111111111111111HELLO"


How i can this ???

$ perl -le'
my $string = "HELLO";

print substr "1" x 20 . $string, -20;
'
111111111111111HELLO



John
 
M

Mirco Wahab

Santana said:
I have a string "xxxxxxx" , i want put ones("1") on left of string, if
this string dont have a length of 20 character.
if i have th string "HELLO" and would like get this ;
"111111111111111HELLO"
How i can this ???

Just by printing the proper count of '1's in front of the string:

...
$string = 'xxxxxxx';
...
$string = '1' x (20-length $string) . $string;


No rocket science required here ;-)

Regards

M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top