>> >> >> >> Thanks guys.  With some help I've come up with this:
>> >> >> >>
>> >> >> >> $string = 'abc def ghi jkl mno pqr stu vwx yz';
>> >> >> >> if(length($string) = 34) {$var1 = $string.":";}
>> >> >> >
>> >> >> > '=' is assignment, '==' is test for numerical equality.
>> >> >> Change the above
>> >> >> > line to:
>> >> >> >    if( length($string) == 34 ) { $var1 = $string . ':' }
>> >> >> >
>> >> >> >> if(length($string) > 34) {
>> >> >> >>   $string =~ s/\s//g;
>> >> >> >
>> >> >> > The above line deletes all of the spaces in $string. Is
>> >> >> that what you want
>> >> >> > to do?
>> >> >>
>> >> >> All fixed up except for this.  How can I remove only the
>> >> spaces at the
>> >> >> end of $var1 and $var2 if they exist?
>> >> >>
>> >> >> - Grant
>> >> >>
>> >> >>
>> >> >> >>   ($var1, $var2) = $string =~ /(.){35}(.){26}/;
>> >> >> >
>> >> >        This pulls 35 characters and splits words, yet what
>> >> you asked for was the last word separated. Correct?
>> >>
>> >> I'm trying to pull 35 or fewer characters to the nearest space
>> >> basically.  This is what I have now:
>> >>
>> >> if(length($string) <= 34) {$var1 = $string.":";}
>> >> if(length($string) > 34) {
>> >>   ($var1, $var2) = ($string =~ /(.{35})(.{26})/);
>> >
>> 1234567891124567892123456789312345
>> >        if you have in $string = q[1234 12345 12 5346 12367
>> 123 123678123];
>> > Then $var1 will be '1234 12345 12 5346 12367 123 12367',
>> but I thought you wanted '1234 12345 12 5346 12367 123'?
>> > Which one is the right one for what you are doing?
>>
>> You're right, I would want:
>>
>> 1234 12345 12 5346 12367 123
>>
>> Can you show me how to do that properly?
>>
>        I sent a reply which had a whole different tack to how you are doing 
> the processing. With Perl, there is always a number of ways to accomplish the 
> task. If and when you get the original email, it was a little program to test 
> out what you were entering.

Thank you for that.  I'm just looking for something more concise so I
can try to follow what it's doing.  Your script must be awesome but I
can't follow it.  I'm only a fake perl guy so far.

- Grant


>        Here is snippet of breaking that apart and re-joining
>    #
>    # if less than 35 characters, just add the colon
>    #
>    if ( length($string) < 35 ) {
>        $var1 = $string . q[:];
>     }
>     else {
>         @MyWorkw = split(/\s+/, $string);
>           #
>           # split the line by white space into an array
>           #
>         while ( 1 ) {
>             if ( length($var1)+length($MyWorkw[0]) < 35 ) {
>                 $var1 .= shift(@MyWorkw) . q[ ];
>              }
>              else {
>                  $var1 =~ s/ $/:/;
>                  last
>              }
>         }
>         while ( 1 ) {
>             if ( length($var2)+length($MyWorkw[0]) < 26 ) {
>                 $var2 .= shift(@MyWorkw) . q[ ];
>              }
>              else {
>                  $var2 =~ s/ $/:/;
>                  last
>              }
>         }
>
>     }
>         If you have any questions and/or problems, please let me know.
>         Thanks.
>
> Wags ;)
> David R. Wagner
> Senior Programmer Analyst
> FedEx Freight
> 1.719.484.2097 TEL
> 1.719.484.2419 FAX
> 1.408.623.5963 Cell
> http://fedex.com/us
>
>> - Grant
>>
>>
>> >>   $var1 =~ s/\s+$//;
>> >>   $var2 =~ s/\s+$//;
>> >>   $var2 .= ":";
>> >> }
>> >>
>> >> Does that look OK?  Is the 3rd line off?
>> >>
>> >> - Grant

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


          • Re: S... Jim Gibson
          • RE: S... Wagner, David --- Senior Programmer Analyst --- CFS
            • ... Grant
              • ... Jim Gibson
              • ... Wagner, David --- Senior Programmer Analyst --- CFS
              • ... Grant
              • ... Jim Gibson
              • ... Grant
              • ... Wagner, David --- Senior Programmer Analyst --- CFS
              • ... Grant
      • RE: String ma... Wagner, David --- Senior Programmer Analyst --- CFS
  • RE: String manipulatio... Wagner, David --- Senior Programmer Analyst --- CFS

Reply via email to