String question

String question

am 07.09.2007 09:59:49 von 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

Re: String question

am 07.09.2007 10:29:28 von Dummy

Santana wrote:
> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: String question

am 07.09.2007 11:33:34 von Mirco Wahab

Santana wrote:
> 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.