Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] s/// is _NOT_ substituting

Expand Messages
  • merlyn@stonehenge.com
    ... calcfreak2003 #i tried this calcfreak2003 print Gimme something: ; calcfreak2003 $var = ; calcfreak2003 chomp $var; calcfreak2003 print Gimme
    Message 1 of 2 , Nov 3, 2004
    • 0 Attachment
      >>>>> "calcfreak2003" == calcfreak2003 <calcfreak2003@...> writes:

      calcfreak2003> #i tried this

      calcfreak2003> print "Gimme something:";
      calcfreak2003> $var = <STDIN>;
      calcfreak2003> chomp $var;
      calcfreak2003> print "Gimme a letter or string to replace:";
      calcfreak2003> $var2 = <STDIN>;
      calcfreak2003> chomp $var2;
      calcfreak2003> print "Replacement char\/string?:";
      calcfreak2003> $var3 = <STDIN>;
      calcfreak2003> chomp $var3;
      calcfreak2003> $var =~ s/\$var2/\$var3/g;
      calcfreak2003> print $var;

      calcfreak2003> #but then i entered "o(()()())" for $var, "o(" for $var2 and "o,("
      calcfreak2003> for $var3
      calcfreak2003> #and it prints $var1 as if nothing happened

      Yes, because there's no appearance of '$var2' in the string 'o(()()())'.
      As in, "dollar v a r 2".

      What did you expect it to do? You backslashed your '$'! That says
      "this is just a dollar sign, not the beginning of a variable name".

      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    Your message has been successfully submitted and would be delivered to recipients shortly.