Re: split up long string with spaces

2004-08-27 Thread John W. Krahn
JP wrote: $string =~ s/(\S{40}/\1 /g; Only use \1 (and \2, \3, etc.) in regular expressions. Use $1 (and $2, $3, etc.) in double quoted strings. $string =~ s/(\S{40})/$1 /g; does exactly the trick I need. now I wonder if it is possible to print the resulting spaced string without changing $stri

Re: split up long string with spaces

2004-08-27 Thread JP
> : $string =~ s/(\S{40}/\1 /g; > > You should really consider turning warnings on. > > #!/usr/bin/perl -w I always use warnings, though I am developping on one system, and reading my news on another (NNTP-enabled) one. therefore I can't copy and paste. it was a typo indeed but only in my post

Re: split up long string with spaces

2004-08-27 Thread JP
yeah, I think I will add the (?=.) Thanks "Mark Maunder" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > G'day. > > $string =~ s/(.{4})(?=.)/$1 /g; > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: split up long string with spaces

2004-08-27 Thread Charles K. Clarkson
From: JP wrote: : Got it! : : $string =~ s/(\S{40}/\1 /g; You should really consider turning warnings on. #!/usr/bin/perl -w or: use warnings; : does exactly the trick I need. There's a typo. The parenthesis doesn't close. When you post code, try to cut an

Re: split up long string with spaces

2004-08-27 Thread JP
Got it! $string =~ s/(\S{40}/\1 /g; does exactly the trick I need. now I wonder if it is possible to print the resulting spaced string without changing $string itself? do I really need a temporary variable or is it possible to do something like: print $string s/(\S{40}/\1 /g; "Jp" <[EMAIL PR

Re: split up long string with spaces

2004-08-27 Thread Mark Maunder
G'day. $string =~ s/(.{4})(?=.)/$1 /g; FYI, the ?= at the end is a zero-width look ahead assertion that stops a space from being inserted after the last 4 chars. Please see 'perldoc perlre' for details. Mark. On Fri, 2004-08-27 at 05:51, JP wrote: > I am trying to split up a given string of unk