Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Use of uninitialized value in concatenation

by targetsmart (Curate)
on Jun 11, 2009 at 05:34 UTC ( [id://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.

Replies are listed 'Best First'.
Re^2: Use of uninitialized value in concatenation
by AnomalousMonk (Archbishop) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://770533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2026-01-14 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.