Wikipedia:Reference desk/Archives/Computing/2011 December 12
Computing desk | ||
---|---|---|
< December 11 | << Nov | December | Jan >> | December 13 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
December 12
editPerl pie
editWhy would someone use perl -p -i -e
over sed? Would it only be when they're writing a Perl script and want to remain in Perl or are there other reasons? Dismas|(talk) 09:52, 12 December 2011 (UTC)
- Some people simply haven't used sed and, therefore, don't use it. If they hear about it, but see no examples, they don't know how to use it. If they are already a perl programmer, why not use what works? -- kainaw™ 15:16, 12 December 2011 (UTC)
- Perl is also, generally speaking, more powerful than sed. If you suddenly realize that the problem is a little more complicated than you thought, Perl is more likely to provide you with an easy way to solve it. Paul (Stansifer) 15:58, 12 December 2011 (UTC)
- Also, although GNU sed has a -i option now, that is a recent addition (relative to the total history of unix which has had a sed command for over 30 years), and it was inspired by perl. It only exists in the GNU and FreeBSD versions of sed. So if you intend to write a portable script, you have do the tempfile handling yourself, and you'll have to run sed once per input file so you'll have to write a for loop. A random unix box is more likely to have perl installed than GNU sed, so use of perl could be seen as a compromise, more portable than "sed -i" but less verbose (therefore harder to screw up) than the fully portable sed equivalent.
- And even if portability isn't a concern, there are a lot of people who formed their habits between the late-1980's release of perl and the early-2000's invention of "sed -i".
- If you're relatively new to unix and your intro was a GNUish system, "sed -i" might look like a natural part of the landscape. For those who used unix in the last millennium, it's conspicuously non-standard.
- The same goes for anything that uses "perl-compatible regular expressions" and isn't perl. We actually had to live with just the 2 varieties of POSIX regular expressions for a long time and we liked it! 68.60.252.82 (talk) 21:40, 12 December 2011 (UTC)
- I'm one of these people too who started using perl -p -e over sed as soon as I found out about it. My info may be out of date, but I don't think sed (or the version I learned on) supported nongreedy expressions, some types of negative lookaheads, and some of the character classes that I find convenient in perl. Also, and this is probably the biggest thing, I don't have to escape out some very useful meta characters with perl but I do with sed. For instance, if I want to do a group I have to escape () in sed, but not in perl. Same with + or ?. But not with []. Trying to keep all of that straight is a pain, so I settled on the one I'm going to be using anyway.
- The flipside, however, is that sed is presumably much faster than perl (at least according to this article I read once). Shadowjams (talk) 00:20, 13 December 2011 (UTC)
- I'll admit that
-i
is superhandy, but by the old Unix philosophy tenet of "each tool should do one job and do it well", it's a feature that arguably should not be provided by perl and sed. Should every filter laboriously provide its own reimplementation of-i
? But if not, is every user compelled to "write afor
loop"? Of course not. Like almost any task, this one can be encapsulated. For example, see here for a shell script I wrote that lets me easily run any filter on any set of files, in place:filter sort *.txt
filter 'tr a-z n-za-m' *
filter 'sed "s/foo/bar/g"' *.c
- —Steve Summit (talk) 14:16, 13 December 2011 (UTC)
- I'll admit that
PRoblem with System Restore
editI am using Windows XP, and I am attempting to use System Restore after a long series of glitches, lags, and freezes. But it seems that even the system restore process is affected by this as well; it would commonly freeze during its "Copying Files" phase of the recovery. Is it just because that my computer is too old and is already damaged beyond repair, or is it possible to fix such a problem? When it runs normally, before I tried the System Restore, it would freeze then jump back to the startup logo on occassion, but soon opens up normally given a few minutes. Afterwards, it would start to lag and later freeze up if I use it for too long. It would be sad to see my computer go though, I've had it since elementary school. 72.235.221.120 (talk) 14:56, 12 December 2011 (UTC)
Graph theory
editWhat is the difference between Path and walk? What is the difference between graph and network?--Intr199 (talk) 15:05, 12 December 2011 (UTC)
- A network can be represented by a graph, but not every graph is a network. Think about path as a possibility, and walk as actually performing a search in a graph or network. 80.39.16.11 (talk) 17:33, 12 December 2011 (UTC)
- This doesn't fully explain what the difference between a graph and a network is. I know what a graph is, and your answer sounds like a network is a subconcept of a graph, but it doesn't include a definition of what kind of subconcept. JIP | Talk 21:55, 12 December 2011 (UTC)
- Network is another name for a graph, at least in all of the contexts I've come across it. If you are seeing the two side by side in the same work, then network may be being used in a special sense defined by the author; maybe to refer to the physical network the graph abstracts. If you look up walk in wikipedia, it should give you all the information you need. Phoenixia1177 (talk) 05:27, 13 December 2011 (UTC)
- Glossary of graph theory attempts to explain the difference between a "path" and a "walk"; it says that a path is a walk whose terminal vertices are distinct, as opposed to a cycle, which is a walk that starts and ends at the same vertex. I would guess that the term "network" is usually used to decribe a graph with additional properties or structure e.g. capacities or lengths assigned to its edges. As other editors have said, the precise usage of the terms probably depends on context. Gandalf61 (talk) 10:21, 13 December 2011 (UTC)