2008/7/14 Rob Dixon <[EMAIL PROTECTED]>: > > Dermot wrote: >> >> I am trying to build a hash(ref) and while doing so I want to remove >> any white space from strings such as "1280 x 1024". So I have >> >> my $record = { >> contributor => $resolution, >> .... >> }; >> >> Perhaps I am trying to be too clever but I thought I could do >> >> my $record = { >> contributor => $resolution =~ s/\s+//g, >> >> >> But my value ends up as 2, the number of white space matches I guess. >> Is this a question on context, scalar or list? Or is this sort of >> assignment over-stretching things? > > The substitution operator alters the object string and returns the number of > changes, as you have found. You could write > > ($record{contributor} = $resolution) =~ s/\s+//g; > > or perhaps > > my $record = { > contributor => do {$resolution =~ s/\s+//g; $resolution}, > }; > > HTH,
The do method worked. I guess that makes it into a sub which is fine. BTW, have I told you what a star you are? You have replied to every item that's come onto the list. Well done. Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/