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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to