IF
... and this is just a WAG because your description seems to be about two different actions -- the first merely printing back the name of $file1 (a variable -- perhaps 'C:\Users\MeinerzM\Desktop\MPS_files\wotis\soc2b2014099d07.210000' -- which was apparently instantiated OUTside the code you posted)...
whereas the second seeks to modify the
contents of $file1 (albeit with syntax that makes little sense to me) since there is no escaped "r" (whatever that would be) in the filename.
But, if that's incorrect, let us know by clarifying your question(s).
If it is correct, consider the difference: your first code will merely echo the value of the variable; not the contents of the file whose name is in your var, where the second code example apparently tries to modify the file's contents.
C:\> perl -E "my $var = 'rstuv'; $var =~ s/r/FOO/; say $var;"
FOOstuv
# replaced the "r" with "FOO"... and would have done the same if $
+var were a filename;
# that is, it would have changed the filename in $var, not the con
+tent of the file.
# Now that I've said it multiple times, does this make sense to y
+ou?
C:\> perl -E "my $var = 'rstuv'; $var =~ tr/r/FOO/; say $var;"
Fstuv
# Grossly oversimplified, the tr///ran out of "r"s to change
C:\> perl -E "my $var = 'rstuv'; my $newvar = $var =~ tr/r/FOO/; say
+$newvar;"
1
# count of the replacement actions
And if you're still interested is some kind of action with a tr/// please read perldoc -f tr to see how to use it correctly.
If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.