I am trying to write a simple script to convert old stock option symbols to a new symbol format. This should be simple, but I am very new to Perl.

This script should take a list of symbols from a text file, change them to the new format, and print them out. For example, I need to change A.TL5E001100.TAV to +TL\E5C1100.TAV.

When I run my script I get 2 errors:

1. Unrecognized escape \F passed through at Find.Replace.TAV.options.P2.pl line 33.

- so it is choking on the "\" and I am not sure how to tell Perl how to treat this as text. I tried single and double quotes.

2. Use of uninitialized value $NewSym in concatenation (.) or string at Find.Replace.TAV.options.P2.pl line 41, <FILE> line 590.

- I am trying to print the new symbols to a file and I am obviously not specifying the outputted values correctly.

# this is my script to translate TAV stock options. use strict; use warnings; open (OUTPUT, ">TAV.opt.rename.txt") || die "TAV.opt.rename.txt $!\n"; my @file = <TAV.stock.opt.oldsym.txt>; # my $OldSym; my $NewSym; foreach my $f (@file) { open (FILE, $f) || die "Could not open $f $!\n"; my $line; while ($line = <FILE>) { chomp ($line); if ($line =~ m/^A.TL5E00/) { $line =~ s/A.TL5E00/'+TL\E5C'/g; } elsif ($line =~ m/^A.TL5F00/) { $line =~ s/A.TL5F00/'+TL\F5C'/g; }

The line above is where it is choking on the "\" character

} $NewSym = $line; print OUTPUT "$NewSym\n"; }

In reply to Substitute script for a newbie by jspanos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.