Andrew Hudson - Fedora™ Unleashed, 2008 edition

Здесь есть возможность читать онлайн «Andrew Hudson - Fedora™ Unleashed, 2008 edition» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2008, ISBN: 2008, Издательство: Sams Publishing, Жанр: ОС и Сети, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Fedora™ Unleashed, 2008 edition: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Fedora™ Unleashed, 2008 edition»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Quick Glance Guide
Finding information you need is not always easy. This short index provides a list of common tasks discussed inside this book. Browse the table of contents or index for detailed listings and consult the specified chapter for in-depth discussions about each subject.
left How Do I…?
See…
How Do I…?
See…
left Back up my system?
Chapter 13
Partition a hard drive?
Appendix B, Chapters 1, 35
left Build a new Linux kernel?
Chapter 36
Play MP3s and other music?
Chapter 7
left Burn a CD?
Chapter 7
Print a file?
Chapter 8
left Change a password?
Chapter 4
Read a text file?
Chapter 4
left Change the date and time?
Chapter 32
Read or send email?
Chapter 21
left Compress a file?
Chapter 13
Read or post to newsgroups?
Chapter 5
left Configure a modem?
Chapter 2
Reboot Fedora?
Chapter 1
left Configure a printer?
Chapter 8
Rescue my system?
Chapter 13
left Configure a scanner?
Chapter 7
Set up a DNS server?
Chapter 23
left Configure a sound card?
Chapter 7
Set up a firewall?
Chapter 14
left Configure my desktop settings?
Chapter 3
Set up a web server?
Chapter 15
left Connect to the Internet?
Chapter 5
Set up an FTP server?
Chapter 20
left Control a network interface?
Chapter 14
Set up Samba with SWAT?
Chapter 19
left Copy files or directories?
Chapters 13, 32
Set up wireless networking?
Chapter 14
left Create a boot disk to boot Fedora?
Chapter 1
Shut down Fedora?
Chapter 1
left Create a database?
Chapter 16
Use a spreadsheet?
Chapter 6
left Create a user?
Chapter 4
Use Instant Messaging?
Chapter 5
left Delete a file or directory?
Chapter 32
Watch television on my computer?
Chapter 7
left Get images from a digital camera?
Chapter 7
Edit a text file?
Chapter 4
left Install Fedora?
Chapter 1
Make Fedora more secure?
Chapter 14
left Log in to Fedora?
Chapter 1
Mount a CD-ROM or hard drive?
Chapter 35

Fedora™ Unleashed, 2008 edition — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Fedora™ Unleashed, 2008 edition», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

}

unless

unlessworks just like if, only backward. unlessperforms a statement or block if a condition is false:

unless ($name eq "Rich") {

print "Go away, you're not allowed in here!\n";

}

NOTE

You can restate the preceding example in more natural language like this:

print "Go away!\n" unless $name eq "Rich";

Looping

A loop is a way to repeat a program action multiple times. A very simple example is a countdown timer that performs a task (waiting for one second) 300 times before telling you that your egg is done boiling.

Looping constructs (also known as control structures ) can be used to iterate a block of code as long as certain conditions apply, or while the code steps through (evaluates) a list of values, perhaps using that list as arguments. Perl has four looping constructs: for, foreach, while, and until.

for

The forconstruct performs a statement (block of code) for a set of conditions defined as follows:

for ( start condition ; end condition ; increment function ) {

statement(s)

}

The start condition is set at the beginning of the loop. Each time the loop is executed, the increment function is performed until the end condition is achieved. This looks much like the traditional for/nextloop. The following code is an example of a forloop:

for ($i=1; $i<=10; $i++) {

print "$i\n"

}

foreach

The foreachconstruct performs a statement block for each element in a list or array:

@names = ("alpha","bravo","charlie");

foreach $name (@names) {

print "$name sounding off!\n";

}

The loop variable ( $namein the example) is not merely set to the value of the array elements; it is aliased to that element. That means if you modify the loop variable, you're actually modifying the array. If no loop array is specified, the Perl default variable $_may be used:

@names = ("alpha","bravo","charlie");

foreach (@names) {

print "$_ sounding off!\n";

}

This syntax can be very convenient, but it can also lead to unreadable code. Give a thought to the poor person who'll be maintaining your code. (It will probably be you.)

NOTE

foreachis frequently abbreviated as for.

while

whileperforms a block of statements as long as a particular condition is true:

while ($x<10) {

print "$x\n";

$x++;

}

Remember that the condition can be anything that returns a true or false value. For example, it could be a function call:

while ( InvalidPassword($user, $password) ) {

print "You've entered an invalid password. Please try again.\n";

$password = GetPassword;

}

until

untilis the exact opposite of the whilestatement. It performs a block of statements as long as a particular condition is false — or, rather, until it becomes true:

until (ValidPassword($user, $password)) {

print "You've entered an invalid password. Please try again.\n";

$password = GetPassword;

}

lastand next

You can force Perl to end a loop early by using a laststatement. last is similar to the C breakcommand—the loop is exited. If you decide you need to skip the remaining contents of a loop without ending the loop itself, you can use next, which is similar to the C continuecommand. Unfortunately, these statements don't work with do ... while.

On the other hand, you can use redoto jump to a loop (marked by a label) or inside the loop where called:

$a = 100; while (1) {

print "start\n";

TEST: {

if (($a = $a / 2) > 2) {

print "$a\n";

if (--$a < 2) {

exit;

}

redo TEST;

}

}

}

In this simple example, the variable $ais repeatedly manipulated and tested in an endless loop. The word "start" is printed only once.

do ... whileand do ... until

The whileand untilloops evaluate the conditional first. You change the behavior by applying a doblock before the conditional. With the doblock, the condition is evaluated last, which results in the contents of the block always executing at least once (even if the condition is false). This is similar to the C language do ... while ( conditional )statement.

Regular Expressions

Perl's greatest strength is in text and file manipulation, which it accomplishes by using the regular expression ( regex ) library. Regexes, which are quite different from the wildcard handling and filename expansion capabilities of the shell, allow complicated pattern matching and replacement to be done efficiently and easily. For example, the following line of code replaces every occurrence of the string bobor the string marywith fredin a line of text:

$string =~ s/bob|mary/fred/gi;

Without going into too many of the details, Table 25.7 explains what the preceding line says.

TABLE 25.7 Explanation of $string =~ s/bob|mary/fred/gi;

Element Explanation
$string =~ Performs this pattern match on the text found in the variable called $string.
s Substitutes one text string for another.
/ Begins the text to be matched.
bob|mary Matches the text bobor mary. You should remember that it is looking for the text mary, not the word mary; that is, it will also match the text maryin the word maryland.
/ Ends text to be matched; begins text to replace it.
fred Replaces anything that was matched with the text fred.
/ Ends replace text.
g Does this substitution globally; that is, replaces the match text wherever in the string you match it (and any number of times).
i Make the search text case insensitive. It matches bob, Bob, or bOB.
; Indicates the end of the line of code

If you are interested in the details, you can get more information from the regex (7) section of the manual.

Although replacing one string with another might seem a rather trivial task, the code required to do the same thing in another language (for example, C) is rather daunting unless supported by additional subroutines from external libraries.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Fedora™ Unleashed, 2008 edition»

Представляем Вашему вниманию похожие книги на «Fedora™ Unleashed, 2008 edition» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Fedora™ Unleashed, 2008 edition»

Обсуждение, отзывы о книге «Fedora™ Unleashed, 2008 edition» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x