2008/7/14 Brad Baxter <[EMAIL PROTECTED]>: > Dermot wrote: >> >> Hi, >> >> 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? > > It will return 2 regardless of context. But speaking of assignment, > what about when you first set the resolution ... > > ( my $resolution = "1280 x 1024" ) =~ s/\s+//g; > > my $record = { > contributor => $resolution, > }; > > or if you use the resolution for other things first, a sub ... > > sub strip{ s/\s+//g for @_; @_ } > my $record = { > contributor => strip $resolution, > }; > > of if you don't really want to change the resolution ... > > sub strip{ ( my $s = shift ) =~ s/\s+//g; $s } > my $record = { > contributor => strip $resolution, > }; > > or something silly for grins ... > > my $record = { > contributor => scalar( $resolution =~ s/\s+//g, $resolution ), > }; > > > -- > Brad
I would say say your just being flash but there is something in the idea of having a sub {s/\s+//g; for @_;@_}. You do get re-usability. The data is coming from tab-delimited files and I am trying to parse the data into a sqlite3 db. In the process I'd like to validate the data but that the subject of another email. Thanx, Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/