casperdaghost has asked for the wisdom of the Perl Monks concerning the following question:
I have a scrit that picks out any word with a "$" in it. I am attempting to add double quotes to this variable in perl
#!/usr/bin/perl use warnings; use strict; my $escaping_file = $ARGV[0]; open( my $filehandle, "<" , "$escaping_file" ) || die "failed : $!"; while (<$filehandle>) { if ($_ =~ /^\$?\w+\$+\w+\$?$/g) { s/\$/\\\$/g ; #$escaped_wquotes = "".$_."" ; #$escaped_wquotes = "\"$_\"" ; $escaped_wquotes = qq("$_") ; print "$escaped_wquotes"; } }
each time I try i get this. the two commented out varaibles give the saem result.
[casper@casperbox$ ./check_escapes /tmp/new_list "bc\$stp ""soc\$ny ""icon\$test ""btec\$stp ""ec\$stp2 ""bos\$nyc ""tec\$live5 ""\$foo\$foo\$ ""\$foo\$baz ""foo\$bad\$
i am trying to get the varaible to spit this out.
"bc\$stp" "soc\$ny" "icon\$test" "btec\$stp" "ec\$stp2" "bos\$nyc" "tec\$live5" "\$foo\$foo\$" "\$foo\$baz" "foo\$bad\$"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: add double quotes to a perl variable
by Kenosis (Priest) on Nov 15, 2013 at 20:33 UTC | |
by casperdaghost (Initiate) on Nov 15, 2013 at 20:40 UTC | |
by Kenosis (Priest) on Nov 15, 2013 at 20:49 UTC | |
|
Re: add double quotes to a perl variable
by oiskuu (Hermit) on Nov 16, 2013 at 07:02 UTC | |
by tobyink (Canon) on Nov 16, 2013 at 18:57 UTC |