in reply to Regular Expression Help

$u = ('0' x (6-length($u))).$u;

Replies are listed 'Best First'.
Re^2: Regular Expression Help
by Anonymous Monk on Jun 28, 2005 at 17:53 UTC
    Hi interesting, can you give me an explaination on this code?
    Thanks!
      Sure! Basically if you take where we started : $u = ('0' x (6-length($u))).$u; we can break this up into multiple statements:
      $length_of_u = length($u); # how long is this string? $how_many_characters_short = 6-$length_of_u; # how far are we from ha +ving 6 characters? $padding = '0' x $how_many_characters_short; # this will give us as ma +ny 0's as $how_many_characters_short is long (e.g. if it is 4 - it gi +ves us '0000') $u = $padding.$u; # concatenate them together... finished!
      HTH!
        Thank you all for the big HELP!!!!