Re: What does belg4mit's signature do?
by ccn (Vicar) on Sep 30, 2004 at 19:40 UTC
|
perl -MO=Deparse -wpe "s/\b;([mnst])/'$1/g"
BEGIN { $^W = 1; }
LINE: while (defined($_ = <ARGV>)) {
s/\b;([mnst])/'$1/g;
}
continue {
print $_;
}
-e syntax OK
| [reply] [d/l] |
|
|
$ perl -MO=Deparse -wpe "s/\b;([mnst])/'$1/g"
BEGIN { $^W = 1; }
LINE: while (defined($_ = <ARGV>)) {
s/\b;([mnst])/'/g;
}
continue {
print $_;
}
-e syntax OK
Where did my $1 went to? :-|
This should be something trivial, but... my $1 is disappearing... :-| I'm going from "don;t" to "don'" :-|
Wasn't ' the same thing as ::? | [reply] [d/l] [select] |
|
|
| [reply] [d/l] [select] |
Re: What does belg4mit's signature do?
by NetWallah (Canon) on Sep 30, 2004 at 19:39 UTC
|
Try it !
On the command line, feed it various names.
See what it does to a name like "Mc;master".
Earth first! (We'll rob the other planets later)
| [reply] |
Re: What does belg4mit's signature do?
by JediWizard (Deacon) on Sep 30, 2004 at 19:41 UTC
|
As far as i can tell, it will print each line of STDIN to STDOUT with any semi-colon preceded by a word charater and followed by one of the letters m, n, s, or t converted to a single quote. I don't know why one would want to do such a thing, but that appears to be what that does.
May the Force be with you
| [reply] |
|
|
| [reply] |
|
|
Or maybe he's a semi-colon phobic ;-)
| [reply] |
|
|
Re: What does belg4mit's signature do?
by talexb (Chancellor) on Sep 30, 2004 at 21:15 UTC
|
What part can't you figure out?
- perl -- runs perl
- -wpe "s/\b;([mnst])/'$1/g" -- passes in the following command line arguments:
- w -- enable warnings (p.502);
- p -- loop this script around each input line (p.499); and
- e "s/\b;([mnst])/'$1/g" -- some search and replace regular expression.
- This regexp takes an input line and looks for \b;([mnst]), captures whatever it finds inside the brackets, and replaces it with '$1, where $1 is the thing it captured. The \b is a
backspace key (p.161) word boundary, capturing and clustering is covered on p.182, using square brackets to define a list of characters is covered on p.201.
So what does it do? My interpretation is that it looks for a backspace word boundary, followed by a semi-colon, followed by any one of 'm', 'n', 's' or 't', and replaces that with an apostrophe followed by the alpha character that it found. It does this globally on the line.
So it probably allows belg4mit to clean up text files where he hit the ; instead of the ', since they're next to each other on his keyboard (as they are on mine.
Did you figure out the part that you missed now?
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
Update: As my learned brothers NetWallah and VenTatsu point out, \b is not a backspace in this context but a word boundary. Thanks brothers.
Update 2: Again, as DigitalKitty has pointed out, my conslusion doesn't include the corrections described in my first update. Hope fully these updates don't get longer than the original post. :(
| [reply] [d/l] [select] |
|
|
talexb: The \b is a backspace key
Nope.
From "perlre":
\b Match a word boundary
Earth first! (We'll rob the other planets later)
| [reply] |
|
|
You have a minor problem with your explinaiton, from perlreref
This one works differently from normal strings:
\b An assertion, not backspace, except in a character class
In regular expressions \b matches word boundries. | [reply] [d/l] [select] |
Re: What does belg4mit's signature do?
by Anonymous Monk on Oct 01, 2004 at 05:38 UTC
|
Suppose If a line contains as follows
check;mode
It will be replaced to
check'ode
INPUT OUTPUT
check;mj check'j
check;mn check'n
check;nm check'm
This is what the above Expression will do ..
I think It will cleare Ur doubt
For PerlMonks JesuAshok | [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in. |