Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Use of uninitialized value in concatenation

by targetsmart (Curate)
on Jun 11, 2009 at 05:34 UTC ( #770533=note: print w/ replies, xml ) Need Help??


in reply to Use of uninitialized value in concatenation

if i understand your problem right, this could be the solution.

use strict; use warnings; my %words = map { $_ => 1 } qw($Word $name $test); my $line = '$Word $ $ $ $test'; $line =~ s/(\$\w*)/exists $words{$1} ? $1 : " dollar "/eg; print "$line\n\n";
will produce
$Word dollar dollar dollar $test

UPDATE
thanks AnomalousMonk, actually i misunderstood the problem :)
this could do it

$line =~ s/(\$(\w*))/exists $words{$1} ? $1 : "dollar$2"/eg;

Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.


Comment on Re: Use of uninitialized value in concatenation
Select or Download Code
Re^2: Use of uninitialized value in concatenation
by AnomalousMonk (Abbot) on Jun 11, 2009 at 06:07 UTC
    >perl -wMstrict -le "my %words = map { $_ => 1 } qw($Word $name); my $line = '$Word $ $foo'; $line =~ s/(\$\w*)/exists $words{$1} ? $1 : qq{ dollar }/eg; print $line; " $Word dollar dollar
    I think the OPer wants '$foo' to be replaced by 'dollarfoo'. And what's with the extra spaces?
      #!/usr/bin/perl -w use strict; my %words = map { $_ => 1 } qw($Word $name); my $line = '$Word $ $foo'; $line =~ s/(\$\w*)/exists $words{$1} ? $1 : qq{ dollar }/eg; print $line;
      For $foo it prints dollar and not dollarfoo. But still gets a warning message

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://770533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-10-24 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (137 votes), past polls