jspanos has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Substitute script for a newbie
by toolic (Bishop) on Jul 14, 2015 at 16:44 UTC | |
by jspanos (Initiate) on Jul 14, 2015 at 17:14 UTC | |
by Laurent_R (Canon) on Jul 14, 2015 at 17:52 UTC | |
by jspanos (Initiate) on Jul 14, 2015 at 18:44 UTC | |
by Laurent_R (Canon) on Jul 14, 2015 at 18:55 UTC | |
| |
|
Re: Substitute script for a newbie
by neilwatson (Priest) on Jul 14, 2015 at 17:47 UTC | |
by toolic (Bishop) on Jul 14, 2015 at 18:05 UTC | |
by Laurent_R (Canon) on Jul 14, 2015 at 18:49 UTC | |
by Laurent_R (Canon) on Jul 14, 2015 at 20:16 UTC |