Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: Substitute script for a newbie

by Laurent_R (Canon)
on Jul 14, 2015 at 18:55 UTC ( [id://1134784]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Substitute script for a newbie
in thread Substitute script for a newbie

Thank you for your answer. So, if I understand correctly, you don't need a list of old and new names, you can figure out the new name by just looking at the old name. Would you mind explaining the rule for renaming in plain English?

If my understanding above is correct, this thing should be fairly easy.

Replies are listed 'Best First'.
Re^6: Substitute script for a newbie
by jspanos (Initiate) on Jul 14, 2015 at 19:42 UTC

    There isn't a hard rule, just individual cases like

    A.TL5E00* becomes +TL\E5C*, A.TL5F00* becomes +TL\F5C*, and A.TL5G00* becomes +TL\G5C*.

    I've actually made great progress on my own. I think my only obstacle is still how to format the substitution string so it will read things like '\F' as a string and not a function

    Here is my latest version. The output is ugly since it has the $VAR tags (this is something I should be able to fix), but I am feeling a lot better about where I am at

    use strict; use warnings; use Data::Dumper; my $input = 'TAV.stock.opt.oldsym.txt'; my @NewSym; { unless(open(INPUT,$input)) { die "\nCannot open $input\n"; } <INPUT>; my @lines; while(my $line = <INPUT>) { chomp $line; if ($line =~ m/^A.TL5E00/) { $line =~ s/A.TL5E00/+TL\E5C/g; push @NewSym,$line; } } close INPUT; print Dumper(@NewSym); }
      Hmm, just something that might help simplify quite a bit your program.
      if ($line =~ m/^A.TL5E00/) { $line =~ s/A.TL5E00/+TL\E5C/g; push @NewSym,$line; }
      might probably be rewritten in a simpler fashion:
      push @NewSym, $line if $line =~ s/^A.TL5E00/+TL\E5C/g;
      I haven't tested it on real data (you did not supply any), but it seems to work properly, as shown in this session under the Perl debugger:
      $ perl -de 42 Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 42 DB<1> $line = "A.TL5E00xxxx"; DB<2> push @NewSym, $line if $line =~ s/^A.TL5E00/+TL\E5C/g; DB<3> x @NewSym 0 '+TL5Cxxxx'
      If the substitution does not find a match, it will report a false value and the push will not be executed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1134784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found